Set Up Event Tracking
Why event tracking matters
Section titled “Why event tracking matters”Customer profiles in ODP are only as useful as the data that feeds them. Without event tracking, ODP has no visibility into what your customers are doing — which pages they visit, what products they view, whether they purchase. Segments, personalization, and experiment targeting all depend on events arriving in real time.
This guide walks you through setting up event tracking on both the client side (JavaScript SDK) and the server side (Events API), covering the most common event types.
What you will do
Section titled “What you will do”- Install the ODP JavaScript SDK on your website
- Track page views automatically
- Send custom events for key user actions
- Track e-commerce events (product views, cart actions, purchases)
- Send server-side events via the API
- Verify events in the ODP debugger
Install the JavaScript SDK
Section titled “Install the JavaScript SDK”Add the ODP snippet to your site’s <head> tag. Replace YOUR_API_KEY with your ODP public API key, found in Settings > API Keys in the ODP dashboard.
<!-- ODP JavaScript SDK -->
<script>
var zaius = window['zaius'] || (window['zaius'] = []);
zaius.methods = ['initialize','onload','event','entity',
'identify','anonymize','dispatch'];
zaius.factory = function(method) {
return function() {
var args = Array.prototype.slice.call(arguments);
args.unshift(method);
zaius.push(args);
return zaius;
};
};
for (var i = 0; i < zaius.methods.length; i++) {
var method = zaius.methods[i];
zaius[method] = zaius.factory(method);
}
zaius.initialize({ tracker_id: 'YOUR_API_KEY' });
</script>
<script async src="https://d1igp3oop3iho5.cloudfront.net/v2/zaius-min.js"></script> The SDK loads asynchronously and queues events until it initializes. Events sent before the script loads are not lost.
Track page views
Section titled “Track page views”The SDK tracks page views automatically when initialized. Each page load sends a pageview event with the page URL, title, and referrer.
To send a page view manually (for single-page applications where the URL changes without a full page load):
// Track a virtual page view in a SPA
zaius.event('pageview', {
page_title: document.title,
url: window.location.href,
referrer: document.referrer
}); Call this in your router’s navigation handler whenever the route changes.
Track custom events
Section titled “Track custom events”Custom events capture actions specific to your business — form submissions, video plays, file downloads, feature usage. Every custom event needs an action (the event type) and can include any number of custom properties.
// Form submission
zaius.event('form_submit', {
form_name: 'contact_us',
source_page: '/contact'
});
// Video engagement
zaius.event('video_play', {
video_id: 'intro-demo',
video_title: 'Product Introduction',
duration_seconds: 180
});
// Feature usage
zaius.event('feature_used', {
feature_name: 'advanced_search',
filters_applied: 3
});
// Newsletter signup
zaius.event('newsletter_signup', {
list: 'weekly_digest',
source: 'blog_sidebar'
}); Naming conventions:
- Use
snake_casefor event actions and property names - Keep action names descriptive but concise (
demo_requested, notuser_clicked_the_request_demo_button) - Use consistent property names across events (always
source_page, not sometimespageand sometimessource)
Track e-commerce events
Section titled “Track e-commerce events”E-commerce events power purchase-based segments, revenue analytics, and product recommendations. ODP expects a specific structure for product and order data.
// Product view
zaius.event('product', {
action: 'detail',
product_id: 'SKU-1234',
name: 'Wireless Headphones',
price: 79.99,
category: 'Electronics > Audio'
});
// Add to cart
zaius.event('product', {
action: 'add_to_cart',
product_id: 'SKU-1234',
name: 'Wireless Headphones',
price: 79.99,
quantity: 1
});
// Remove from cart
zaius.event('product', {
action: 'remove_from_cart',
product_id: 'SKU-1234',
quantity: 1
});
// Purchase
zaius.event('order', {
action: 'purchase',
order_id: 'ORD-5678',
total: 159.98,
subtotal: 149.98,
tax: 10.00,
discount: 0,
items: [
{
product_id: 'SKU-1234',
name: 'Wireless Headphones',
price: 79.99,
quantity: 2
}
]
}); Identify known users
Section titled “Identify known users”When a visitor logs in, submits a form, or otherwise provides identifying information, link their anonymous session to a known identity:
// After login or form submission
zaius.identify({
email: 'customer@example.com',
first_name: 'Alex',
last_name: 'Chen'
});
// With a customer ID from your system
zaius.identify({
customer_id: 'CUST-9876',
email: 'customer@example.com'
}); After identification, ODP merges the anonymous browsing history with the known profile. All past events from the same cookie are attributed to the resolved identity.
Server-side event tracking
Section titled “Server-side event tracking”Some events originate from your backend — order fulfillment, subscription changes, support interactions. Use the ODP Events API to send these directly.
const fetch = require('node-fetch');
async function trackEvent(event) {
const response = await fetch(
'https://api.zaius.com/v3/events',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': process.env.ODP_PRIVATE_API_KEY
},
body: JSON.stringify(event)
}
);
if (!response.ok) {
console.error('ODP event failed:', response.status);
}
}
// Example: track a subscription renewal
trackEvent({
type: 'subscription',
action: 'renewed',
identifiers: {
customer_id: 'CUST-9876'
},
data: {
plan: 'enterprise',
annual_value: 12000,
renewal_date: '2026-03-24'
}
}); import requests
import os
def track_event(event: dict) -> None:
response = requests.post(
'https://api.zaius.com/v3/events',
headers={
'Content-Type': 'application/json',
'x-api-key': os.environ['ODP_PRIVATE_API_KEY']
},
json=event
)
response.raise_for_status()
# Example: track a subscription renewal
track_event({
'type': 'subscription',
'action': 'renewed',
'identifiers': {
'customer_id': 'CUST-9876'
},
'data': {
'plan': 'enterprise',
'annual_value': 12000,
'renewal_date': '2026-03-24'
}
}) curl -X POST https://api.zaius.com/v3/events \
-H 'Content-Type: application/json' \
-H 'x-api-key: YOUR_PRIVATE_API_KEY' \
-d '{
"type": "subscription",
"action": "renewed",
"identifiers": {
"customer_id": "CUST-9876"
},
"data": {
"plan": "enterprise",
"annual_value": 12000,
"renewal_date": "2026-03-24"
}
}' Important: Server-side calls use your private API key (not the public tracker ID used in the JavaScript SDK). Never expose the private key in client-side code.
Test and debug events
Section titled “Test and debug events”Use the ODP Event Debugger
Section titled “Use the ODP Event Debugger”- Open the ODP dashboard and navigate to Settings > Event Debugger
- Trigger events on your site (load a page, click a button, complete a purchase)
- Events appear in the debugger within seconds, showing the full payload
- Verify that event types, actions, and properties match your expectations
Validate a customer profile
Section titled “Validate a customer profile”After sending events with an identifier:
- Navigate to Customers in ODP
- Search for the customer by email or customer ID
- Open their profile and check the Activity tab
- Confirm that all expected events appear with correct timestamps and properties
Debug common issues
Section titled “Debug common issues”Check the browser console for SDK errors:
// Check if SDK is loaded
console.log('Zaius loaded:', typeof window.zaius !== 'undefined');
// Enable verbose logging
zaius.dispatch('debug', true);
// Manually send a test event and check the response
zaius.event('test_event', { debug: true }); Troubleshooting
Section titled “Troubleshooting”| Issue | Cause | Fix |
|---|---|---|
| Events not appearing in debugger | SDK not loaded or wrong API key | Verify the snippet is in <head> and the tracker ID matches your ODP account |
| Events appear but customer profile is empty | No identifier sent | Call zaius.identify() with email or customer ID before or after events |
| Duplicate events on page load | SDK initialized multiple times | Ensure the snippet appears only once; check for tag manager conflicts |
| Server-side events return 401 | Invalid or missing API key | Verify x-api-key header uses the private API key from ODP settings |
| Server-side events return 400 | Malformed payload | Check that type and action fields are present and identifiers is an object |
| E-commerce revenue not appearing | Missing order_id or total field | Purchase events require both order_id and total in the payload |
| SPA page views not tracked | SDK does not detect client-side navigation | Call zaius.event('pageview', {...}) manually on route change |