Gclid tracking via cookie


Hi there,

I'm looking into a solution to track the Gclid parameter (and potentially other UTM parameters) via the cookie and hidden field in Hubspot.

I've found the following post on GitHub that describes a good solution: https://gist.github.com/jakebellacera/54d30aa662b706aecf633664b96c60a6

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 :smiley: **

Many thanks!


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.

For your second question, this blog post might help out with using utm parameters in HubSpot: https://blog.hubspot.com/marketing/what-are-utm-tracking-codes-ht

Hope this helps set you on the right path :slight_smile:


Thanks @Connor_Barley! I've tested a few things and believe I got it to work correctly now :slight_smile: