Hi, I am trying to capture referral data from various sources using ColdFusion such as Google Adwords, Yahoo, MSN, Google etc. I have done this in the past using PHP as it allows access to the header variables, but I'm rather rusty when it comes to ColdFusion having only lightly touched on it during me degree many years ago. What I need to ask is, is there a way that I can capture the URL a visitor has come to me from using ColdFusion, so I can report back to my superiors and say "this many visitors came from Google Adwords, this many came naturally via MSN, this many came naturally via Yahoo etc." ? Thankful for any help anyone can give. SEOMalc.
Very easy. #cgi.http_referrer# is the variable you are looking for. Then to save it to your database: <cfquery name="save_referrer" datasource="#MY_DSN#"> INSERT INTO referrer_table (referrer_name) VALUES ("#cgi.http_rerferrer#") </cfquery>
I'd recommend dumping the CGI scope as a learning exercise. <cfdump var="#CGI#"> While your at try dumping application, server, client, session, request, form, variables, or any other scope you have or can think of. It's the best way to see what the server and or browser are seeing.
I am a big fan of CFDUMP and it even gets better with CF8. I wrote about it on my blog in the post CFDUMP even better in CF8.
Is there any way to capture the Referer/User without storing the value of cgi.http_referer or cgi.http_cookie to a database? All I want to do, is grab the variable once, store it (as users still browse your website), then attach it to a contact form that sends to an email address. Any help would be appreciated.
Read up on client scope and session scope. If you store the variable in either scope you can access it throughout their stay on the site.
in application.cfm <CFPARAM name="session.ref_Url" default="#cgi.http_referrer#"> Then add session.ref to your send mail script. Something like <CFIF isdefined("session.ref_URL")> Ref : #session.ref_URL# </CFIF>