Dev guideAPI Reference
Dev guideAPI ReferenceUser GuideGitHubNuGetDev CommunityDoc feedbackLog In

Set up Google Universal Analytics

This topic describes how to enrich Google Universal Analytics with Optimizely Feature Experimentation test information.



This article is about Google Universal Analytics properties, which will stop processing data on July 1, 2023.

View the updated documentation on implenting Optimizely Feature Experimentation and Google Analytics 4 here.

With Google Analytics, you can use events to track Optimizely Feature Experimentation test activations and build segments for each variation in an experiment. For more details on alternative solutions, read on.

The example code in each section below shows how to add an activate listener closure to the notification center. When the callback is called, the code creates and sends an event containing the experiment key and variation key.

To set up Google Analytics:

  1. Read the setup instructions and information about non-interaction events for your platform and study the example code.
  2. Build segments for each variation of your test. In the segment-builder user interface, look under Advanced and add a new condition. Select to filter users by Event Action and Event Label, enter a name for the segment, and save.
  3. Build a report of metrics that you are interested in.

Compare results

When comparing Optimizely Feature Experimentation and Google Analytics results, remember to apply a date filter in Google Analytics to correspond with the dates your Optimizely Feature Experimentation test was running.

Alternative solution

Google offers custom dimensions as another way to include non-standard data in your reports. Custom dimensions are the replacement for custom variables from older versions of Google Analytics.

Optimizely Feature Experimentation's suggested integration does not use custom dimensions because free Google Analytics accounts are limited to 20 indices (or slots), and 360 accounts are limited to 200 indices. Because a custom dimension cannot store a value that exceeds 150 bytes, you would need to dedicate an index for each Optimizely Feature Experimentation test. Google recommends against reusing indices, so the number of available indices is the upper limit of Optimizely Feature Experimentation tests that you can use custom dimensions to track and segment.


If you are getting started, read the Google Analytics Android Setup instructions.

Read more about non-interaction events and support for them in the Google Analytics Android SDK.

import com.optimizely.ab.config.Experiment;
import com.optimizely.ab.config.Variation;
import com.optimizely.ab.notification.ActivateNotificationListener;
import com.optimizely.ab.notification.NotificationCenter;
import com.optimizely.ab.notification.TrackNotificationListener;

// Add a Activate listener
int notificationId = optimizely.notificationCenter.addNotificationListener(NotificationCenter.NotificationType.Activate, new ActivateNotificationListener() {
   public void onActivate(@Nonnull Experiment experiment, @Nonnull String userId, @Nonnull Map<String, String> attributes, @Nonnull Variation variation, @Nonnull LogEvent event) {
    String experimentKey = experiment.getKey();
    String variationKey = variation.getKey();

    // Google Analytics tracker
    SampleApp application = (SampleApp) getApplication();
    mTracker = application.getDefaultTracker();

    // Build and send a non-interaction Event
    mTracker.send(new HitBuilders.EventBuilder()
        .setAction("Experiment - " + experimentKey)
        .setLabel("Variation - " + variationKey)


If you are getting started, read the Google Analytics JavaScript setup instructions.

Read more about non-interaction events and support for them in the Google Analytics JavaScript SDK.

const optimizely = require('@optimizely/optimizely-sdk');
const optimizelyEnums = require('@optimizely/optimizely-sdk/lib/utils/enums');

 * Assume the Google Analytics is loaded.
 * Add an ACTIVATE notification listener.
const activateId = optly.notificationCenter.addNotificationListener(
  function onActivate(activateObject) {
    const action = 'Experiment - ' + activateObject.experiment['key'];
    const label = 'Variation - ' + activateObject.variation['key'];
    ga('send', 'event', 'Optimizely', action, label, {
      nonInteraction: true,

Objective-C and Swift

If you are getting started, read the Google instructions for your platform:



The Google Analytics iOS SDK does not support non-interaction events. This may affect your bounce rate.

Unsupported platforms

Optimizely Feature Experimentation does not have a suggested solution for integrating Google Analytics with our SDKs for these platforms:

  • Agent
  • Go
  • Node
  • PHP
  • Python
  • Ruby

What’s Next