Prusak.com

Serving up my thoughts since 2004

Month: November 2008

Google Analytics Tracking in Flash

Google just announced an official ActionScript 3 library for tracking flash events in Google Analytics.

You can read the whole post here:
http://analytics.blogspot.com/2008/11/want-to-track-adobe-flash-now-you-can.html

I’ve implemented Google Analytics tracking from withing Flash in the past, but it was simply having the Flash call some JavaScript code on the page.

This solution is much more elegant and opens up many new possibilities.

This is also very exciting for Google Website Optimizer users, as it should now be very easy to use an event within a Flash as the conversion event.

Google Analytics Initial Referrer Update

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!

Google Analytics Referrer Override

A couple of weeks ago I posted about a known issue using A/B experiments in Google Website Optimizer.
http://www.prusak.com/google-website-optimizer-and-referer-data/

Basically, when conducting an A/B experiment in Website Optimizer, the original referrer data is lost because of the JavaScript redirect to the test versions. This means that the traffic source will be wrong (it will say direct instead of the true traffic source).

This issue isn’t just a problem with website optimizer. Any landing page that uses JavaScript to redirect will loose the original referrer data. For example if your site provides easy to remember URLs like www.mysite.com/freeshipping and then uses JavaScript to redirect users to a different URL.

I wrote in my previous blog post that I wished Google Analytics provided an easy way to over ride the referrer value (and not use the document.referrer value).

It seems I spoke to soon.

Google Analytics DOES have a way to overwrite the referrer data.

It just doesn’t seem to be documented anywhere 🙂

I planned on writing my own hack to override the referrer value in Google Analytics. I was doing some reverse engineering of the ga.js code and found this interesting tidbit:

a._setReferrerOverride=function(b){a.yb=b}

I’m still running some tests, but based on my initial results, the _setReferrerOverride function provides a simple way to manually set the referrer value.

So now, we can actually capture the original referrer even when the visitor is redirected. Here’s how:
1 – Store the original referrer data in a cookie named realreferrer right before we redirect
2 – On the test pages, look for the realreferrer cookie. If it exists use it to over ride the referrer value in Google Analytics and then delete the cookie (so it won’t mess up page views that weren’t a result of a redirect from the original version).

Here’s the code I’m currently using in my tests.
Add this on the original page before the redirect (the GWO control script):


On the test page, add this code before any GA or GWO calls:


Then change your GA code from this:


to this:


Please let me know if this works for you !

Update:
I just found another (and possibly better) solution. See:
http://www.prusak.com/google-ananlytics-initial-referrer-update/

Update #2 [Oct 2010]:
It's been over two years since my initial posting and this issue still exists. A few people have asked about an async version so here it is.

All of my custom JS stays the same.

Here is the change for the async code:

Before

_gaq.push(['_trackPageview']);

After

if (realreferrer.length > 0) {
    _gaq.push(['_setReferrerOverride',realreferrer]);
}
_gaq.push(['_trackPageview']);

Please note my blog messes up the single quotes for code snippets when copying / pasting.

- Ophir

© 2024 Prusak.com

Theme by Anders NorenUp ↑