Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideProduct feedbackGitHubNuGetDev CommunitySubmit a ticketLog In

Integrate Google Analytics for iOS and Android

Integrate Google Universal Analytics or Google Analytics Classic to read data from Optimizely Web Experimentation's iOS and Android experiments and track GA metrics as experiment goals.



This integration is deprecated. See the Optimizely Feature Experimentation Google Analytics documentation instead.


Turn on the integration

  1. Go to Settings > Integrations.
  2. Select either Google Analytics (Classic) or Google Universal Analytics and toggle the integration to On.

Set up the integration

  1. Write down your tracking ID from Property Settings.
  1. In your GA dashboard, click Custom Definitions > Custom Dimension > New Custom Dimension and enter the experiment you wish to track.
  1. Also note the Index for this experiment, as you will be using this value in the Integrations menu in the Optimizely Editor.
  2. In the Optimizely App, click Settings > Integrations.
  3. Toggle on Google Universal Analytics and select a custom dimension that you want your experiment to send data to. This custom dimension is the same as the slot you have set in your Google Analytics dashboard.



When toggling on this integration, you may need to wait up to five minutes due to propagation delay.

  1. Save your experiment.



While our recommended integration is scoped at the session level, you can also configure your integration to be scoped at the user level.

Ultimately, you need to choose the scoping that's better for the types of conversions you want to track. For instance, session-level scoping may be better if the experiment is running sitewide or if a visitor will always go back through the experiment pages before converting. But user-level scoping may be better if it's possible for a user to leave the site, then come back and convert without seeing the experiment again.

Our default integration uses session scope to minimize the possibility of overwriting your experiment data sent to Google Analytics, but if you're tracking complex conversions that span multiple sessions, you may prefer to scope at the user level. For more information, see Google's documentation on scoping.

If you do this, just be cautious of reusing Custom Dimensions in Google Analytics, and for consistency between Google Analytics and Optimizely's Results page, set the Google Analytics reporting range to the duration that your experiment ran.

Add a Tracker

In your Xcode (iOS) or Android Studio (Android) project, with the GA for iOS or Android SDKs installed, instantiate a tracker with your tracking ID that matches the property you created in the dashboard.

A sample setup in your AppDelegate (iOS) looks like this:

For Android, this is a sample setup to instantiate your tracker:

Tracker tracker = GoogleAnalytics.getInstance(this).newTracker("TRACKER\_ID");  



Make sure to instantiate your tracker before you start Optimizely Web.

You can now use the Google Analytics API to start tracking events that occur in your app. For iOS, your code may look like this:

For Android, your code may look like this:

HashMap\<String, String> hitParameters = new HashMap\<String, String>();  
hitParameters.put(Fields.HIT\_TYPE, "appview");  
hitParameters.put(Fields.SCREEN\_NAME, "Home Screen");


For more information on how to configure settings and send data, see Google’s Developer Docs.

Verify the installation

  1. On iOS, enable GA verbose logging for QA purposes by entering

    \[[GAI sharedInstance].logger setLogLevel:kGAILogLevelVerbose];

    before the GAITracker. This protocol is provided to handle useful messages from the SDK at these levels of verbosity: error, warning, info, and verbose .

    On Android, use this code to enable verbose logging:

    // Set the log level to verbose.
  2. Now rebuild your app and verify in Xcode (iOS) or Android Studio (Android) log statements that experiment data is successfully being sent to GA.

  1. Your app will now send Optimizely experiment and variation information to your Google Analytics account whenever an event is triggered. These can be seen in real-time from the GA dashboard when an event triggers.
  1. Log into your Universal Analytics account and click the Customization tab at the top. You should see a Custom Reports list that looks something like this:
  1. Set up a Custom Report for each experiment you have integrated Universal Analytics with. To do this, click New Custom Report. Then give the report a title and add the metric groups you wish to view in the report.
  2. To filter this report for only your Optimizely experiment, choose the Custom Dimension you set up previously as one of the Dimension Drilldowns. See the below image for an example.
  3. Add this dimension in the Filters section and use a Regex match on the experiment name for the experiment you want to filter. This will ensure that only Universal Analytics data for that particular experiment is shown in your report:



Make sure to leave filters empty when creating a custom report for an iOS or Android experiment.

  1. Click Save. You will then be able to access your report and update the date filter if you wish: