Skip to content

Instantly share code, notes, and snippets.

@tomfuertes
Last active August 29, 2015 14:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tomfuertes/910c8abf4fce40cccfcb to your computer and use it in GitHub Desktop.
Google Tag Manager & Optimizely
/* _optimizely_evaluate=force */ /*jshint curly:false*/
/**
* Curries "{experiment name}: {variation name}" to GTM
* via window.clearhead['ab{n}']
*/
var experimentId = 'TODO'; // experiment id
var chDimension = 'TODO'; // 1,2,3,4,5
// poll till optimizely's global exists
var timeout = setInterval(function () {
var o = window.optimizely;
if (!o || !o.data) return;
clearInterval(timeout);
// make sure experiment exists
if (!o.variationMap.hasOwnProperty(experimentId)) return;
// curry to gtm via window.clearhead['ab{n}']
window.clearhead = window.clearhead || {};
window.clearhead['ab' + chDimension] =
o.data.experiments[experimentId].name + ': ' +
o.variationNamesMap[experimentId];
}, 25);
/* _optimizely_evaluate=safe */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment