Skip to content

Instantly share code, notes, and snippets.

@measureschool
Last active August 4, 2023 09:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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