Setting a custom variable in Google Analytics after _trackPageview is called

google-analytics

Solution

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

Problem

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

Original source