Integrate with Analytics Platforms
Why integrate with analytics
Section titled “Why integrate with analytics”Optimizely’s results page gives you statistical significance and lift. Your analytics platform gives you the broader context — session duration, bounce rates, funnel behavior, and attribution. By sending experiment data to analytics, you can answer questions like “Did the winning variation also improve time on site?” or “Which traffic sources responded best to the variation?” without switching tools.
What data to send
Section titled “What data to send”At minimum, send two values for each experiment:
| Data point | Purpose |
|---|---|
| Experiment name or ID | Identifies which experiment the visitor is in |
| Variation name or ID | Identifies which variation the visitor is seeing |
Some teams also send the experiment status (running, paused) and the campaign or project name for organizational filtering.
Integration options
Section titled “Integration options”| Method | Best for | Setup effort |
|---|---|---|
| Built-in integration | GA4, Adobe Analytics — one-click setup | Low |
| Custom analytics integration | Any platform via JavaScript callbacks | Medium |
| Tag manager | GTM, Tealium — route data through your tag layer | Medium |
Google Analytics 4 (built-in)
Section titled “Google Analytics 4 (built-in)”Optimizely has a native integration that sends experiment and variation data as GA4 custom dimensions.
- In Optimizely, navigate to Settings > Integrations
- Find Google Analytics 4 and click Enable
- Configure the dimension mapping:
- Experiment ID dimension — Choose or create a custom dimension in GA4 (e.g.,
optimizely_experiment) - Variation ID dimension — Choose or create a second custom dimension (e.g.,
optimizely_variation)
- Experiment ID dimension — Choose or create a custom dimension in GA4 (e.g.,
- Save the integration
Data begins flowing on the next page load. In GA4, create segments or comparisons using these custom dimensions to analyze experiment performance.
Adobe Analytics (built-in)
Section titled “Adobe Analytics (built-in)”- Navigate to Settings > Integrations
- Enable Adobe Analytics
- Map experiment and variation data to Adobe eVars:
- Select the eVar for experiment ID
- Select the eVar for variation ID
- Save — Optimizely will set the eVars via the
sobject on each page load
Custom analytics integration
Section titled “Custom analytics integration”For platforms without a built-in integration, use the Optimizely JavaScript API to read active experiments and send data to any analytics tool.
// Wait for Optimizely to be ready
window.optimizely = window.optimizely || [];
window.optimizely.push({
type: 'addListener',
filter: { type: 'lifecycle', name: 'activated' },
handler: function(event) {
var state = window.optimizely.get('state');
var activeExperiments = state.getActiveExperimentIds();
activeExperiments.forEach(function(experimentId) {
var variation = state.getVariationMap()[experimentId];
var experimentName = state.getExperimentStates()[experimentId].experimentName;
var variationName = variation ? variation.name : 'original';
// Send to your analytics platform
analytics.track('Experiment Viewed', {
experiment_id: experimentId,
experiment_name: experimentName,
variation_id: variation ? variation.id : 'control',
variation_name: variationName,
});
});
},
}); Google Tag Manager integration
Section titled “Google Tag Manager integration”If you manage analytics through GTM, push experiment data to the data layer and trigger your analytics tags from there.
window.optimizely = window.optimizely || [];
window.optimizely.push({
type: 'addListener',
filter: { type: 'lifecycle', name: 'activated' },
handler: function() {
var state = window.optimizely.get('state');
var experiments = state.getActiveExperimentIds();
experiments.forEach(function(expId) {
var variation = state.getVariationMap()[expId];
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'optimizely_experiment',
optimizely_experiment_id: expId,
optimizely_variation_id: variation ? variation.id : 'control',
optimizely_variation_name: variation ? variation.name : 'Original',
});
});
},
}); Then in GTM:
- Create a Custom Event Trigger for the event name
optimizely_experiment - Create Data Layer Variables for
optimizely_experiment_idandoptimizely_variation_id - Use these variables in your GA4 or Adobe Analytics tags
Verify the integration
Section titled “Verify the integration”- Open your site with the experiment running
- Open browser developer tools
- For GA4: Check the Network tab for requests to
google-analytics.comcontaining your custom dimensions - For Adobe: Check the
sobject in the console for eVar values - For custom/GTM: Check
window.dataLayeror your analytics platform’s debug view
Data alignment considerations
Section titled “Data alignment considerations”| Consideration | Details |
|---|---|
| Sampling | GA4 may sample data on free accounts. Optimizely does not sample. Numbers may diverge at scale. |
| Attribution window | Optimizely counts unique visitors per experiment. GA4 may use session-based attribution. |
| Timing | Optimizely activates on snippet load. Analytics tags may fire at different points in the page lifecycle. |
| User identity | Optimizely uses cookies for visitor identity. Ensure your analytics platform uses the same identity basis. |
Troubleshooting
Section titled “Troubleshooting”| Issue | Cause | Fix |
|---|---|---|
| No experiment data in analytics | Integration not enabled or listener not firing | Verify integration settings and check for JavaScript errors |
| Experiment data appears for wrong pages | Experiment activating on unintended URLs | Check URL targeting in the experiment configuration |
| Visitor counts differ between tools | Different identity models or sampling | Accept minor discrepancies as normal; use Optimizely as the source of truth for experiment decisions |
| Data layer events not firing | Optimizely snippet loading after GTM | Ensure the Optimizely snippet loads before GTM evaluates |