Forum Moderators: DixonJones

Message Too Old, No Replies

How to include referrer details in contact form

Simple way to track source of successful conversions

         

Daithi123

12:10 pm on Jul 29, 2006 (gmt 0)

10+ Year Member



Hello all, I have been looking through these messages, including all the google analytics stuff, but I haven't been able to find what I am looking for.
When a user submits a form on my site, I would like to know how that visitor first arrived at my site - e.g what search phrase they used.
I'm guessing the solution will involve looking at http_referrer, but I not sure how to go about it. Also, I want to know how they originally arrived at my site - not just how they arrived at the contact page.

Anyone got ideas on this one?

McElvoy

6:41 pm on Jul 29, 2006 (gmt 0)

10+ Year Member



This is done in analytics software or services by going back in the visit to the very first hit and looking at the referrer of that hit, which will be the other site. Maybe. A lot of times for many reasons the referrer of that first hit is empty --- search on "No Referrer" in this forum for several discussions about it.

To correctly match the conversion hit to the first hit of the visit, you will have to have a cookie given out by your site. If you don't give out a cookie, then you can try to rely on the IP address method, which is iffy. The cookie method is iffy also because your visitor's browser has to accept cookies.

There are other, much more difficult ways of doing this same thing; this is how it is almost always done though.

Of course you don't necessarily have to have analytics software. For one thing, you can open log files and do the tracing yourself, visit by visit.

Daithi123

5:26 pm on Jul 31, 2006 (gmt 0)

10+ Year Member



Mcevoy,
Thanks for your reply. So assumming I am happy to use a cookie (OK so it won't work 100%, but it should work 90%), how would I go about doing that?
Would it be a bit of code in the header to place the cookie, and then a bit of code in the feedback form to pull info back out of the cookie?
I've heard of cookies, but I have never actually coded one.

Thanks,

cgrantski

6:11 pm on Jul 31, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are a lot of ways to implement cookies, so there should be no shortage of information. I know it's a different process for IIS versus Apache.

Daithi123

9:55 am on Aug 1, 2006 (gmt 0)

10+ Year Member



Doing a bit more research, I came accross this thread in good old reliable WebmasterWorld [webmasterworld.com...] - 4 years old!
However, this solution is in ASP - could I be very cheeky and ask some whiz-kid coder to 'translate' this to php?

Cut-n-paste from the original post:

THIS ASP CODE SETS THE COOKIE. IT MUST GO ABOVE EVERY OTHER LINE OF CODE ON YOUR PAGE - ABOVE THE <HEAD> TAG. Change "SITENAME" to your site name (something totally unique).

<%
if request.cookies("SITENAME")="" then
vRef = Request.ServerVariables("HTTP_REFERER")
response.cookies("SITENAME")("Referer") = vRef
response.cookies("SITENAME").expires = now + 720
end if
%>

ON YOUR EMAIL FORM OR SHOPPING CART FORM YOU NEED TO CAPTURE THE REFERRER FROM THE COOKIE AND PUT IT IN A HIDDEN FIELD:

<input type="hidden" name="Referer" value="<%=Server.HTMLEncode(request.cookies("SITENAME")("Referer"))%>">

WHEN USING AN ASP SENDMAIL FORM LIKE WE USE, YOU SIMPLY REQUEST THE 'REFERRER' AS YOU WOULD ANY OTHER FIELD FROM THE FORM.

vReferer = request.form("Referer")