Lead Capture Tools

AvesMarketing
Participant

Submit Cookie Values Upon Form Submission

Hi All,

 

I have an urgent issue and am hoping someone here has the answer. I am trying to pass a cookie value into a hidden field when my contact form is submitted.

 

These are the tools I am using to try and complete this:

  • HubSpot Form
  • Google Tag Manager

These are the steps I have taken (this works with other form builders like Gravity Forms, but not with HubSpot forms).

 

  1. Created a custom field in HubSpot called "msclkid".
  2. Added the field "msclkid" to my contact form as a hidden field. 
  3. Created a cookie on my website via Google Tag Manager that stores the value of the "msclkid" value. 
  4. Created a custom html tag that passes that msclkid cookie value into the hidden field "msclkid".

Everything works in the process except for step 4. 

 

Here is the code I am using to pass the values into my hidden form field. Keep in mind, HubSpot hidden form fields do not have ids, so I am using the name element.

 

<script>
   // msclkid
   (function () {
  var value = "{{url - msclkid}}" //fill with variable which information should be written into the field
  var selector = "input[name='msclkid']"  //fill with CSS Selector that identifies the form field
  var field = document.querySelector(selector)
  if(field){ field.value = value; }
})();
</script>

 

Does anyone see any issues with my code? The value {{url - msclkid}} is the custom GTM variable for my cookie. 

Here is an image of the div for the msclkid:

Screenshot 2023-03-29 at 4.33.23 PM.png

 

Does anyone have an answer for how I can solve this using only Google Tag Manager? I am open to all ideas!

 

 

0 Upvotes
2 Replies 2
PamCotton
Community Manager
Community Manager

Submit Cookie Values Upon Form Submission

Hello @AvesMarketing, thank you for posting in our Community!

I want to invite our top experts to this conversation @jolle @DanielSanchez @amwilie any recommendations for @AvesMarketing 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 !




AvesMarketing
Participant

Submit Cookie Values Upon Form Submission

@jolle @DanielSanchez @amwilie Wanted to follow up with Pam's question and see if you have any insights?

 

0 Upvotes