Hi, every one

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.

Dani AI

Generated

Short answer: use explicit campaign tagging (UTM parameters) and persist those values on first landing; fall back to a client-side capture of the browser referrer if you need it. ’s point about the server seeing the referer is correct, and is also right — that header is often empty (direct visits, privacy tools, some proxies, HTTPS->HTTP, or referrer-policy). ’s suggestion to inspect the CGI scope is useful for debugging.

Practical, reliable workflow:

  1. Ensure paid links include utm_source/utm_medium/utm_campaign.
  2. On the landing page, capture any utm_* query parameters and persist them in a cookie (or session) so later pages and conversions can attribute back to the campaign.
  3. If no utm_* is present and no cookie exists, capture document.referrer on the client and send it to a small CF endpoint to set the same cookie (this covers cases where the referer header was stripped before the server saw it).
  4. At the conversion moment (signup/checkout), read the cookie and write source/medium/campaign/timestamp to your conversions table — report from that table.

Example snippets (not the same code already shown in thread):

<!-- capture utm params on landing -->
<cfif NOT structKeyExists(cookie,'ref_source') AND structKeyExists(url,'utm_source')>
  <cfcookie name="ref_source" value="#url.utm_source#" expires="30">
  <cfcookie name="ref_medium" value="#url.utm_medium#" expires="30">
  <cfcookie name="ref_campaign" value="#url.utm_campaign#" expires="30">
</cfif>
<!-- client-side fallback: send document.referrer to server if no cookie -->
<script>
(function(){
  if (!/ref_source=/.test(document.cookie)) {
    var r = document.referrer || '';
    if (r) new Image().src = '/trackRef.cfm?ref=' + encodeURIComponent(r);
  }
})();
</script>

Common pitfalls and tips:

  • Don’t rely only on the referer header; use UTM as the primary key.
  • Sanitize and limit cookie values.
  • Persist at first touch so later conversions (even after many pages) stay attributed.
  • If debugging, inspect the CGI scope on a test page (as suggested) to see what your server actually receives.

Recommended Answers

All 3 Replies

Use the CGI.HTTP_REFERER variable.

<cfoutput>#CGI.HTTP_REFERER#</cfoutput>

If it returns blank, it means they got to the page directly (user was not taken to it via a URL).

If you want to see a list of other avaiable cgi options, do this code

<cfdump var="#cgi#">

That will show you all kinds of stuff about what the server is storing for you.

If it returns blank, it means they got to the page directly (user was not taken to it via a URL).

.. or that value is blocked by firewall s/w.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.