SWhy and How to Detect Referrer Information in WordPress

Sounds fancy but the thing is actually easy to do and brings a number of unique benefits. Just to make things clear let me give you a short definition of a referrer. A referrer is what the internet population calls a website from which a visitor came to your site.

There are two main reasons for monitoring referrers. One is pretty obvious and the other not so much. Let’s talk the obvious one first.

Who’s your biggest source of traffic?

Referrers are an important piece of information from an analytical standpoint. This is a well understood fact by most webmasters. Once you know which referrers are bringing you the most traffic you can focus your actions on these exact sites to make the results even better.

This is a truly handy thing to know, especially if you’re running a promotion of any kind and need a way of checking its direct results.

Thankfully, gathering the raw numbers is nothing difficult and your Google Analytics profile does this by default. So after you set up your WordPress blog to work with Google Analytics there’s nothing more you have to do, and you will start getting referrer statistics right away (among countless other pieces of information, of course).

You can check your referrer numbers by going to your Analytics profile and navigating to “Traffic Sources” and “All Traffic Sources” … but you already know this, so let’s talk the other benefit – the one a little less popular.

Display custom content to visitors coming from different referrers

For the most part, your blog’s content should be exactly the same for everybody. But there are elements you might want to include in some specific situations (as an extra).

Displaying a custom welcome message

If you know where the visitor is coming from you can use this knowledge and welcome each visitor individually by mentioning their referrer. For instance, if the visitor is coming from Problogger you can display an additional box above the content and say something like:

“Hi there! I’ve noticed you’re visiting after reading my guest post on Problogger. Feel free to visit my blogging advice page for more tips on the same topic.”

You can create similar messages for all the other major referrers to your site, and of course you can craft such a box to provide any other message. Some ideas you can take advantage of:

  • Point to a relevant piece of content (the example above).
  • Encourage users to subscribe to your RSS feed or email list.
  • Whenever you’re selling something give away a gift code for people coming from certain sources (most likely your partners or affiliates).
  • Display links to other content that is popular among the visitors coming from the same source (you can get such data from your G. Analytics).
  • Display custom advertisements.

These are just 5 examples, and I’m sure we can come up with more during just a short brainstorming session.

How to implement referrer recognition into your blog

If you’re just going to display simple messages, like a box above the content, or something similar. And the actual contents of the box doesn’t need to be dynamically fetched from anywhere then you can go with a plugin called Referrer Detector.

It enables you to do just that. You can set a number of referrers and assign a welcome box to each. What you place inside the box is totally up to you, as long as it’s a piece of static text (HTML allowed).

You can also choose where do you want the box to appear (posts, pages) and what position it should take (before the post, after, or inside a lightbox). Pretty easy to use, so feel free to check it out.

If you want to use referrer data for something a bit more interesting then you’re going to have to implement it yourself. Luckily, the actual part of recognizing the referrer is a simple, two-line piece of code.

Before I talk over some possible usages let me just quickly share the code I’m talking about:

$referer_parse = parse_url($_SERVER['HTTP_REFERER']); 
   if(strpos($referer_parse['host'], 'google.')!==false)  
         // your PHP code

This is an example of how to recognize Google as the referrer. Google uses a lot of different domains hence the “google.” usage instead of “google.com” which would only catch the US version of Google.

You can paste this code wherever you like inside one of the files of the theme you’re using.

(Note. If you’re using a premium theme from ThemeFuse or a similar site, creating a new child theme might be a better idea than modifying the existing one.)

What for?

Several paragraphs above I mentioned two quite interesting applications of all this. First of all, displaying custom ads.

There is a belief that internet users hate ads. Some people worry about this, and some people don’t. If you’re somewhere in the middle you might want to use referrer recognition to display ads to users coming from search engines only.

This is a fairly popular trick. Many bloggers don’t like to show too many ads to their constant readers to avoid pissing them off. So they only show those ads to visitors coming form search engines. These visitors are most likely new to the site, so they have no expectations whatsoever. They are a lot less likely to be discouraged by an additional add somewhere on the page.

This is easy to implement. You just pick the file you want to enable it into. Like single.php, for example, and use the code above in whatever section of the file you feel being the most suitable.

The only thing you have to do is place your AdSense code inside the parentheses (or any other advertising code).

Another usage might be to provide some custom discount codes. This is a situation very likely to happen when you’re selling something on your site and have an agreement with your partners to give some kind of discount to whoever comes from their sites and buys your products. This is easily attainable by using the referrer detection technique.

Actually, it’s also a great example of something that can’t be done with the Referrer Detector plugin, but can be done quite easily with just a couple of lines of code. That’s because if you’re doing such a promotion you want the code to appear on your landing page only, not across the whole site to every visitor coming from a certain referrer.

I think we’ve reached the end of this tutorial. I hope you’ll find some interesting applications of this technique. And when you do, don’t forget to shoot me a comment.

there are no comments added

back to top