Skip to content

Set Up Event Tracking

⏱ 30 minutes intermediate
📜CoreODP

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.

  1. Install the ODP JavaScript SDK on your website
  2. Track page views automatically
  3. Send custom events for key user actions
  4. Track e-commerce events (product views, cart actions, purchases)
  5. Send server-side events via the API
  6. Verify events in the ODP debugger

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.

Add the ODP snippet
html
<!-- 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.

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):

Manual page view tracking
javascript
// 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.

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.

Custom event examples
javascript
// 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_case for event actions and property names
  • Keep action names descriptive but concise (demo_requested, not user_clicked_the_request_demo_button)
  • Use consistent property names across events (always source_page, not sometimes page and sometimes source)

E-commerce events power purchase-based segments, revenue analytics, and product recommendations. ODP expects a specific structure for product and order data.

E-commerce event tracking
javascript
// 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
    }
  ]
});

When a visitor logs in, submits a form, or otherwise provides identifying information, link their anonymous session to a known identity:

Identify a visitor
javascript
// 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.

Some events originate from your backend — order fulfillment, subscription changes, support interactions. Use the ODP Events API to send these directly.

Server-side event tracking via API
javascript
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'
  }
});
python
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'
    }
})
bash
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.

  1. Open the ODP dashboard and navigate to Settings > Event Debugger
  2. Trigger events on your site (load a page, click a button, complete a purchase)
  3. Events appear in the debugger within seconds, showing the full payload
  4. Verify that event types, actions, and properties match your expectations

After sending events with an identifier:

  1. Navigate to Customers in ODP
  2. Search for the customer by email or customer ID
  3. Open their profile and check the Activity tab
  4. Confirm that all expected events appear with correct timestamps and properties

Check the browser console for SDK errors:

Debug SDK initialization
javascript
// 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 });
IssueCauseFix
Events not appearing in debuggerSDK not loaded or wrong API keyVerify the snippet is in <head> and the tracker ID matches your ODP account
Events appear but customer profile is emptyNo identifier sentCall zaius.identify() with email or customer ID before or after events
Duplicate events on page loadSDK initialized multiple timesEnsure the snippet appears only once; check for tag manager conflicts
Server-side events return 401Invalid or missing API keyVerify x-api-key header uses the private API key from ODP settings
Server-side events return 400Malformed payloadCheck that type and action fields are present and identifiers is an object
E-commerce revenue not appearingMissing order_id or total fieldPurchase events require both order_id and total in the payload
SPA page views not trackedSDK does not detect client-side navigationCall zaius.event('pageview', {...}) manually on route change