Skip to content

Instantly share code, notes, and snippets.

@mbaersch
Created June 20, 2025 08:57
Show Gist options
  • Save mbaersch/1df204eceda48100457e7cc52a70b4e6 to your computer and use it in GitHub Desktop.
Save mbaersch/1df204eceda48100457e7cc52a70b4e6 to your computer and use it in GitHub Desktop.
Transforms GTM HTML code with variables for testing in console
function gtmTagCode(fCode, delimiter="'", replacement="", run=false){
if (replacement && replacement != "") {
fCode = fCode.replace(/{{.*}}/gi, replacement)
} else
fCode = fCode.replace(/({{|}})/gi, delimiter)
if (run===true) eval(fCode); else console.log(fCode)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment