Google Tag Manager & Optimizely
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* _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