I’ve seen this question a zillion times, so please link the hell out of this so it shows up in search results and helps people (Matt Cutts, please ignore the previous statement, I’m just trying to help people). I also posted this at the Google Analytics help forums and will do a post on Search Engine Land next week, so hopefully one of these will rank and the world will be a happier place.

ONCE AND FOR ALL! LET’S DO THIS! :)

Google Analytics will report the ORIGINAL referrer to the ORIGINAL requested page if a server-side 301 (or 302) redirect is in place.

Let’s shake out an example.

You own mySite.com and have a page called unicorns.html. You decide that you want to make a better page for this, so you make “DOUBLE-unicorns.html”.

Then you realize that you want to remove the original unicorns.html because it is lame compared to your double unicorns page, but you want to make sure that people who linked to that old page see the new, awesome double unicorns page. Because you’re a good, SEO-conscious person, you do a 301 redirect from “/unicorns.html” to “http://www.mySite.com/DOUBLE-unicorns.html”.

OK, breathe…here we go.

Let’s say that the site unicornUniverse.com loved your original page, and had a link on it. Now that your 301 redirect is present, what happens when someone clicks on that link at unicornUniverse.com? What shows up as a referrer?

Yes: unicornUniverse.com is the referrer! And what is your landing page? DOUBLE-unicorns.html is your landing page.

This happens because the browser never actually sees the first file: the server redirects your browser and the field of the DOM that monitors your referrer isn’t updated. This field is referred to by the document.referrer variable, and a quick cheat to check what’s in it is to type the following in your location bar:

javascript:alert(document.referrer);

If you’re a browser ninja, you might have firebug installed, and you can look at the DOM map there to see the same thing.

Let’s take another example:

What if someone searches for “super awesome unicorn page” on Google, just MINUTES after you put your redirect up? Well, Google hasn’t had time to find your redirect and update the URL in their index! OH MY! What will happen?

All is well in the world (almost, see the last paragraph below for what’s not well in the world), because when someone clicks the link to http://www.mySite.com/unicorns.html in the Google search results, they will be 301 redirected to http://www.mySite.com/DOUBLE-unicorns.html. Referrer? google.com (the document.referrer will actually read: http://www.google.com/search?q=super+awesome+unicorn+page — that is how it knows your search engine keywords). And again, DOUBLE-unicorns.html will be the landing page.

So, direct is direct, search is search, referred is referred.

Exceptions:

There are times when a 301 redirect will NOT preserve referrer information, but they are rare. The most common example is when an https page links through a redirect on a non-https page. Again, drop the javascript above into your browser to audit this on your own site if this is a concern. If that script tells you the right referrer information, Google Analytics will be cool as a cucumber.

Also, if you’re trying to do a 301 that isn’t of the server-side variety (I’ve seen some people try to state 301 in HTML or through a JavaScript redirect — don’t ask), you will definitely have problems.

Google’s documentation on this refers to javascript and tracking redirects, and is MISLEADING. It is technically correct, but it is NOT talking about server-side 301/302 redirects. In the isolated case it refers to (which isn’t well explained), it is right.

Lastly, webkit-based browsers (Chrome and Safari among them) have a known problem with opening content in new tabs and windows. If a user right-clicks a link and selects Open in a New Window or Open in a New Tab, referrer data is LOST! MIND BLOWN! But if they simply hold CTRL or command (on a mac) while they click to launch in a new tab, referrer data is preserved. DOUBLE BLOWN!

KEEP IN MIND:

If you are using 301 redirects, make sure they preserve your tracking parameters (utm_source, etc., at the end of your destination URL). Commonly, parameters that may specify display, email, or paid search campaigns may be stripped. What happens here? The URL of the referring site becomes a referrer and your campaign information is lost.

For example:

1) Your email that someone reads on Gmail should be counted as source:”email” medium:”email” campaign:”super email campaign”

if you forget to keep your URL parameters, instead of this visit being attributed to the email campaign, it will count as a referral from google.com! WHAT?!? Yes!

2) You are running a paid search campaign and have the keyword “unicorn site.” You expect source:”google” medium:”cpc” campaign:”generic unicorn terms”

if you forget to keep your URL parameters, instead of the paid search campaign being recorded, this visit will be attributed to NON-PAID search!!! Holy shnikeys!

The last thing to keep in mind is that before 301 destination pages replace your original pages in search engines (or if you use 302 redirects, and the URLs are not replaced in that case), your actual link URL from the engines and your Entry Page will NOT be the same! In the example above, Google linked to http://www.mySite.com/unicorns.html, but the entry page was DOUBLE-unicorns.html. If you’re trying to compare traffic to entry pages with your ranking reports (tisk tisk for running ranking reports!), they will not mesh up if you marry them by URL!

