Google Analytics Initial Referrer Update
Posted by ophir on November 4th, 2008
I just posted a solution for capturing the initial referrer on landing pages that use JavaScript to redirect to a different page, and already I’ve found another (and maybe better) solution.
I just read a post by ShoreTel who suggests using initData without the trackPageview call. This will indeed set the GA cookies with the correct initial referrer value and not mess up pageview numbers.
On the landing page that does the JavaScript redirect, copy the original Google Analytics tracking code (something like this):
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-xxxxxx-11");
pageTracker._trackPageview();
</script>
var pageTracker = _gat._getTracker("UA-xxxxxx-11");
pageTracker._trackPageview();
</script>
and change it to this:
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-xxxxxx-11");
pageTracker._initData();
</script>
var pageTracker = _gat._getTracker("UA-xxxxxx-11");
pageTracker._initData();
</script>
Both solutions should work fine!
November 4th, 2008 at 12:31 pm
[...] Google Ananlytics Initial Referrer Update [...]
November 5th, 2008 at 9:01 am
The solution here is awesome. I will definitely be using this on the site’s I’m working on.
On another note I had a quick question on setting up an A/B test on a WordPress website. The issue I’m having is that Website Optimizer wants the initial control script above the tag. While adding the control script on the page template works it also adds the script to everyone of my pages. Most browsers don’t mind but Chrome gets trapped in an infinite loop.
I searched everywhere and no one has a solution on how to add Website Optimizer code to a Wordpress website for an A/B test. The only thing available is an extension that allows for multivariate testing on headlines and images.
Is it possible to write a conditional statement that writes the needed JavaScript code above the tag when the correct page is served?
December 17th, 2008 at 2:43 pm
I’m not sure I’m following - does this process overwrite the ‘last referrer’? How do you then use the ‘initial referrer’ data within GA?