Set Up Event Tracking for Experiments
Why event tracking matters
Section titled “Why event tracking matters”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.
What you will do
Section titled “What you will do”- Create events in the Optimizely application
- Implement tracking code in your application
- Attach events as metrics to experiments
- Verify events appear in the dashboard
Step 1: Create events
Section titled “Step 1: Create events”- Navigate to Events in the Optimizely application
- Click Create New Event
- Enter an event key — use lowercase with underscores (e.g.,
purchase_completed,form_submitted) - Add a descriptive name for non-technical users
- Save the event
Use consistent naming conventions. Prefix events by area: checkout_started, checkout_completed, search_performed, search_result_clicked.
Step 2: Implement tracking code
Section titled “Step 2: Implement tracking code”Feature Experimentation: track events via SDK
Section titled “Feature Experimentation: track events via SDK”// 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,
}); # 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,
}) // 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”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,
},
}); Step 3: Attach events to experiments
Section titled “Step 3: Attach events to experiments”- Open your experiment and navigate to Metrics
- Click Add Metric
- 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
revenuetag) - Numeric — average of the
valuetag per user
- Designate one metric as the primary metric for statistical analysis
- Save the experiment
Step 4: Verify events fire
Section titled “Step 4: Verify events fire”Check the Events dashboard
Section titled “Check the Events dashboard”- Trigger the event in your application (submit a form, complete a purchase)
- Navigate to Events in Optimizely
- The event should appear with a timestamp within a few minutes
Debug in code (Feature Experimentation)
Section titled “Debug in code (Feature Experimentation)”// 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' import logging
logging.basicConfig(level=logging.DEBUG)
# After tracking, check logs for:
# 'Dispatching event to https://logx.optimizely.com/v1/events' // Enable debug logging in your logging framework
// After tracking, check logs for:
// 'Dispatching event to https://logx.optimizely.com/v1/events' Debug in browser (Web Experimentation)
Section titled “Debug in browser (Web Experimentation)”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 tracking requirements
Section titled “Revenue tracking requirements”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.
Troubleshooting
Section titled “Troubleshooting”| Issue | Cause | Fix |
|---|---|---|
| Events not appearing | Event key mismatch between code and Optimizely | Copy the key directly from the Events page |
| Revenue shows as zero | Missing revenue tag or wrong data type | Confirm revenue is an integer in cents |
| Delayed results | Event batching and processing latency | Wait 5-10 minutes; batch intervals are configurable |
| Duplicate events | Tracking called multiple times per action | Guard with a flag or deduplicate on the server |
1. Your experiment tracks revenue, but the results dashboard shows all purchases as $0.50 instead of the expected $49.99. What is the most likely cause?
Revenue events require the value in the smallest currency unit (cents for USD). The Optimizely results page divides by 100 for display. Passing 49.99 instead of 4999 results in revenue being reported as approximately $0.50.
Revenue events require the value in the smallest currency unit (cents for USD). The Optimizely results page divides by 100 for display. Passing 49.99 instead of 4999 results in revenue being reported as approximately $0.50.
Review this topic →2. A developer implements event tracking for a form submission. Events appear in the Events dashboard, but the experiment results show zero conversions. What should they check?
Events appearing in the Events dashboard confirms tracking is working. If the experiment shows zero conversions, the event has not been attached as a metric to the experiment. You must add the event as a metric and designate a primary metric for statistical analysis.
Events appearing in the Events dashboard confirms tracking is working. If the experiment shows zero conversions, the event has not been attached as a metric to the experiment. You must add the event as a metric and designate a primary metric for statistical analysis.
Review this topic →3. You want to track both the number of searches performed and the average number of search results per query in your experiment. How should you implement these two different metrics?
A simple event (no tags) tracks conversion rate -- the percentage of users who searched. Adding a value tag to a separate tracking call creates a numeric metric that averages the value per user, ideal for tracking search results count.
A simple event (no tags) tracks conversion rate -- the percentage of users who searched. Adding a value tag to a separate tracking call creates a numeric metric that averages the value per user, ideal for tracking search results count.
Review this topic →