Integrating Google Analytics & HubSpot
Michael Wiegand Sep 9 2014
Google brought Universal Analytics (UA) out of beta earlier this year in April. It’s ushered in an exciting new era where integration with Customer Relationship Management (CRM) systems is possible.
That kind of integration is the holy grail of web analytics — truly closed-loop reporting, from the time a visitor first hits your website, to when they become a lead and, ultimately, a paying customer.
Here at Portent, we use HubSpot for marketing automation and as a checkpoint before our leads are passed into our CRM — Salesforce. So, naturally, we were chomping at the bit to integrate.
Researching the HubSpot integration
If you’ve ever looked into this kind of integration before, Google’s documentation for integrating with popular CRMs is non-existent. There really are no best practices for this. It’s the wild west out there.
A lot of reputable folks have written about integrating with Salesforce, but nobody framed it within the scope of a pre-Salesforce marketing automation pitstop. So I had to cobble an approach together from a few sources.
Finding a Unique Identifier
I started at e-nor’s blog. They wrote an excellent post last year on integrating with Salesforce before UA came out of BETA.
In it, they describe the process of reading Google’s __utma cookie and passing that value into Salesforce as a Visitor Id and into GA as a Custom Variable.
That got my creative juices flowing. If they were reading the __utma cookie, why couldn’t I read another cookie for the same purpose?
Leveraging Google Tag Manager
But this roll-out would be a real pain in the neck if I couldn’t do it programmatically. (I was envisioning a scenario where I’d have to ask my developers to insert an additional piece of script every time a new landing page went up.) Nope, I needed to use Google Tag Manager (GTM) for this.
That’s where Justin Cutroni came in. He wrote an amazing walkthrough on specifying a User ID with Google Tag Manager.
Essentially, you can define a macro in GTM that scrapes a First Party Cookie set on your site and repurpose it in any tags you want to fire, not just User ID.
Putting the pieces together
That got me thinking: HubSpot has its own tracking pixel. Are they already setting an ID in a cookie that I could scrape?
I’m sure you can see where I’m going with this. The answer is yes! They are!
They set a cookie called hutk — a 2-year cookie. And it already gets passed into HubSpot along with every form submission:
From there, it was easy to set a macro in GTM to scrape it:
Then, I pass that value into GA as either a User ID (shown below) or as a Custom Dimension:
The beautiful results
This is what it looks like when it’s all said and done. (I’ve passed in the hutk as a Custom Dimension in this example.)
The same ID associated with my form submission on the site can be tied back to my sessions that led up to that action:
So what’s next?
The possibilities are endless, really. But two things I’m really looking forward to are:
Sorting our HubSpot contacts into buckets by lead quality and passing that information back into GA keying on the UID. You can do this by going to Admin > Data Import in GA and using either the User Data or Custom Data options:
David Simpson launched a Chrome Extension that allows you to take any data exports from HubSpot or any other CRM and inject information back into the analytics UI without actually passing Personally Identifiable Information (PII) into GA — which would violate their terms of service.
Notice now that I can see a user’s email address alongside their behavior in GA. Really powerful stuff!
In 14 years as a marketer, Michael's experience has run the gamut from design, development, direct mail, multivariate testing, print and search. He now heads Portent's Analytics practice, overseeing everything from Google Tag Management, to CRM integration for closed loop analytics, to solving ponderous digital marketing questions. Outside of work, he enjoys recording music, playing JRPGs and supporting Seattle Sounders FC. Read More