Issues Getting GCLID Into Hubspot

Hi all,

Context:

I’m not a programmer, but I have some limited understanding of code and tracking. Currently, I use Google Ads and Hubspot, and want to track offline conversions using Google’s GCLID. I have two types of forms on my site – Hubspot Forms, and non-Hubspot Forms. I use Zapier webhooks to integrate and map my non-Hubpot forms into Hubspot.

I’ve installed Hubspot’s tracking template in my Google Ads account and Hubpot’s tracking code on all my website’s pages using Google Tag Manger.

Situation:

Hubspot Form – No Issues

When a lead submits through a Hubspot form, there are no issues. A new Contact is created and it includes all available web analytics data as well as the GCLID and obviously the fields of the form that the user filled out.

Non-Hubspot Form – Main Issue

However, when a lead submits through a non-Hubspot form, the web analytics data and GCLID don’t come across.

Only the fields that the user filled out get sent into Hubspot.

Side Note: Hubspot’s automatic non-Hubspot form tool does not work reliably enough and in some cases, doesn’t even detect certain forms on my website at all. So this is not a solution.

Points of Interest:

I’ve scrounged the internet to no avail on this. But came across an interesting possiblity that may factor in. It seems that maybe Hubpot’s template or tracking code interfers with Google’s standard way of appending the GCLID to the URL (making it unavailable to my non-Hubspot forms). Currently, the GCLID is not found in the URL. I presume Hubspot is doing something to change where it is stored.

Goal:

I want to get the web analytics data and the GCLID from every form submission, Hubspot and non-Hubspot.

How do I collect the web analytics data and GCLID with my non-Hubspot form in the same way that Hubpot collects it with their own form? Where is this data stored? Does Hubspot change the data’s location? How would I implement it? Hidden fields? etc…

Help on this is much appreciated.

Lorenzo

Hi @Lorenzoenns ,

Because you use Zapier to send the data of your non-hubspot forms to HubSpot you are missing the analytics and GCLID data. HubSpot stores a cookie on your website (if you have added the HubSpot tracking script) called hutk. This cookie is used to identify the user and connect all analytics data of that user to the newly created contact in HubSpot.

I would advise using the non-hubspot form tracking that the HubSpot Tracking script offers or asking a developer to build something with the form submission API so you can pass that cookie to HubSpot.

I figured out how to store and capture the GCLID using the code below in Tagmanager for contacts in Hubspot. However, I still need code to do the same thing for the MSCLKID (Microsoft Click ID for Microsoft Ads). If you know how to fix this problem, please paste the code for tagmanager in the reply.

If you need help with store the GCLID, paste the code below into tagmanager using all pages as the trigger.

<script>

function getParam(p) {
var match = RegExp(‘[?&]’ + p + ‘=([^&]*)’).exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ’ '));
}

function getExpiryRecord(value) {
var expiryPeriod = 90 * 24 * 60 * 60 * 1000; // 90 day expiry in milliseconds

var expiryDate = new Date().getTime() + expiryPeriod;
return {
value: value,
expiryDate: expiryDate
};
}

function addGclid() {
var gclidParam = getParam(‘gclid’);
var gclidFormFields = [‘gclid_field’, ‘foobar’]; // all possible gclid form field ids here
var gclidRecord = null;
var currGclidFormField;

var gclsrcParam = getParam(‘gclsrc’);
var isGclsrcValid = !gclsrcParam || gclsrcParam.indexOf(‘aw’) !== -1;

gclidFormFields.forEach(function (field) {
if (document.getElementById(field)) {
currGclidFormField = document.getElementById(field);
}
});

if (gclidParam && isGclsrcValid) {
gclidRecord = getExpiryRecord(gclidParam);
localStorage.setItem(‘gclid’, JSON.stringify(gclidRecord));
}

var gclid = gclidRecord || JSON.parse(localStorage.getItem(‘gclid’));
var isGclidValid = gclid && new Date().getTime() < gclid.expiryDate;

if (currGclidFormField && isGclidValid) {
currGclidFormField.value = gclid.value;
}
}

window.addEventListener(‘load’, addGclid);

</script>

You will also have to create a property in Hubspot called gclid and change it to hidden on your forms.