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 _trackPageview
s 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With