I ran across an interesting question on the yahoo web analytics group.
Paraphrased: If you have a short easy to share/print/send email like www.mysite.com/cool and that redirects to the user to a long ungangly url like www.mysite.com/much/longer/url/to/get/customer/to/admit/that/ie6/is/thedevil.htm. What happens to the referrer data/info?
Short answer? Most likely it is lost and your redirect will strip out that precious referrer data. But, it does not have to depending on how you have your redirects set up.
For this example lets assume that you use a common redirect folder called “redir” . So when you print or create a short easy to share email for your new campaign you want to sent out or shared.
www.site.com/redir/ie6isthedevil
And when a user types this in, or clicks on the link from an email they get taken to
www.site.com/its/true/ie6/is/the/devil.ftw
However, as the question above highlights, the referrer data from page to the short url is lost. Fortunately, this fix to this is easy. On the page that contains the actual redirect code, place this JavaScript in place.
<script language="javascript"> document.url = document.referrer; </script> . ..... (redirect code in language of choice)
It merely copies the referrer data into the DOM URL object on the redirect page to pass it along to the long final url. Then all of your web analytic tracking code will function as expected. (I tested this in Omniture & Google Analytics)
That’s it!
-Rudi
4 thoughts on “Save the referrals!”
If you have a server-side script language running, you can easily use
If you have a server-side script language running, you can easily use
PHP
< ?php header("Location: http://www.site.com/its/true/ie6/is/the/devil.ftw"); ?>
ASP
< % Response.Redirect "http://www.site.com/its/true/ie6/is/the/devil.ftw" %>
ASPX
< %@ Page Language="C#" ContentType="text/html" ResponseEncoding="utf-8" %>
ColdFusion (not tested)
This also keeps the orig. referrer and no need to parse/execute the redirect page.
Best
Andreas
ColdFusion (not tested)
This also keeps the orig. referrer and no need to parse/execute the redirect page.
Best
Andreas
Andreas, you are right.
My goal with this was to highlight as easy, way to handle a redirect for a shortend url that would be used in a marketing campaign, and would be easy to cut and paste into many different redirect pages without have to make any changes to it.
Also, I liked it because it would work with any scripting language without any changes. And would not require a high level of coding experience.
-Rudi
Indeed, in BlueDragon (a CFML engine) there is a CFFORWARD tag that does the header change with a server side redirect that seems to preserve the original incoming CGI scope vars.
But I like the Javascript gimmick Rudi has here. Simple and makes the fix platform agnostic.
Cool trick, but though it works in Firefox 3.6b4, but doesn’t seem to work in IE8 compatibility mode. Too bad.