• Got questions about HubSpot’s Smart CRM?

    Our product team is answering them live through March 6th!

    Ask us anything
  • Ready to build your local HubSpot community?

    HUG leaders host events, spark connections, and create spaces where people learn and grow together.

    Become a HUG Leader

How to pass utm parameters from a cookie into hidden fields?

zangerine1
Member | Gold Partner
Member | Gold Partner

Hi,

 

I have been trying to find the best solution for passing data stored in a cookie into hidden form fields via GTM.

 

Here's an example of how I want it to work:

  • A user clicks on a paid advertisement and visits my site. The user has a utm_source value of facebook.
  • The utm_source value is stored in a cookie. 
  • The user navigates around my website and submits a form.
  • On my form, there is a hidden field named "utm_source".
  • When the user submits a form, I want the pass the value from the cookie into the hidden form field.

I was able to do this for a while by setting the field attribute "value", but recently HubSpot has not been recognizing my GTM script. 

 

Anyone know how to pass the utm data from a cookie into a hidden field? Would love some help on this!

0 Upvotes
1 Accepted solution
karstenkoehler
Solution
Hall of Famer | Partner
Hall of Famer | Partner

Hi @zangerine1,

 

Does this help?

[How-To] Pass Values into Hidden Fields from Google Tag Manager

 

Best regards!

Karsten Köhler
HubSpot Freelancer | RevOps & CRM Consultant | Community Hall of Famer

Beratungstermin mit Karsten vereinbaren

 

Did my post help answer your query? Help the community by marking it as a solution.

View solution in original post

3 Replies 3
azisbak
Member

You're on the right track with storing the UTMs in a cookie when the visitor first arrives, then writing them into hidden fields when they submit a form. The challenge is that maintaining custom JavaScript for this can be tricky (it breaks when HubSpot updates their form code, when browsers change behavior, or when you add new forms to your site).

 

There are dedicated tools like Attributer.io that handle this automatically (disclosure: I am the founder). It captures the UTM parameters when someone first lands on your site, stores them in a first-party cookie, and then writes them into hidden fields on your HubSpot forms when they're submitted. Plus it captures other attribution data like the GCLID, landing page URL, and information on leads that come from organic channels (Organic Search, Organic Social, Direct, etc.) where UTMs aren't present.

 

You could certainly keep trying to solve this with GTM and custom code, but you'll likely run into ongoing maintenance issues as things change (like HubSpot's form rendering changes, or browsers like Safari implement new privacy features). 

 

Hope this helps

 

Note: AI helped me draft this comment, but I've reviewed and refined it based on my experience before posting.

0 Upvotes
karstenkoehler
Solution
Hall of Famer | Partner
Hall of Famer | Partner

Hi @zangerine1,

 

Does this help?

[How-To] Pass Values into Hidden Fields from Google Tag Manager

 

Best regards!

Karsten Köhler
HubSpot Freelancer | RevOps & CRM Consultant | Community Hall of Famer

Beratungstermin mit Karsten vereinbaren

 

Did my post help answer your query? Help the community by marking it as a solution.

Chris_Matt
Member

Thanks for the guide. Unfortunately, this solution didn't work for me. They form listener never recognizes that the HubSpot form has loaded. 

0 Upvotes