Using Goggle Analytics I'd like to use a custom variable. This is built in functionality, but unfortunately I don't have control over the code that loads GA and calls _trackPageview;
This means I can't call _setCustomVar before _trackPageview
If I call _trackPageview a second time will it log two page views?
For example
// I'm not able to change this order
_gaq.push(['_setAccount', 'UA-XXXXXXXX']);
_gaq.push(['_trackPageview']);
// I'm forced to run this after the first _trackPageview
_gaq.push(['_setCustomVar',1,'name','value']);
_gaq.push(['_trackPageview']);
Is there any other way to get the custom variable set
Yes, each _trackPageview will log a page view.
You could pass a pageURL to the second _trackPageview, and set a filter in your analytics profile to ignore those page views.
_gaq.push(['_trackPageview', '/dummyPageName']);
Alternatively, instead of a second _trackPageview, you could use _trackEvent to cause a tracking GIF request and deliver the custom variable.
_gaq.push(['_setCustomVar', 1, 'name', 'value']);
_gaq.push(['_trackEvent', 'dummy category', 'dummy action']);
In order to prevent affecting the statistics on both your page view count and your bouncerate you should probably use the _trackEvent method and remember to set the opt_noninteraction variable to false. This should neither track a page view nor affect the bouncerate
_gaq.push(['_setCustomVar', 1, 'name', 'value']);
_gaq.push(['_trackEvent', 'category', 'action', 'label', 1, true]);
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