Capture Google Analytics Client ID in HubSpot

One of the most frustrating aspects about capturing conversion data is later attributing that conversion to an offline sale. So unless you have an integrated ecommerce platform or some point of sale checkout process, using Google Analytics and Google Ads to later map sales from conversions is pretty darn impossible.

Luckily, we can capture the Google Analytics Client ID from our website’s visitors using Google Tag Manger and send them by email, a CRM such as HubSpot, or another storage destination and later import them to report as Offline Conversions.

I came across a guide from Mixed Analytics that gave me the code I needed, shout out to them and thanks!

Watch the video version of this tutorial on YouTube here.

Now let’s get started!

1. Setup email fields

Create a form with what ever method you prefer. In the image on the right, I have used a non-hidden field in Contact Form 7 to easily see my results. To hide an html form field, simply use; type=”hidden” or [hidden textarea-someid] id:guid], in contact form 7. 

Google User ID Capture Form
Form with exposed User ID field
Google User ID in COntact Form 7
Contact Form 7 Setup

2. Capture & store Google Client ID

Head over to Google Tag Manager and click Variables -> New. Then “User-Defined Variables” -> “Custom JavaScript”.

Then, enter the code below and copy the Variable name you set (highlighted in yellow) as we’ll need it in the next step.

function(){
return ga.getAll()[0].get(‘clientId‘);
}

Client ID Tag Manager Variable
Setup Tag Manager Variable

3. Insert Client ID into form field

Setup a New “Custom HTML Tag”. Make sure the last line matches your form field name and the value is where you paste the Variable name we just set up.

<script type=”application/javascript”>
var gclid_field = document.querySelector(“#gclid_field”);
gclid_field.value={{Store GA ID}};
</script>

Insert GCID to Form
Insert GCID to Form

4. Add a Page View Trigger

Now we need to add a Trigger to fire the contact form filler Tag with the Client ID from the previous step.  Just to be safe, we’ll add the Trigger as Page View – Window Loaded, which waits until the entire page is rendered before firing. This should avoid any conflicts.

Load the script only on the pages you will be capturing on. Add as many URLs’ as needed.

Trigger on Window Load
Trigger only on the forms page view

5. Add Trigger to the insert Tag

Next, I’ll add the Trigger to the Tag that inserts the Client ID into the form, called GA ID Filler” on my setup.

Add Trigger to Google Tag
Add Trigger to Google Tag
There is a chance that other scripts on the page that aren’t fully loaded yet can cause a conflict when the Trigger fires. Mixed Analytics was kind enough to add a timed Delay Trigger. If you have issues with the GA ID trigger, check out Step 6 in their article here.

6. Setup HubSpot Fields (optional)

Of course, you can submit your Forms to any source such as; email, Zapier, or another CRM altogether – but I’m using HubSpot today.

Assuming your using HubSpot’s tracking code which detects third-party form submissions, simply setup a contact field to hold our new GCLID.

Navigate to your HubSpot Settings, Click Data Management -> Properties -> Create property. I’ve put mine under the “Conversion information” category.

If you create the internal name to match your forms ID (above we used “gclid_field”) then HubSpot will automatically detect the corresponding field upon submission. If anything, use the field matching process on the Marketing -> Forms Page.

HubSpot & Google Client ID
HubSpot & Google Client ID Setup
HubSpot & Google Client ID
HubSpot Field with Google Client ID

You can learn more about adding custom fields to HubSpot here.

Do you have a creative way of using the captured Google Analytics CID? Share it with us below!

Blog Signup

New posts?

AboutMatt
I'm passionate about uncovering the mysteries that are hidden behind SEO data and search engine algorithms. "Always two there are - a master, and an apprentice."

Leave a Reply