bolynn
bolynn

Reputation: 1

Google Analytics Single Application Issue

I have setup google analytics on a small 1 page application website with 3 sections. I have implemented page fields and tracker object. However, every page title in google analytics is coming across as "Contact" although I have designated page titles for each pageview as below:

  ga('create', 'UA-50789730-1', 'auto');
    ga('set', {
        page: '/',
        title: 'Home'
    });
    ga('set', {
        page: '/#features',
        title: 'Features'
    });
    ga('set', {
        page: '/#download',
        title: 'Download'
    });
    ga('set', {
        page: '/#contact',
        title: 'Contact'
    });
    ga('send', 'pageview', '/');
    ga('send', 'pageview', '/#features');
    ga('send', 'pageview', '/#download');
    ga('send', 'pageview', '/#contact');

Am I doing something wrong here?

Thanks!

Upvotes: 0

Views: 39

Answers (1)

Philip Walton
Philip Walton

Reputation: 30441

Whenever you call set you're overriding the previously set data. That's why "Contact" is all you're seeing for the title in the code shown above, since that set call overrides the previous two.

I'd recommend reading the analytics.js overview to get a better idea of how the underlying library works:
https://developers.google.com/analytics/devguides/collection/analyticsjs/

Then once you have a better understanding, you should read the guide on tracking single page applications, as there are some gotchas you should be aware of:
https://developers.google.com/analytics/devguides/collection/analyticsjs/single-page-applications

Upvotes: 1

Related Questions