Welcome to WebmasterWorld Guest from 54.224.253.82

Forum Moderators: open

Message Too Old, No Replies

Tracking original referrer

track first referer to website

     
12:01 pm on Jul 26, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:May 1, 2004
posts: 100
votes: 0


Hi

I'm no expert in JavaScript, but thought this would be an easy one. After several hours of searching, I've simply ended up totally confused!

My client wants to trace the original/first HTTP referer of every visitor to his site. He wants his home page to write a cookie to the user's computer recording the referer domain. The php-driven inquiry form will then access the cookie and include the refer information in the notification to the client.

I'm not worried about the php side - but am having great trouble finding a reliable source for the JavaScript code to write the initial cookie. I thought this would be literally just a couple of lines of code, but studying the web it seems a lot more complex. Any help would be appreciated.

12:31 am on July 27, 2009 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts:4987
votes: 12


You would not want to use JavaScript for this. If the site uses PHP, you can access the referrer information like this:

<?php
echo $_SERVER['HTTP_REFERER'];
?>

Hope that helps.

9:44 am on July 27, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:May 1, 2004
posts: 100
votes: 0


Hi Fotiman

Thanks - but I can't have explained properly.

I can't use php because this is not all happening in the same session - and, even if it is, the reader will likely have started at the home page and read various other pages of the site, so the original referer will be long gone unless we trap it at the next page.

I am assuming that the user might not complete the inquiry form on their first visit to the site. They may well look at competitor services, consider things and then come back a few weeks later. So, the only way to store the 'orginal' referer is through a cookie. Yes, could use PHP to write the cookie as soon as they entered the site, but the regular pages aren't php-driven and so JavaScript seems the obvious way.

1:55 pm on July 27, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Dec 9, 2003
posts:3416
votes: 0


I'd recommend a search in your favorite search engine for "javascript write cookie" or "javascript set cookie." You'll find plenty of straightforward functions you can use to make cookie handling easier. :)