Skip to content

Instantly share code, notes, and snippets.

@measureschool
Last active November 1, 2024 21:11
Show Gist options
  • Save measureschool/480ffdee9734cdda9a2f73d8123c66e2 to your computer and use it in GitHub Desktop.
Save measureschool/480ffdee9734cdda9a2f73d8123c66e2 to your computer and use it in GitHub Desktop.
This is a custom HTML tag for GTM that fills out a form field with the data provided by a variable
<script>
(function () {
var value = "{{cookie - __gtm_campaign_url}}" //fill with variable which information should be written into the field
var selector = "input[name='source']" //fill with CSS Selector that identifies the form field
var field = document.querySelector(selector)
if(field){ field.value = value||"(none)"; }
})();
</script>
<script>
(function () {
var value = "" //fill with variable which information should be written into the field
var selector = "" //fill with CSS Selector that identifies the form field
var field = document.querySelector(selector)
if(field){ field.value = value||"(none)"; }
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment