문제

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>
도움이 되었습니까?

해결책

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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top