Skip to content

Set Up Event Tracking for Experiments

⏱ 15 minutes beginner

An experiment without conversion events is a coin flip. Events measure what users actually do — purchases, signups, clicks — and connect those actions to the variation they experienced. Without them, you cannot calculate lift, statistical significance, or revenue impact.

  1. Create events in the Optimizely application
  2. Implement tracking code in your application
  3. Attach events as metrics to experiments
  4. Verify events appear in the dashboard
  1. Navigate to Events in the Optimizely application
  2. Click Create New Event
  3. Enter an event key — use lowercase with underscores (e.g., purchase_completed, form_submitted)
  4. Add a descriptive name for non-technical users
  5. Save the event

Use consistent naming conventions. Prefix events by area: checkout_started, checkout_completed, search_performed, search_result_clicked.

Feature Experimentation: track events via SDK

Section titled “Feature Experimentation: track events via SDK”
Track conversion events
javascript
// Simple event
user.trackEvent('form_submitted');

// Revenue event -- value in cents
user.trackEvent('purchase_completed', {
  revenue: 4999,
  quantity: 2,
});

// Numeric metric -- arbitrary value
user.trackEvent('search_performed', {
  value: resultsCount,
});
python
# Simple event
user.track_event('form_submitted')

# Revenue event -- value in cents
user.track_event('purchase_completed', {
    'revenue': 4999,
    'quantity': 2,
})

# Numeric metric -- arbitrary value
user.track_event('search_performed', {
    'value': results_count,
})
csharp
// Simple event
user.TrackEvent("form_submitted");

// Revenue event -- value in cents
user.TrackEvent("purchase_completed", new EventTags
{
    { "revenue", 4999 },
    { "quantity", 2 },
});

// Numeric metric -- arbitrary value
user.TrackEvent("search_performed", new EventTags
{
    { "value", resultsCount },
});

Web Experimentation: track events via push API

Section titled “Web Experimentation: track events via push API”
Track custom events in Web Experimentation
javascript
window.optimizely = window.optimizely || [];

// Simple event
window.optimizely.push({
  type: 'event',
  eventName: 'form_submitted',
});

// Revenue event -- value in cents
window.optimizely.push({
  type: 'event',
  eventName: 'purchase_completed',
  tags: {
    revenue: 4999,
    quantity: 2,
  },
});
  1. Open your experiment and navigate to Metrics
  2. Click Add Metric
  3. Select the event you created and choose a metric type:
    • Conversion rate — percentage of users who triggered the event
    • Revenue per visitor — average revenue (requires the revenue tag)
    • Numeric — average of the value tag per user
  4. Designate one metric as the primary metric for statistical analysis
  5. Save the experiment
  1. Trigger the event in your application (submit a form, complete a purchase)
  2. Navigate to Events in Optimizely
  3. The event should appear with a timestamp within a few minutes
Verify event dispatch
javascript
// Enable the event dispatcher logger to confirm dispatch
import { createInstance, enums } from '@optimizely/optimizely-sdk';

const optimizely = createInstance({
  sdkKey: 'YOUR_SDK_KEY',
  logLevel: enums.LOG_LEVEL.DEBUG,
});

// After tracking, check console for:
// 'Dispatching event to https://logx.optimizely.com/v1/events'
python
import logging
logging.basicConfig(level=logging.DEBUG)

# After tracking, check logs for:
# 'Dispatching event to https://logx.optimizely.com/v1/events'
csharp
// Enable debug logging in your logging framework
// After tracking, check logs for:
// 'Dispatching event to https://logx.optimizely.com/v1/events'

Open your browser DevTools Network tab and filter for logx.optimizely.com. Each event fires an HTTP request. Inspect the request payload to confirm the event name and tags are correct.

Revenue events require a revenue tag with an integer value in the smallest currency unit (cents for USD, pence for GBP). The Optimizely results page divides by 100 for display. Passing 49.99 instead of 4999 reports revenue as $0.50.

IssueCauseFix
Events not appearingEvent key mismatch between code and OptimizelyCopy the key directly from the Events page
Revenue shows as zeroMissing revenue tag or wrong data typeConfirm revenue is an integer in cents
Delayed resultsEvent batching and processing latencyWait 5-10 minutes; batch intervals are configurable
Duplicate eventsTracking called multiple times per actionGuard with a flag or deduplicate on the server