SEO Blog

Using the HTTP Referer to personalise your pages

In http_referer, scripting on February 21, 2007 at 6:35 pm

Ever been to one of those pages that said ‘hi visitor from domain name and wondered how they knew where you’d came from?

Well, for those of you who don’t (wonder that is) just um..go and read something else or make a cup of tea or something. For those of you who do, read on…

It’s very simple really. Browsers record all manner(of things such as useragent, operating system, screen width, resolution, time, date, IP address to name but a few. The aspect we are looking at is the HTTP_REFERER.

If you use a browser like internet explorer or firefox or opera then in most cases your browser will use this to record and provide the site that you used to arrive. So, when you click a link from site a to go to site b, site b could, if the right code was embedded, catch your referer info and give you a little message.

The following code is a simple example of how you use the HTTP referer to customise your user experience.

In this example we are going to imagine that we want to treat referals from say Yahoo or Google or MSN in slightly different ways. In this scenario, we’d be looking to reward each engine with say an output from their contextual advertising programs. The logic being that they gave us the traffic, so we are going to show their ads as a reward kinda thing.

If a visitor came from Y! then we’d output their ads, if they came from Google then we’d show theirs, from MSN theirs (if they had a program that is) and so on and so forth.

[php]

$refer = parse_url($_SERVER['HTTP_REFERER']);
$domain= $refer['host'];//grab the host name
$googleads=”code for goog ads”;
$yahooads=”code for yahoo ads”;
$msnads=”code for msn ads”;
$standardads=”code for ads”;

if($domain){

if(strstr ($domain, ‘google’)){
echo”$googleads”;

}
if(strstr ($domain, ‘yahoo’)){
echo”$yahooads”;

}
if(strstr ($domain, ‘msn’)){
echo”$msnads”;

}

}

else {
echo”$standardads”;

}
[/php]

You could embed this code in a page or a theme or template somewhere and provided that a valid http referer existed it would do what you asked of it.

You could use and adapt this in all sorts of ways by customising messages from say your best referers.If you were really into it you could go a step further and even parse the path or anchor info too even. The manual for the parse_url function provides detailed information and code examples on how this can be used.

Search Marketing Services Holistic Search
  • Hi

    No not at all, you are misunderstanding what I am saying.

    You'd never show both sets of ads at the same time.

    You can participate in as many ad programs as you like. The toc's just say that you cant output both on the same page at the same time, the issue of straightjacketing aside, its nothing to do with google or yahoo or whoever how you choose to program your website. Nothing in this breaks the tos.

    In fact there is a strong effeciency argument that says its a waste of time and resources even outputting the script code for the bots anyway.
  • so .. this is not out of TOC?
    if you run google ads on page and then yahoo ads page ... when google adsbot came ... it'll find that you ran other ads.
    thanks.
  • I presume this would be the way to go for geo targeting. Say a site had and affiliate offer, one from UK, one from the US. A redirect could send the browser to the relevant offer.

    Not used this yet, but it's only a matter of time.

    Hmmm, could be useful to "include" targeted keywords to, ahem, massage adsense relevancy. For example if someone came from Google looking for blue widgets, an extra bit of content could be added to do with blue widgets.

    How far to push it before Google slaps wrists is the thing. If one were to set up some blackhat sites for purely, ahem, research purposes one could do very creative things the HTTP Referer. Of course one only has to dip into the syndk8 forums to see what can go on.
blog comments powered by Disqus