Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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']);

...?

like image 379
duggi Avatar asked Oct 02 '10 06:10

duggi


2 Answers

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.

like image 168
Crayon Violent Avatar answered Oct 30 '22 20:10

Crayon Violent


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)

like image 40
d-_-b Avatar answered Oct 30 '22 22:10

d-_-b