Exclusive Angular.js and Google Analytics

So, I'm trying to implement an Google Analytics content analysis experiment on a website that is made as an angular one page website.

I installed two versions of my homepage: /and /?v=2, inserted into the google code according to the instructions, at the very top of the tag <head>, and it worked fine, Google sent 30% of the traffic to one and 70% of the traffic to the second version of the page.

The problem arose when I tried to access, say /contactgoogle, apparently, I would think that I was still accessing /and sending me to /v=2(if I were part of the 30% that is).

I don’t even know why this is happening, but it is, I think it can help if the google functions do not start immediately after loading, but only after the angular main page loads controller. But I could get google code working in the specified controller.

Has anyone dealt with this problem before?

+4
source share
2 answers

What you can do is use the API instead of https://developers.google.com/analytics/devguides/collection/gajs/experiments#cxjs

Then you need to do something similar in determining the route / state

{
   templateUrl: function() {
      if(cxApi.chooseVariation() == 0) {
         return "version1.html";
      } else {
         return "version2.html";
      }

   }
}
+12
source

AngularJS, Angular. Google . , , - Google Analytics. API JavaScript . , script:

<script src="//www.google-analytics.com/cx/api.js?experiment=EXPERIMENT_ID"></script>

ui-router:

foxx, cxApi.chooseVariation() , $state, . $stateProvider.state() ( foxx), , : ng-class="{original: isVariation(0), variation-one: isVariation(1)}"

Google .

+2

All Articles