Last active
August 15, 2016 23:07
-
-
Save tomfuertes/6cef9b4bd37ef72a9e203515752037cc to your computer and use it in GitHub Desktop.
Custom Smartling GA Integration
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
// put this in experiment.js in between force and safe | |
(function pollForGA() { | |
var experimentId = 123456789; // TODO: Replace This | |
// NOTE: no custom dimension so can't set it | |
if ( | |
window.ga && window.optimizely && | |
optimizely.data && optimizely.data.experiments && | |
optimizely.variationNamesMap | |
) { | |
var exp = window.optimizely.data.experiments[experimentId]; | |
var name = exp && exp.name ? exp.name : ('Exp Id: ' + experimentId); | |
var variation = window.optimizely.variationNamesMap[experimentId]; | |
if (!name || !variation) return; // nothing to do | |
var tracker = 'optimizely' + experimentId; | |
ga('create', 'UA-11307836-1', { name: tracker }); | |
ga(tracker + '.send', 'event', 'optimizely', name, variation, { nonInteraction: 1 }); | |
} else return setTimeout(pollForGA, 1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment