I’m just getting started with splittesting using Google Analytics (GA). Rather then using different URLs for different versions of a page I want to use the same URL and differentiate the versions via GA custom variables.
I’ve managed to accomplish this in my Django project with a conditional in the view-layer that loads up different html templates for different versions and the html-templates also take care of setting the custom variables.
However I think that it would be a lot cleaner to have all of my splittest code in a javscript file that:
1) Sets/reads a cookie on the browser specifying which testing bin this browser is in.
2) Modifies the page html and css to create the different versions
3) Records the version in a GA custom variable
Right now I’m setting all of my custom variables right in the code snippet that I’ve copy-pasted from GA.
My question is simply: Can I set the custom variables later in the page buy a _gaq.push(), or do they need to happen before the anonymous function that ends the snippet from GA?
Custom variable data gets recorded when GA makes a tracking GIF request, which occurs with
_trackPageviewor_trackEvent.So, you can set the custom variables anywhere in the page, as long as there’s a
_trackPageviewor_trackEventsomewhere afterwards.