This article will help you:
- Integrate Google Universal Analytics to read data from Optimizely
- Add Google Universal Analytics integration code to your page
- Track Google Universal Analytics metrics as experiment goals
- Create custom dimensions and reports in Universal Analytics to track and report on Optimizely data
If you use Google Universal Analytics (UA) to monitor your site's traffic, you can view the results of your Optimizely experiments alongside the rest of the data that UA collects. In this article, we'll walk through how to implement Google Universal Analytics, and we'll cover some common troubleshooting issues.
Why integrate Optimizely and Google Universal Analytics?
- You'll have a direct view of how Optimizely experiments affect the metrics you track in Google Analytics.
- You'll be able to see Google Analytics data for each variation in your experiment.
- You'll be able to filter your Google Analytics reporting by visitors who were successfully included in an Optimizely experiment and exclude those who weren't.
- If you're running redirect experiments and plan to view your data in Universal Analytics, you'll need to turn on this integration for your traffic source information to report correctly. Otherwise, Optimizely won't be able to set a necessary variable, and your traffic will report as "Direct."
Begin by going to the Integrations tab on the Home page. Select Universal Analytics and toggle the button to ON in the details sidebar to the right.
To enable Google Analytics for an individual experiment, go to that experiment in the Editor, then click Options > Integrations.
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.
If you are using Google's new Universal Analytics for analytics on your website, you may wish to view analytics details for the visitors who have seen a given variation in your Optimizely experiment.
- In order to integrate Optimizely with Universal Analytics, you must have an available Custom Dimension (note: this refers to a Custom Dimension in Google Analytics, not the Optimizely feature) to populate with Optimizely experiment data.
- You will use the number (index) of the Custom Dimension to configure your Optimizely experiment to send data to.
- See below to learn how to access your list of Custom Dimensions in Universal Analytics and create one for Optimizely if needed.
- Optimizely strongly recommends using one Custom Dimension per concurrently running experiment so that their experiment names/variations don't overwrite each other.
As long as you're testing on the same domain and Optimizely is implemented on the experiment page, you can track session-wide goals in Google Analytics.
Enable Universal Analytics Integration
Optimizely uses Universal Analytics' "Custom Dimensions" to tag your visitors with the experiments and variations to which they've been added. Configuring Optimizely to begin sending this information to Universal Analytics requires three steps:
ga('create'...)function fires and before the Universal Analytics
ga('send','pageview')function fires and the tracking call is made (see details in the next section):
// Optimizely Universal Analytics Integration window.optimizely = window.optimizely || ; window.optimizely.push("activateUniversalAnalytics");
In the Optimizely Editor, go to Options > Integrations then click the Universal Analytics checkbox to enable the integration.
By enabling this integration, you actually replace the need to include the UA
setDimensioncode on your page. If you include the
ga('set', 'dimension1', dimensionValue);code on your site, you may actually end up overwriting the Optimizely/UA integration.
Select a "Custom Dimension" you'd like Optimizely to use. This Custom Dimension should not already be in use by another part of your site, or by another currently-running Optimizely experiment.
- Specify a "custom tracker" if you are using a custom event tracker other than the default. This will change Optimizely's integration call to use the custom tracker rather than the default. For example, if your website is using the call:
then you would enter tracker2 into the Specify a custom tracker field, and Optimizely would integrate with tracker2 instead of the default tracker.
The Optimizely API call in step #1 will set custom dimension values for all active Optimizely experiments that are configured to use the Universal Analytics integration and is safe to make even if no experiments are currently configured to use it.
Essentially, you can add this code sitewide, once, and never have to change it again.
The only exception is if you have experiments using manual or conditional activation. If you're using these activation modes, you may need to re-activate UA (step 1) and send a second Google Analytics pageview call after the experiment is activated.
Place the API Call
We recommend adding this code to your site as the last call that is made before the pageview, especially if you are using the cookieDomain function.
The latest tracking code can be obtained from Google Analytics by navigating to the Admin tab, then clicking Tracking Info > Tracking Code
A sample setup might look like this in the body of your HTML:
<script> //Universal Analytics Setup
ga('create', 'UA-XXXX-Y', 'auto’);
// Optimizely Universal Analytics Integration Code
window.optimizely = window.optimizely || ;
// End Optimizely Code
Create a Custom Dimension
In order to integrate Optimizely with Universal Analytics and view reports based on the integration data, you must configure a Universal Analytics custom dimension first. This dimension, and the name you give it, will be used to create reports that leverage your Optimizely integration data for filtering.
- While logged in as an Admin, click the Admin tab at the top and you should be brought to a page like this:
- Click the Custom Definitions link under the middle Property column and then select Custom Dimensions. You should be brought to a tab like this:
- If the Custom Dimension you want to integrate your Optimizely experiment with is listed on this tab (the 'dimension number' is shown in the Index column), then you can just take note of the name for that Dimension and don't need to add one.
- If the Custom Dimension is not listed on this tab, you'll need to create a new Custom Dimension for use with Optimizely. To do this, click the New Custom Dimension button and give the New Dimension a name and a Scope. Optimizely strongly recommends using the Session level scoping, which is defined by Google as "value is applied to all hits in a single session."
While our recommended integration is scoped at the session level, you can also configure your integration to be scoped at the user level. 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.
- Click Create and your new Custom Dimension will be available for integrating with Optimizely experiments.
Create a Custom Report
Now, you'll need to see reporting on your experiment within Universal Analytics.
- 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 ID 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 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 Community to post a discussion and see what others are talking about.