Free tech support / small logo


How do I identify direct, not referred, Website visitors?

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?


Dave's Answer:

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:

if [ -z "$HTTP_REFERRER" ] ; then
  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:

$referrer = getenv("HTTP_REFERRER");

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!


Also check out:








Subscribe!
Never miss another Q&A article! Click to subscribe: Add to Google Reader Add to My Yahoo! Subscribe in NewsGator RDF XML
Comments · Add Comment
Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you for all your efforts on this Web site by buying you a cup of coffee!
Rather amazingly, there are no comments on this article yet.

I do have a comment, now that you mention it!











Remember personal info?


Please note that I will never send you any unsolicited email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Recent Entries


Search
I Need Help!
Need Help? Ask Dave Taylor!


© 2002 - 2012 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.