Prusak.com

Online Since 1996

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):


and change it to this:


Both solutions should work fine!

11 Responses to “Google Analytics Initial Referrer Update”

  1. Google Analytics Referrer Override Says:

    [...] Google Ananlytics Initial Referrer Update [...]

  2. Matt Says:

    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?

  3. Michael Broukhim Says:

    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?

  4. Mike Says:

    The initData function is no longer included in the default GATC and may vanish from ga.js altogether. I’d recommend setting the account to some bogus id, then running pageTracker:

    var pageTracker = _gat._getTracker(”UA-0-0″);
    pageTracker._trackPageview();

  5. ophir Says:

    @Mike:

    Using a bogus ID sounds like a good idea (I’ll trust you it works).

    I wouldn’t be worried though about Google removing the initData function anytime soon (or at all). Google is pretty good about keeping backwards compatibility. Think of all of the existing installations that would break if they were to do so.

    - Ophir

  6. 30+ Google Analytics Tools, Goals, Segments, Filters, Hacks & Resources | SEOptimise Says:

    [...] Google Analytics Initial Referrer Update [...]

  7. Dpaq Says:

    Hello,

    did you see the recent discussion thread?

    http://www.google.com/support/forum/p/websiteoptimizer/thread?tid=648e25778bb6aee1&hl=en

    Two gents started arguing each of theirs was the best solution, and I am confused.

    What would you recommend given your own experience on the matter?

    Thanks

  8. Dan Says:

    Is the change you suggest above here the ONLY change to be made to the page? Or, does the above need to be combined with any of the changes suggested in your previous solution? ShoreTel suggests also to add another instance of the full GA tracking code at the bottom of the page, this instance including the page tracker as well? I am totally lost… help ! Many thanks for your assistance !

  9. Firesit Says:

    You have to check up these Google Analytics tips

  10. Katya Says:

    Ehi evrybody, but this is the old code, but what are talking about new asynchronous code?
    It is the same thing? Or what??
    Thanks a lot.

  11. Measuring and Running A/B Testing Using Google Website Optimizer and Google Analytics | Portal Analytics Says:

    [...] first solution is to run Google Analytics prior to running the Google Website Optimizer Control Script. All you have to do is call _initData (which is responsible for setting your utmz cookie based on [...]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>