Ads

SpaceAge
Member

Hubspot GCLID Stripping

After integrating my hubspot with my google ads the gclid in my url's keep being stripped from people clicking on my google ads. I have changed all of my url parameters and made sure auto tagging on so it is not an issue on google ads end. This only started happening when I integrated hubspot. I have since removed it from my hubspot but the issue persists

0 Upvotes
2 Replies 2
Danielle1
Participant

Hubspot GCLID Stripping

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. 

PamCotton
Community Manager
Community Manager

Hubspot GCLID Stripping

Hello @SpaceAge, Happy new year 🎆

 

Could you please provide us more information about your ads, such as links or screenshots?

The more information, screenshots, and details you can provide, the better I can advise on the next steps.

 

I will also tag some top experts to be able to share their opinion, @Daniel_Bleich@EmmaWashington@ajchapman20 what would you recommend to @SpaceAge matter?

 

Thank you!

Pam

 

 

 

Você sabia que a Comunidade está disponível em outros idiomas?
Participe de conversas regionais, alterando suas configurações de idioma !


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !