Trying to use GTM Cookie to save value of utm_source on landing page to hidden field in Feathery

Explaining my situation:

I’m attempting to use Google Tag Manager to capture the entry URL’s UTM_Source into a cookie so that I can then use that cookie later as the value for my hidden ‘utm_source’ field on the Feathery form.

It seems I’m running into an issue where I can’t correctly reference my Feathery form’s selector and the ‘id’ of the hidden field ‘utm_source’ and would like help there.

This is for my Aruza Buy Online form if some support admin would like to access my account.

This is what the code currently looks like:

<script>
  document.addEventListener('DOMContentLoaded', function() {
    var utmSource = '{{Cookie - utm_source}}';
    var form = document.querySelector('#container > form'); // Replace with your form's ID or class
    if (form && utmSource) {
      var utmField = form.querySelector('input[name="utm_source"]'); // Replace with your hidden field's name
      if (utmField) {
        utmField.value = utmSource;
      }
    }
  });
</script>

Any insights or walkthroughs or guidance would be greatly appreciated for this subject.

WHY I’M DOING THIS:

  • When a user visits a landing page with utm_sources in the URL, if they buy online then and there - I capture the value of the utm_source - however, if they click off of that landing page and lose that source parameter, I then cannot match that conversion to the proper entry source.

Cheers,

Ian

Hey Ian, we don’t support grabbing and setting field values in that manner. If you want to capture field values from your url parameters for an embedded form, you can turn that on in your form settings for that to happen automatically. If you want to do it via custom logic, please reference our docs for best practices: onLoad() | Feathery Docs