1

I have been trying to integrate optimizely into google analytics and it has proved a bit difficult than I anticipated. I am doing it through gtm which makes it slightly complicated. I have created a macro

function() {
  dimension = optimizely.allExperiments[experimentId].universal_analytics.slot;
  experimentIds = optimizely.activeExperiments;
  variationName = optimizely.variationNamesMap;
  experimentDetails = variationName + "|" + experimentIds;

  return experimentDetails;
}

and joined it to a custom dimension in universal analytics tag which means this will be fired on every page but the dimension always comes back as:

'Running command: ga("set", "dimension14", undefined)'

I will really some help on this as I am struggling and the optimizely team dont know what to do either.

Thanks.

lossleader
  • 12,197
  • 1
  • 23
  • 38
Analytics
  • 11
  • 1
  • This should work if you change `experimentId` to the actual experiment number from the querystring on the page. So line 2 would look like `optimizely.allExperiments[987654323456]` – TomFuertes Oct 24 '14 at 17:09

1 Answers1

1

While Optimizely is best installed directly onto your page, it is possible to install Optimizely using Google Tag Manager (GTM), which is discussed here, with a complete walk through. This will ensure Optimizely fires before GA (or any other tag):

https://help.optimizely.com/hc/en-us/articles/200040095-Implementing-the-Optimizely-Snippet#tag_manager

The next part is troublesome - how can you integrate Optimizely with Google Analytics? To do so, you must insert a line of code before the GA tracking call is made ( ga('send','pageview') ). To do this, you must modify the JS in the GA call to look like the code below.

Please note, unless GTM allows you to modify their GA add on, you will need to add a custom integration in GTM for GA to place the modified code.

// Optimizely Universal Analytics Integration code
window.optimizely = window.optimizely || [];
window.optimizely.push(['activateUniversalAnalytics']);

ga('send', 'pageview');

The 'activateUniversalAnalytics' call is similar to the macro you've written above, where all it does is pass your experiment ID# (or name) and the variation # (or name) to the custom Dimension you've assigned to GA in Optimizely. One benefit of using Optimizely's integration is you can change the Dimension number per experiment inside Optimizely without making any changes to your page's source code.

If you need further assistance with this, please contact support@optimizely.com (full disclosure, I am an Optimizely employee).

GMarx
  • 453
  • 3
  • 11