Last active
November 29, 2019 11:23
-
-
Save simondahla/75f4afbdc918a8b0efb0236ca3437dca to your computer and use it in GitHub Desktop.
set d to true for console debugging
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
(function() { | |
var d = false; | |
window.optimizely = window.optimizely || []; | |
var o = window.optimizely; | |
if (o.activeExperiments && o.allExperiments) { | |
for (var i = 0; i < o.activeExperiments.length; i++) { | |
var experimentId = o.data.state.activeExperiments[i]; | |
var experimentName = experimentId; | |
if (typeof o.data.experiments[experimentId] !== 'undefined') { | |
experimentName = o.data.experiments[experimentId].name; | |
} | |
var variationName = o.data.state.variationNamesMap[experimentId]; | |
if (d) console.info('You are in experiment "' + experimentName + '" and in variation "' + variationName + '".'); | |
window.dataLayer = window.dataLayer || []; | |
dataLayer.push({ | |
'event': 'optimizelyEvent', | |
'eventCategory': 'Optimizely', | |
'eventAction': experimentName, | |
'eventLabel': variationName | |
}); | |
if (d) console.log('Experiment infomation pushed to dataLayer.'); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment