Question

I am upgrading from Classic analytics to UA so my question relates to the tracking code that I need. There are several additional custom dimensions (e.g author) that I want to also use.

Not every page on the site would have an author but there are many articles that would.

My question is if i need to duplicate the ga('send', 'pageview') but pass the author variable as below:

<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-xxxxxx-x', 'example.com');
    ga('send', 'pageview');
    ga('send', 'pageview', { 'dimension1': '<?=$author?>'});
</script>
Was it helpful?

Solution

No, you should send a single pageview. Otherwise the pageview data will be duplicated in GA.

<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-xxxxxx-x', 'example.com');
    ga('send', 'pageview', { 'dimension1': '<?=$author?>'});
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top