GTM is great… until you try to write modern JavaScript. Then it feels like you’ve traveled back in time to 2008.
What’s the issue?
GTM only supports ECMAScript 5, meaning let and const are a no-go — your container won’t even publish if you use them. So, if you were hoping to write clean, modern JS, tough luck!
But there’s a workaround!
GTM processes <script> tags through Closure Compiler, turning them into <script type="text/gtmscript">. These are just inert data blocks — until GTM decides to run them.
The trick? Instead of <script>, use <script type="text/gtmscript">. GTM won’t try to compile it, but it will execute it on the page.
Result: You get to use modern JavaScript in GTM without breaking anything.
Huge thanks to Florian Götting for this awesome trick!
If you work with GA4 to BigQuery exports, be sure to check out my SQL cheat sheet.