Posted on

Google Optimize is a pretty cool product, it’s a free A/B tester and it integrates pretty well with Google Analytics via your Google account.

But only one way.

Google Optimize uses your goals and your traffic data to determine the outcomes of your experiments but you are not able to see which visitor visited variant A/B of your experiment in your Google Analytics data. Or at least I couldn’t find the option.

Here is a quick fix for this; Basically we retrieve the information from the Google Optimize cookie, then put it into the dataLayer of Google Tag Manager and finally save it into a custom dimension for Google Analytics.

The Google Optimize Cookie

If a visitor is part of any kind of A/B test, be that with Google Optimize or Optimizely or any other tool, it’s important that the visitor always sees the same variant (be that A or B). Even if he navigates to a different page and then returns.

To make this work, A/B testing tools have no other option than to save the variant (& some unique experiment identifier) in a cookie.

For Google Optimize, this cookie is the _gaexp cookie.
Here’s my cookie, viewed with EditThisCookie.

Let’s dissect this.

  • Multiple experiments would be separated by a “!”. So if I were part of two experiments, then my cookie would have a value like “GAX1.2.E8….17537.1!GAX1.2.B5…..17537.0″
  • “GAX” is the marker for Google Optimize, previously the same cookie was used for Google Experiments inside Google Analytics.
  • “.1.2” I have no idea what this is, probably something related to the container?
  • “.E8GTNipvRlinl6TRL8mm9w” is the experiment id, the unique identifier which you can also view inside of Google Optimize.
  • ”.17537” as pointed out by the answer above, this is the expiration date.
  • “.1” the variant id. The variant id starts counting at 0; So this is already my B version, this is the crucial information, together with the experiment id I want to have.

The dataLayer 1st Party Cookie Variable

Alright, so let’s set up a 1st Party Cookie Variable, and then translate that into something readable. I choose to string everything together in my custom dimension, but you’re free to do something else with this, including to handle multiple experiments. I simply choose first best, as it’s enough for my case.

Create a simple 1st Party Cookie Variable in GTM with the Cookie Name _gaexp.

Then we translate the value into something readable such that we can use it properly in our Google Analytics account to work with.

This will return something like

    “Experiment id: E6…… variant id: 1”.

The Google Analytics Custom Dimension

Then we push everything into a Google Analytics custom dimension with every page view & event tag. To do this first we have to create a custom dimension. In Google Analytics select your property > Administration > Property > Custom Definitions > Custom Dimensions then create a new one like the one below.

Make sure you select the scope “Hit”. On the next screen take note of the custom dimension id. In my case it’s 1 because I’ve created a fresh new property for the experiment data.

Next we send the additional data over to Google Analytics by changing the Google Analytics Settings variable, that you are hopefully already using. If not, you should definitely create one.

This variable in my case is used on all the important tags. If you don’t have one, make sure you’re changing all tags present on your A/B tested pages.

What You Can Do With This Data

I’m using the free version of Google Optimize, but I do want to be able to do the evaluation of the experiments myself. For that I need the “raw” data. In part this is because I like to have the data, and in part it’s because I have a series of tests, multi pages, where Google Optimize cannot serve a proper evaluation metric.

With this method I get a good idea of what the raw data is like.

Related: After posting this, I stumbled across David Vallejo who wrote up a different version to get Optimize data into Google Tag Manager.

2 Replies to “Getting Google Optimize Data into Google Analytics and GTM”

Leave a Reply