AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
1.7K members online now
1.7K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Google Analytics for AngularJS SPA (Single Page Analytics) using Autotrack

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I'm trying to implement Google Analytics for AngularJS single page application. For this, I'm using Autotrack and UrlChangeTracker for which the Google Analytics should also display virtual page views which the user views in AngularJS SPA. But, all I'm getting in the Google Analytics Real Time overview is just the index page view.Google Analytics Real time overview

 

The Google Analytics code snippet:

 

<script>
        window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
        ga('create', 'UA-XXXXXXX-1', 'auto');
        ga('require', 'urlChangeTracker', {
        shouldTrackUrlChange: function(newPath, oldPath) {
            newPath = newPath.split('?')[0];
            oldPath = oldPath.split('?')[0];
            return newPath != oldPath;
          }
        });
        ga('send', 'pageview');
        </script>
        <script async src='https://www.google-analytics.com/analytics.js'></script>
        <script async src="https://cdnjs.cloudflare.com/ajax/libs/autotrack/0.6.4/autotrack.js"></script>

Is there anyway i can implement the Google Analytics on SPA.

I was able to see the virtual page views in Google Analytics previously, but not now.

Google Analytics for AngularJS SPA (Single Page Analytics) using Autotrack

[ Edited ]
Participant ✭ ✭ ✭
# 2
Participant ✭ ✭ ✭

Hi,

 

I would recommend reading a blog written by Simo Ahava. Really great stuff.

 

Here you can find a couple of articles how to implement GA on SPA through GTM:

 

1) http://www.simoahava.com/analytics/google-tag-manager-history-listener/

2) http://www.simoahava.com/gtm-tips/fix-rogue-referral-problem-single-page-sites/

 

Lunametrics has written a great article about that as well: http://www.lunametrics.com/blog/2016/05/04/integrating-angularjs-google-tag-manager/

 

Hope this helps. Let us know how it goes.

Taavi