I am trying to parse UTMs and get them into fields but it seems that my script won't publish on GTM.
(the script works when directly put on webflow custom code)
var queryString = window.location.search;
console.log(queryString);
// ?utm_source=facebook&utm_medium=post&utm_campaign=webflow
var URLSearchParams_wb = new URLSearchParams(queryString);
const utmParameters = [
"utm_campaign",
"utm_source",
"utm_medium",
"utm_content",
"utm_term"
];
for (const utm_element of utmParameters) {
/* if utm_source exist */
if(URLSearchParams_wb.has(utm_element)){
console.log(utm_element + " : is exist");
/* get UTM value of this utm param */
var value = URLSearchParams_wb.get(utm_element)
/* change form hidden feild to this utm url value */
$("."+utm_element).val(value);
}
}/* end for loop */
</script>```
Any idea ?
Yes, GTM has troubles adopting ES6. Therefore:
The rest should be good. Give it a shot.