Good luck!



Comments

11 Responses to “How Does Google Analytics handle 301 and 302 Redirects?”

  1. evanlapointe on May 6th, 2010 6:30 pm

    Oh, and for you Omniture people out there, OMTR handles redirects EXACTLY the same way. Some of their documentation is pure crap. Leave a comment here so I can email you the details and links in their help center if you’d like them.

  2. Getting The Credit Your Analytics Efforts Deserve on May 14th, 2010 6:02 am

    [...] confusion around how analytics tools will react to these changes. I wrote a comprehensive guide to how Google Analytics and Omniture SiteCatalyst treat 301 (and 302) redirects, so if that’s something you’ve been trying to work out, please go take a look and fire [...]

  3. Barb on May 16th, 2010 7:30 am

    Evan – very mind-blowing indeed about tracking being lost with the right click/new tab action in Chrome.

    I get the part about utm tags on email and cpc for Bing, Yahoo, Amazon, etc. BUT, I’ve recently removed utm tags on my Google AdWords urls because the “auto-tagging” feature is required to accurately import AdWords click and cost data into Analytics.

    Can you address the role Google’s “auto-tagging” plays in the 301 redirect process? Also, will the utm_nooverride=1 tag preserve the original campaign in the event of a redirect?

  4. evanlapointe on May 16th, 2010 5:54 pm

    Barb,

    Great question.

    For adwords autotagging, you’ll just have to be sure that you preserve the parameter named “gclid.” this is what autotagging uses to identify itself to google analytics.

    As for nooverride, that will behave just like it normally would, as if the redirect were not even there.

  5. Ken Dickens on May 26th, 2010 3:09 pm

    Hey Evan, I have a client who is having a problem with a mix of 301 and 302 redirects on the same page which is causing Google Analytics to report most of the traffic on the site as referral from a sub-domain. Can you help out? If so, I’ll send you a doc that explains the problem. Please respond to my email address. Thanks.

    Ken

  6. Scott on June 2nd, 2010 5:30 pm

    Just when I thought unicorns were perfect as they are, you announce DOUBLE unicorns! Can the world get any better? ;-)

    Anyways, interesting post. I was actually looking for information on how referal traffic from the beta httpS Google would show up in Analytics (would it be under “other”?). But stumbled onto this article. Never gave the 301/302 issue on Analytics much thought before, but it is interesting, and a nice little piece of info to know :)

  7. evanlapointe on June 2nd, 2010 6:36 pm

    Yep, until you know about double unicorns…ignorance is bliss.

    Not sure if you saw my other post about Google https. It should all count as direct, unless it’s paid search, which will still be paid search if your GCLID/utm parameters persist…

  8. John on August 27th, 2010 6:18 pm

    Here’s a related question:

    I want a redirect from one domain to another to the show original domain as a referrer. What’s the best way to set that up?

  9. Mads - Ingeniør uddannelse on August 28th, 2010 8:33 am

    Hi

    How can you check to see if things are set up wrong, and how can I check how things are set up wrong.

    On this page http://www.sdu.dk/ing is a 302 redirect to http://www.sdu.dk/om_sdu/fakulteterne/teknik/uddannelse.aspx .

    But how can I know if GA is registering traffic to http://www.sdu.dk/ing ?

    Hope you can help me, thanks in advance.

    Best regards
    Mads Gorm Larsen

  10. evanlapointe on August 30th, 2010 9:44 am

    There isn’t any traffic to /ing… that page never loads. A 302 redirect prevents the original page from ever loading. So GA can’t track that page.

    Are you interested in knowing how many of the pageviews on /om_sdu…. originally came from /ing? If so, you can change your 302 redirect rule to add a parameter like ?camefrom=ing. Then you can set a custom variable or look at pageviews for the page with that parameter.

    Your original referrer information is being preserved. For example, if you go to http://bit.ly/8XTc6H and click the link to /ing, you can look at the DOM or type “javascript:alert(document.referrer);” in your location bar to see that Google referred the visit.

    Does that answer your question?

  11. evanlapointe on August 30th, 2010 9:53 am

    @John,

    If you’re using a server-side redirect, it will always pass the original referrer, even if you cross domains. One of the big exceptions is if any of the redirects go through https. Nothing can be done about that, except appending the original referrer as a URL parameter and capturing that into the campaign variables or setting a custom variable.

    Here’s a test I set up.

    1. Go to http://www.feedthehead.com/301test.html
    2. This link points to the evanlapointe.com domain
    3. It is 301 redirected to cnn.com
    4. Look at your referrer once you get to cnn.com – it’ll be feedthehead.com, not evanlapointe.com

    Great success!

Leave a Reply