A/B Testing with Google Optimize and Tag Manager

Now that Google Optimize is available to the masses, I was keen to try it for my A/B experiments. Perhaps the best thing about A/B testing Optimize is that variant pages can be created with a visual editor, rather than having to create a second page.

Be aware that what is described herein isn’t the recommended way to set up and deploy A/B testing, but it’s quick and easy and it works. In a nutshell, here’s how we can easily A/b test (and what is required).

  1. You will need GA via GTM, and an Optimize account.
  2. Make sure you have your Goals set up in Analytics – these are your experiment Objectives
  3. Optimize is deployed by means of a Tag in GTM. Tag type is of course Google Optimize, and add the GA tracking code of the View in question, and the Container ID of the Optimise account to the tag.
    a-b-testing-gtm
  4. When you’re ready to go live, change the trigger for this tag to fire on ALL pages (not just the one you want to test)
  5. Over in Optimize, create your experiment. The key part of the classic A/B experiment is the variant page. In old school Analytics experiments these would be copies of pages, edited with the variations you were testing. But that’s old school – Optimize has a visual editor, and delivers this variant automatically as part of the experiment.
  6. Finally, Start your experiment, and wait for the data to come in.

You’ll notice we aren’t using the recommended anti-flicker code which usually goes above the GTM code. This is usually required to stop the page flicker effect as Optimize swaps one experiment variant page for another. It would definitely be required for A/B/N testing of multiple variants, or for image-heavy pages, but for a simple page and an basic A/B test we can omit it. Naughty but nice. Here’s the official party line:¬†https://support.google.com/360suite/optimize/answer/6314801

One your experiment is live, allow at least 4 hours for your first data to come in, and I found it refreshes the results at about the same interval.

An important proviso is that you can’t fully edit an experiment once it’s running – which makes sense. You can tweak the Targeting aspects of the experiment, but you can’t add a secondary objective (unless you are running Optimize 360, the pro versions).

Track Meta Refreshes to external sites using GTM

Google Tag Manager is fine if you want to track standard outgoing links. But what if the link is contained in a Meta Refresh? And you only want to capture certain meta refreshes? This was my challenge the other day!

  1. Set up a new variable in GTM, call it something like Get Meta Refresh
  2. Variable type should be Custom Javascript, and that javascript is as follows:function getMetaContent() {
    var metas = document.getElementsByTagName(‘meta’);for (var i=0; i<metas.length; i++) {
    if (metas[i].getAttribute(“http-equiv”) == “refresh”) {
    return metas[i].getAttribute(“content”);
    }
    }return “”;
    }

    All we’re doing here is looking at the Metas within the code and saving it.

  3. Next we create a tag/trigger combination.The Trigger is fired when the Get Meta Refresh variable contains the desired URL or domain (and the page name also matches a desired URL); the tag simply creates an event called ‘Refresh to outgoing link’ or similar.

And voila, we’ve created meaningful Events when a page Meta Refreshes to a specified domain.