Created
June 6, 2016 22:31
-
-
Save tomfuertes/7ec0f01cd0b0e45adaad69aefaad519b to your computer and use it in GitHub Desktop.
Google Tag Manager and Optimizely
This file contains hidden or 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
<script> | |
// Curry Optimizely optimizely.activateUniversalAnalytics() into GTM via window.optimizelyGTM | |
(function() { | |
window.gtmData = window.gtmData || []; | |
window.optimizelyGTM = window.optimizelyGTM || {}; | |
var oldObj = window.GoogleAnalyticsObject; | |
window.GoogleAnalyticsObject = 'gtmtmp'; | |
window.gtmtmp = function(set, dim, val) { | |
window.optimizelyGTM[dim] = val; | |
}; | |
try { | |
window.optimizely = window.optimizely || []; | |
window.optimizely.push("activateUniversalAnalytics"); | |
} catch (e) {} finally { | |
window.GoogleAnalyticsObject = oldObj; | |
window.gtmtmp = undefined; | |
delete window.gtmtmp; | |
window.gtmData.push({event: 'gtm.curriedPageview'}); | |
} | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gtm.curriedPageview
AB Testing - {index}
where index is the next number from 1-20 you're using)javascript variable -> optimizelyGTM.dimensionN
(e.g.,optimizelyGTM.dimension4
,optimizelyGTM.dimension5
, etc...)References: https://help.optimizely.com/Integrate_Other_Platforms/Integrating_Optimizely_with_Google_Universal_Analytics