VKI Studios is now Cardinal Path! www.CardinalPath.com
Learn more about Cardinal Path

An Update to the Erik Vasilik's "Poor Man's GWO/Analytics Integration": Using Custom Variables

GWO and GA, together at last

Here's an update to Erik Vasilik's "Poor Man's GWO/Analytics Integration" technique. The latest iteration of the technique used GA's user-defined variable to store the combination the visitor saw. Here's an update to that technique, but leveraging the new Custom Variables just released by Google.

Multivariate Test Integration

To integrate with an MV test, you need to replace the code

pageTracker._setVar("MyExperiment-" + utmx('combination'));


pageTracker._setCustomVar(1, 'GWO Tests - Basic MVT Experiment', utmx('combination_string'), 1);

You will need to make a few modifications to the code.

  1. Update the first argument to an unused MCV slot. In the sample code, we'll be storing the GWO information in slot 1.
  2. Update 'Basic MVT Experiment' to the name of the experiment being run.

You will need to be very careful as to where you place this script. The function _setCustomVar must be called before the call to _trackPageview. This is because custom vars are sent with the next call to either _trackPageview or _trackEvent. This is in contrast to _setVar, which sends it's own request when the code is executed.

Here is some sample code for how the order of execution should appear:

<script type="text/javascript">
         var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
         document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
         document.userPage = true;
      <script type="text/javascript">
         try {
            // GA tracking object             
            var pageTracker = _gat._getTracker("UA-XXXXXX-X");
            //set combination info             
            pageTracker._setCustomVar(1, 'GWO Tests - Basic MVT Experiment', utmx('combination_string'), 1);
      <script type="text/javascript">
         try {
            // GWO tracking object             
            var gwoTracker = _gat._getTracker("UA-XXXXXX-X");

A/B Test integration

As with the old GA/GWO integration technique, special consideration must be taken for A/B experiments. Because the page redirects to the "B" page before any analytics code is run, we need to insert the custom variable code between the code that defines the "utmx" function, and the code that actually runs the "utmx" function. Using UDVs, this was easily achieved by inserting the call to _setVar between the two pieces of code. But, remember how I mentioned that MCVs are sent along with the next call to _trackPageview or _trackEvent? Well, setting the custom variable, and then sending either a pageview or event will have a really negative effect on your bounce rates. Especially if your A/B experiment is on a landing page!

To track the A/B test correctly, you can implement one of the following solutions:

  1. In the GA tracking code on the A and B pages, populate the custom variable information using information stored in the "__utmx" cookie.
  2. In between the two sets of code, set a cookie containing the experiment information. Then, in the GA tracking code on the A and B pages, read the cookie, set the custom variable, then delete the cookie. I would highly recommend this method because the JavaScript code is simpler to implement

Like this post? Give it a Sphinn!

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)

Maybe instead of

pageTracker._setCustomVar(1, 'GWO Tests - Basic MVT Experiment', utmx('combination_string'), 1);

the right one is:

pageTracker._setCustomVar(1, 'GWO Tests - Basic MVT Experiment', utmx('combination'), 1);

combination_string returns null value.
# Posted By Yannis Karampelas | 1/30/10 9:18 AM
Ah, nice update. Could you please upload screenshots of how Custom Variables category looks after your code has been implemented? I'd greatly appreciate that.
# Posted By Rishi Rawat | 9/8/10 5:24 AM
Hi Rishi,

Thanks for your comment. I'll work on a follow-up blog post with screen shots!
# Posted By Andre Wei | 9/15/10 10:33 PM
That would be awesome. Thanks!
# Posted By Rishi Rawat | 9/16/10 2:26 AM
Sorry Rishi, it's been awhile since I said I would post some screen shots. I was just about to begin then realized I had already done a blog post! This blog post includes some screen shots of a live test we performed as well as the data we saw coming into Google Analytics.

# Posted By Andre Wei - VKI | 11/29/10 2:33 PM
Thanks a lot Andre. Every day I record a highlight for the day. Both your articles are going straight to my list.
# Posted By Rishi Rawat | 11/30/10 3:37 AM
Yes i agree with Yiannis. He has a point!
# Posted By cyprus | 3/18/11 2:08 PM
Yannis is right. This is the right thing to do.
pageTracker._setCustomVar(1, 'GWO Tests - Basic MVT Experiment', utmx('combination'), 1);
# Posted By ????????? ??????????? | 6/2/11 9:25 AM