I have a question regarding traffic source tracking w/o the help of web analytics code. I would like to identify visitors that have directly accessed my website (i.e. typed the URL directly into the address bar) and to reward them with a voucher (basically an HTML or a PDF page they can print out). Do you know of any method (whether PHP, JavaScript or otherwise) that would isolate direct visitors from the ones coming via Search Engine or referrer?
That’s an interesting question and I think it’s definitely something you can solve in code, but there’s a big caveat: This will only work if you make the assumption that the HTTP_REFERRER information is always accurate and it’s not. Worse, because the referrer code is often used with affiliate programs, there’s something that’s arisen called referer spoofing where malicious code or malware on someone’s computer changes the referrer code so that the spyware author gets credit for the affiliate sale rather than the proper Web site owner.
There’s always something, right? 🙂
With that caveat, there are a number of ways you could tackle the problem of offering up a snippet of information on your Web page (or a pop-up window) based on whether the HTTP_REFERRER value has a value (meaning that they came from another site) or not (meaning that they either typed in the URL directly or are masking that information).
One could simply be to have the page served by a simple script that ran on the server itself, similar to:
include code that’s only for people who type in the URL directly
fi
That’s probably a solution only a hacker can love, however, so what if we wanted to do something similar in JavaScript? Here’s a possibility:
if ($referrer != “”) {
// add code here for null referrer
}
You could also code this in PHP or some other language, but I don’t want to go too far down this proverbial rabbit hole right now.
Suffice to say, yes, there is a way that you could have an operation only trigger upon loading a page for people who have a blank or null referrer value. Whether it’s a completely sure indicator that they’ve not come from another page and actually typed in your URL? Well, that’s a bit less sure.
Good luck!