forked from eaguerralde/angular-google-experiments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogleExperiments.min.js
1 lines (1 loc) · 980 Bytes
/
googleExperiments.min.js
1
angular.module("googleExperiments",["angularLoad"]),angular.module("googleExperiments").provider("googleExperiments",[function(){this.configure=function(conf){this.config=conf},this.$get=["$q","$timeout","angularLoad",function($q,$timeout,angularLoad){var variationDeferred=$q.defer();return angularLoad.loadScript("//www.google-analytics.com/cx/api.js?experiment="+this.config.experimentId).then(function(){variationDeferred.resolve(cxApi.chooseVariation())}).catch(function(){variationDeferred.resolve(0)}),{getVariation:function(){return variationDeferred.promise}}}]}]),angular.module("googleExperiments").directive("variation",function(googleExperiments){return{scope:{variationSelected:"="},link:function(scope,element,attr){element.addClass("ng-cloak"),scope.$watch(attr.variation,function(value){googleExperiments.getVariation().then(function(variation){variation==value?(element.removeClass("ng-cloak"),element.removeClass("ng-hide")):element.addClass("ng-hide")})})}}});