A while back I wrote a post about how you can integrate Google Analytics with a CRM system. That posts referenced the old
urchin.js code and is in need of an update. Plus a lot of people have been asking me about different integration options and I thought it would be a good time to revisit the topic.
So here it is, an update. I’m not going to re-do the entire post, just a few key points.
Why Do This?
hack configuration is based on one simple idea: to build a more robust view of customers/prospects/leads/whatever-you-call-them. The more information we know about people that we sell to the more we can adjust our marketing. This technique let’s us combine where the visitor came from (referral, campaign, direct, search engine) and how often they’ve been to the site with CRM data.
How It Works
We’re going to extract data from the GA tracking cookies and add it to a lead generation form. The GA data will be stored in hidden form elements that the visitor can not see. When the visitor submits the form the GA will be connected to the other information that the visitor entered into the form (usually name, contact information, etc.).
Here’s the data that we’re going to pull from the GA cookies:
* Current referral information (i.e. where the visitor came from)
* Custom segment value (if it exists)
* How many times the visitor has been to the site
You’re probably wondering why we’re not extracting the data via the GA API. More on that in a minute.
Here it is, the updated code:
The new code differs from the original code in three ways:
First, the inclusion of
ga.js. No explanation needed there.
The second change is the addition of the
_uGC() function. This function was in the original
urchin.js, and because I don’t include that file I need to include the code in the script.
The function is used to parse pieces of data and return certain parts. For example, I use to to parse the cookies (which are just a string) and return the value of the campaign cookie (
__utmz), the custom segment cookie (
_utmv) and the visitor identification cookie (
Finally, I added some new functionality to include this visitor’s number of visits. This data is pulled from the
__utma cookie (which identifies the visitor). The last integer in __utma is actually a visit counter. I think it is interesting to understand behavior based on frequency so I added this nugget of data.
If you want to see the code in action try this:
In my previous post I included a reference section that documents the format of the campaign cookie and the
_uGC() function. Check it out if you’re looking for more technical information.
An Alternate Approach
Remember, all the data we’re pulling is in first party cookies. This means that you could extract the info at the server level rather than the browser level (first party cookies are available to server side code).
I’m just trying to provide some inspiration here :)
What About the Google Analytics API?
I’m sure there are a lot of people out there wondering about the GA API and why I don’t just use it to pull data out from GA. The reason is the data in GA is all anonymous, aggregated data. There’s no way to reach into GA and say, “tell me where John Doe came from.” That’s why we pull data from the cookie, because we can combine it with a visitor’s info when they supply it.
Sure, it is possible to pull out GA data and place it in a CRM (like traffic from an email campaign, bounce rate from paid search, etc.) but it’s tough to identify individuals in that data.
Is it impossible? No, not from a technical standpoint. You would need to place a unique identifier in GA to link the data.
But we’re getting into a risky area here.
Remember, it is against the GA terms of service to capture data in GA that identifies an individual. This could be an email address or database ID number. Not my rule, Google’s, and they will crack down.
I’d be interested to hear people’s thoughts on this. Feel free to comment!