开发者

do i need to call _gaq.push(['_trackPageView']) more than once on a page when using goog analytics asynchronous code?

i am using the vanilla ga asynchronous code thusly, right before end of </head>:

<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxx-1']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]开发者_开发技巧; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>

now, later in the middle of the page i call:

<script>
_gaq.push(['_setCustomVar',
  1,
  'usertype',
  'anon',
  2
]);
</script>

the question is, do i need to make another call to _trackPageView?

that is, should i add another

_gaq.push(['_trackPageview']);

...?


Yes, you will need to make another call to _trackPageView in order to count the _setCustomVar. However, this will count as 2 separate page views, which is going to inflate the # of page views for the page. So you should instead move the _setCustomVar up to before _trackPageView is called.


Calling two _trackPageviews will send the custom variable to GA, however this will cause a few negative consequences:

  • Bounce rate will turn to 0%

  • pages per visit will increase by 1

To get around this you can:

  • move the custom variable before the initial _trackPageview, or:

  • trigger some other call to GA, such as an Event, User Timing Event, Social Event (or last resort, _trackPageview,'fake page name', and filter the 'fake page name' out of all reporting)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