- Integrate Google Universal Analytics to read data from Optimizely's iOS and Android experiments
- Track GA metrics as experiment goals
If you use Google Analytics (GA) to monitor your site's traffic, you can view the results of your Optimizely experiments alongside the rest of the data that GA collects. In this article, we'll walk through how to implement Google Analytics for iOS and Android.
Begin by going to the Integrations tab on your Project Settings. Select either Google Analytics or Universal Analytics and toggle the button to ON in the details sidebar to the right.
Implementing Optimizely and Google Analytics in a tag manager? Read the tag manager section of our article on implementing Optimizely to find out more about how this will affect your GA tracking code.
- The latest Optimizely Swift SDK or Optimizely Android SDK must be installed.
- The Google Analytics for iOS or Google Analytics for Android SDK must be installed.
- You have an available custom dimension that Optimizely will use to send data to.
- You have Google Analytics “Mobile app” property with a tracking ID.
- You can create a custom report in Google Analytics.
- For Android, you should have a gradle dependency for the Universal Analytics plugin.
- Write down your tracking ID from Property Settings.
- In your GA dashboard, click Custom Definitions > Custom Dimension > New Custom Dimension and enter the experiment you wish to track.
- Also note the Index for this experiment, as you will be using this value in the Integrations menu in the Optimizely Editor.
- In the Optimizely App, click Settings > Integrations.
- 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. Note: When toggling on this integration, you may need to wait up to five minutes due to propagation delay.
- 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'll 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.
Adding 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"); OptimizelyUniversalAnalyticsIntegration.setTracker(tracker);
Make sure to instantiate your tracker before you start Optimizely.
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"); tracker.send(hitParameters);
For more information on how to configure settings and send data, consult Google’s Developer Docs.
- 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
On Android, use this code to enable verbose logging:
// Set the log level to verbose. GoogleAnalytics.getInstance(this).getLogger() .setLogLevel(LogLevel.VERBOSE);
- Now rebuild your app and verify in Xcode (iOS) or Android Studio (Android) log statements that experiment data is successfully being sent to GA.
- You’re done! 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.
- 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:
- 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.
- 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.
- 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.
- Click Save. You'll then be able to access your report and update the date filter if you wish:
Have a question about integrating Optimizely with your Analytics Platform? Head over to the Optimizely questions on Stack Overflow to post a discussion and see what others are talking about.