Skip to content

Instantly share code, notes, and snippets.

@aroach
Created January 5, 2016 23:09
Show Gist options
  • Save aroach/da9215e3fd25bbfdc791 to your computer and use it in GitHub Desktop.
Save aroach/da9215e3fd25bbfdc791 to your computer and use it in GitHub Desktop.
angular-optimizely
angular.module('myApp')
.service('ABTestService', function () {
this.abtestActivateExperiment = function(experimentId) {
console.log(experimentId);
window['optimizely'] = window['optimizely'] || [];
window.optimizely.push(["activate", experimentId]);
console.log(window['optimizely'].variations);
var variation = window.optimizely.variationMap;
// If variation exists return it, otherwise return default of 0
return (typeof variation === 'undefined' ? 0 : variation);
};
this.abtestEvent = function(event_name, event_properties) {
event_properties = typeof event_properties !== 'undefined' ? event_properties : {};
window['optimizely'] = window['optimizely'] || [];
window.optimizely.push(["trackEvent", event_name, event_properties]);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment