Skip to content

Instantly share code, notes, and snippets.

@tomfuertes
Last active August 15, 2016 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomfuertes/6cef9b4bd37ef72a9e203515752037cc to your computer and use it in GitHub Desktop.
Save tomfuertes/6cef9b4bd37ef72a9e203515752037cc to your computer and use it in GitHub Desktop.
Custom Smartling GA Integration
// 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