Question

How do I configure Google Universal Analytics with AngularJS and instantly see some test data from my local test environment?

The current code:

  <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-XXXXXXX-X', { // I have my actual UA id here
      cookieDomain: 'none'
    });

  </script>
</head>

I also have this one:

$rootScope.$on('$routeChangeStart', function() {
    ga('set', 'page', $location.url());
});

In the Real-time section in Google Analytics Dashboard i see '0 active visitors'.

Was it helpful?

Solution

You set a page url but you don't seem to have a call to the send function

ga('send', 'pageview');

"set" merely sets fields (you can do this via a configuration object as the third parameter to the send pageview, too), you need "send" to, well, send them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top