The best way to integrate Optimizely and Google Analytics through GTM

Simon Dahla

Through the years, we’ve integrated data from Optimizely and Google Analytics in a number of different ways. The method we’re about to share with you is in our experience the best and easiest.

Why would you want to integrate your analysis and testing tools? Because it helps to improve the quality of your test data. Since there is a difference between these tools, you’ll want to make sure that your experiments are as valid as possible.

The “old” (link to post in Swedish) way requires you to remove the Page view tag (in GTM) and that you replace it with a Custom HTML tag. This was an emergency solution that’s not required anymore, since GTM has released long anticipated updates. Now, we’re using GTM the way it should be.

Our recommendations are not the same as Optimizely’s

Please note that this is not what Optimizely themselves recommend… Our way gives you both events and custom dimensions in Google Analytics, which gives you more freedom during the analysis phase. Optimizely’s method only gives you custom dimensions. More about the differences between these recommendations further below.

How to:

1Make the integration possible from Optimizely

  1. Log in to the Optimizely tool
  2. Go to the “Integrations” tab
  3. Activate “Google Universal Analytics” through clicking “On”

Integrate Optimizely into Google Analytics  

2Create a custom dimension in Google Analytics

  1. Log in to Google Analytics and go to “Account”
  2. Underneath “Property Settings”, choose “Custom Definitions” and “Custom Dimension”
    Create Custom Dimension in GA
  3. Create a new “Custom Dimension” and name it Optimizely, for example
  4. Set this to either Session or User level (we recommend User level, see why further down)

3 Add Custom HTML script in Google Tag Manager

  1. Log in to your GTM account
  2. Underneath “Tags”, click “New” and choose “Custom HTML Tag”
  3. Add the code available at the bottom of this post
  4. Choose “Fire on all pages” (this is the easiest way, but you can also choose to only fire on the pages where you’re conducting your experiment)
  5. Underneath “Variables”, create 4 Data Layer Variables (if you don’t have them already). They should be named eventCategory, eventAction, eventLabel. Just check the yellow box at the top for the last DLV.
    Check box for event
  6. Create a new “Custom event” underneath “Triggers”. The “Event name” should match “event” and the Event Data Layer Variabel underneath filter should match “Event” optimizelyEvent (see image)
    Trigger in Optimizely
  7. Create a new Google Analytics tag underneath “Tags”
  8. Configure the tag and choose the variables you just created (as instructed in the images below)
    Create new event in GTM
  9. Important! Non-Interaction Hit needs to be set to True, otherwise you’ll mess up your bounce rate
  10. Your tag triggers on the event you created
  11. Double check everything, if it looks right, run Preview Mode and see how it looks.
  12. Publish

 

4Create a Custom Report in GA

  1. Go back to Google Analytics
  2. Go to “Customisation”
  3. Create a new “Custom Report”
  4. Select your Optimizely Custom Dimension as the drill down dimension
  5. Configure the filters so that you only see current experiments
  6. Save

Create a Custom Report in GA

Done!

User or Session Scope in GA?

Our recommendation is to always look at the user level, but you can also configure settings to view the Session level, which is what Optimizely recommends…

What is the difference? You’ll want to choose the scope that matches the type of conversion you wish to track in your experiments. The User level scope is better if it’s possible for the user to leave the site to come back later and convert, without seeing the experiment again. However, please note that User data is only stored for three months before it disappears from GA.

Through Session scoping, you decrease the risk of overwriting existing data since a Custom Dimension in Google analytics only holds one value. On the other hand, we want to see users converting, not sessions. For more information, read Google’s documentation about Scoping.

If you choose to change the scope, be careful when re-using your Custom Dimension in GA. If you have the possibility, it’s good to have two different Custom Dimensions that you switch between. Also, to be consistent, make sure that your GA report has the same time span as your experiment.

The code you need to paste into GTM:

Read also

Conversionista is open for business in The Netherlands.
Conversionista is open for business in The Netherlands. Read more.