The Sticky Cookie
The Sticky Cookie
The Sticky Cookie
Google Analytics is an invaluable tool for gaining these types of insights. Every time an
anonymous visitor goes to your website, Google Analytics automatically detects the specific
source that led them there—whether that be Google search, Facebook, or a referral from an
online industry publication. These sources are also automatically grouped into broader
marketing channels, called Mediums, which often include organic, cpc, social, referral, email,
and direct.
In order to associate traffic with paid campaigns, Google allows you to add parameters to a URL
that identify important reporting data about your campaign like the site where the ad appeared,
the campaign name, ad creative, and the search term that was targeted. These are often
referred to as “UTM tags”, and typically look something like this:
http://yourdomain.com/?utm_source=adsite&utm_campaign=adcampaign&utm_term=adkeywor
d
Unfortunately, this only works if the tagged URL is also the page where the form is placed. If the
conversion funnel requires that the user navigate to multiple URLs, the values of the UTM tags
that were used on the landing page will not automatically persist throughout the visit.
It also doesn’t account for the vast majority of traffic to your site coming from non-paid channels
like organic search, referrals, and direct visits.
This is where an integration with Google Analytics becomes critical. Since Google Analytics is
already capturing this data, it should be pretty straightforward to take that data and pass it over
to Marketo and Salesforce, right? Wrong. Unfortunately it’s not so easy.
Do a quick Google search and you’ll find tons of scripts that were designed to extract the values
from the cookie and pass them into hidden form fields. For a while, this solved the problem.
Unfortunately these scripts no longer work because with the new version of Google Analytics,
called Universal Analytics, all tracking happens at the server-side and the cookie set by the new
analytics.js contains no information about the user's traffic sources.
Technically, the classic Google Analytics tracking script still works, so you could simply place
the old version on your site until Google no longer supports it.
Since this isn’t a good permanent solution, we chose to go with the script e-nor created, which
mimics the classic Google Analytics cookie and can be found here. With the tracking script
problem resolved, we can now focus our efforts on extracting that data from the cookie and
passing them to hidden fields in a Marketo form.
The Solution: Make UTM Values Sticky, And Then Store Them In
Hidden Marketo Fields
If you follow the steps below you’ll be able to capture a lead’s referring campaign, source,
medium, ad content, and keyword and carry those values all the way through the sales funnel,
from initial form submission to won opportunity. To do this, we’ll start at the end and work
backwards. Note: We are limiting the scope of some of these tags just to run on certain sites so
we don’t change everyone’s Salesforce and Marketo reports at once, but eventually we will roll it
out to all Northeastern sites and won’t need to limit the scope anymore.
<script>
/*
* To populate mkto form fields from cookie
*/
function fillAllFormVals(){
var z = _uGC(document.cookie, "__utmz=", ";"),
source = _uGC(z, "utmcsr=", "|"),
medium = _uGC(z, "utmcmd=", "|"),
term = _uGC(z, "utmctr=", "|"),
content = _uGC(z, "utmcct=", "|"),
campaign = _uGC(z, "utmccn=", "|"),
gclid = _uGC(z, "utmgclid=", "|"),
allForms = MktoForms2.allForms();
if (gclid !="-") {
source = "google";
medium = "cpc";
}
var passedVals = {
"GA_Medium__c_account":medium,
"GA_Source__c_account":source,
"GA_Campaign__c_account":campaign,
"GA_Term__c_account":term,
"GA_Content__c_account":content,
"LeadSource":medium,
"Lead_Source_Detail__pc":source
}
function _uGC(l,n,s){
if (!l || l=="" || !n || n=="" || !s || s=="") return "-";
var i,i2,i3,c="-";
i=l.indexOf(n);
i3=n.indexOf("=")+1;
if (i > -1) {
i2=l.indexOf(s,i); if (i2 < 0){ i2=l.length; }
c=l.substring((i+i3),i2);
}
return c;
}
(function(){
fillAllFormVals();
}());
</script>
If you chose to use different labels for your custom fields, you’ll want to modify the field labels
referenced in the script to match your own.
Since Marketo forms aren’t populated until after the page has fully loaded, you’ll want to
leverage a custom event triggered by the Marketo Form Listener to trigger this tag. For your
firing trigger, create a Custom Event called mkto.form.ready.
If you’ve implemented everything correctly and you’re using the Hidden Form Finder extension,
you should see hidden field values that look something like this: