Did you ever get a good lead on your website and wonder "How did these guys find us?"  Was it from the ad we ran on that trade website, our PPC campaign or our SEO efforts?

You can always go into Google Analytics and see how people are finding your site in general but Google Analytics doesn't report on personal user data, so it doesn't tell you how any specific leads found your site.  You would normally have to figure that out for yourself, which depending on lead volume, can be a painstaking process. It would be good to have an easy way to be able to attribute a lead to the specific way they found you...good news, there is! A great way to do this is to have that referrer data inserted (using Javascript) directly into each new lead email you get.

We found a cool (and absolutely free) script that pulls visitor referrer data out of Google Analytics and inserts it directly into your lead form.  (We originally found this tip on Analytics Talk). What does this mean?  When someone fills out the form on your site and you get a new lead with Name, Email Address, Phone, etc, you will also get other valuable info in that email such as the search engine the lead used to find you and the actual keyword they typed to find you.

Knowing that the lead came from Google and exactly what keywords they typed to find you can be useful information to have before you follow up with the lead.  It can also help you make better marketing decisions moving forward because you'll know which sources are providing the highest quality leads (or lowest quality).

You get other data as well.  Here's detailed info on each of the additional fields you will get:

  • source:  Search engine or website that sent the lead (e.g. Google, Bing, CNN)
  • medium:  The medium that directed the visitor(s) to your site (e.g. cpc, organic, direct, referral).
  • term: Keyword the lead used to find your site.
  • content: The first line of the text for your online ad campaign.
  • campaign:  The name(s) of the online ad campaigns you have used for your website.
  • numVisits:  Number of previous visits to your website.  Is this a new or returning visitor?

This sounds pretty cool and useful.  How do I set it up?

All you have to do is insert the following lines of code onto any page on your site that has a lead form.

var z = _uGC(document.cookie, '__utmz=', ';');

var source = _uGC(z, 'utmcsr=', '|');

var medium = _uGC(z, 'utmcmd=', '|');

var term = _uGC(z, 'utmctr=', '|');

var content = _uGC(z, 'utmcct=', '|');

var campaign = _uGC(z, 'utmccn=', '|');

var gclid = _uGC(z, 'utmgclid=', '|');

if (gclid !="-") {

source = 'google';

medium = 'cpc';


var csegment = _uGC(document.cookie, '__utmv=', ';');

if (csegment != '-') {

var csegmentex = /[1-9]*?.(.*)/;

csegment = csegment.match(csegmentex);

csegment = csegment[1];

} else {

csegment = '(not set)';


var a = _uGC(document.cookie, '__utma=', ';');

var aParts = a.split(".");

var nVisits = aParts[5];

function populateHiddenFields(f) {

f.source.value = source;

f.medium.value = medium;

f.term.value = term;

f.content.value = content;

f.campaign.value = campaign;

f.segment.value = csegment;

f.numVisits.value = nVisits;

return false;


For lead based business, adding this simple script to your lead form pages is a great way to add more insight into what is/isn't working for you. If you don't know how to add javascript to your pages, ask your developer to do it for you. It should be a relatively quick and inexpensive addition for them to make.

A nice thing about this approach is that it can be used with almost any type of lead generation form. You can use a CRM to collect and store the data or you could use a simple text file.