Part 1: Integrating Optimizely with Google Analytics

Optimizely is a great tool for running optimisation tests on your website. If you use Google Analytics, best practice is to incorporate your Optimizely data so that you have it all in one place. Combining performance data on your variation pages with your other Google Analytics data is a great way to analyse the performance of your landing pages but it does take a little bit of work to get the data integration working. Read on to find out how.

Set up Google Analytics

To be able to associate data from Optimizely with your other data in Google Analytics, you will need to create a custom dimension to record which variation of an experiment a user saw on your website. Setting this up is fairly straightforward:

  1. Log in to your Google Analytics account
  2. Click on the 'Admin' tab
  3. Select the property where you want to integrate Optimizely
  4. Under 'Custom Definitions' select 'Custom Dimensions' and create a 'New Custom Dimension'
  5. Give your custom dimension a name and set its scope to 'Session' and click ‘Create’
Add custom dimension

Once you've created your custom dimension, take note of its index. You will need this later to configure the integration settings in Optimizely.

New custom dimension

Set up Optimizely

To get started in Optimizely, follow these steps:

  1. Log in to your Optimizely account
  2. Click on the 'Integrations' tab
  3. Select 'Google Universal Analytics' from the list and click 'On' to enable integration
UA

At this point, you've enabled the ability to integrate Google Analytics for all experiments in your project. You will then need to go into each individual experiment to complete the integration.

Open the editor for each experiment where you want the integration, then open the 'Options' menu just above the visual editor and select 'Integrations'. A pop-up box will appear on the screen giving you the option to integrate Google Analytics. Enable the integration and select the appropriate custom dimension using the dropdown menu – this should correspond to the index of the custom dimension you created earlier – then click 'Apply'.

Integrations

Tip: If you don't see the option to enable 'Google Universal Analytics' go back to your project home page and follow the instructions from the top of this section.

Update your tracking code

A small code change to your website tracking code is required to complete the integration. To find your Google Analytics tracking code:

  1. Log in to your Google Analytics account
  2. Open the 'Admin' tab
  3. Select the property that you want to get the tracking code for
  4. Under 'Tracking Info' open 'Tracking Code'

<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXX-Y', 'auto');

// Optimizely Universal Analytics Integration Code window.optimizely = window.optimizely || []; window.optimizely.push("activateUniversalAnalytics"); // End Optimizely Code

ga('send', 'pageview'); </script>

The above tracking code has been slightly modified, the additional Optimizely integration code needs to be inserted between the 'create' and 'send' lines of code. To put this into perspective, Optimizely will integrate with Google Analytics after it has loaded on the page but before the pageview is sent.

Analyse your data

And that's it! Optimizely and Google Analytics are now integrated. Your custom dimension will be recording which variant of an experiment each user saw. You will now be able to create custom segments and reports to analyse the performance of your tests and understand the underlying behaviour of your website visitors.

Optimizely experiment

Are you using Google Tag Manager? Stay tuned for part two of this blog to see how you can integrate your Optimizely experiments with Google Tag Manager!