It suggests implementing this code on every page AFTER the HubSpot tracking code.
I have two questions here:
We've implemented the HubSpot tracking code via GTM and therefore don't have the HS tracking code in our CMS directly. It's therefore unclear to me where we should install the Gclid tracking code. Can we still install it like it is (into our CMS or GTM?) or do I first need to replace the GTM tag by installing the initial HS tracking code on all pages and then paste this code after HS tracking code?
Would I be able to expand this code in order to track other UTM parameters via the cookie, are there examples of code that I can install?
*** Important note, I'm not a developer and don't have much coding skills **
Hi @Kaythlin_Das, that github repo you linked is an external resource that we can't really support as it's not maintained by us and might be prone to break. That said, if you use GTM, you should be at least loading all your scripts at some location, so conceivably adding the code below that line would be your best bet. I did find an old forum post on this topic that links to an article here so you may want to check that out as well.
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;
Hi @Kaythlin_Das, that github repo you linked is an external resource that we can't really support as it's not maintained by us and might be prone to break. That said, if you use GTM, you should be at least loading all your scripts at some location, so conceivably adding the code below that line would be your best bet. I did find an old forum post on this topic that links to an article here so you may want to check that out as well.