2

I am getting frustrated. I want to use custom html code in GTM, for numerous reasons. I am trying to integrate a basic Google Ads code via GTM, but it doenst accept the following :

 window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    gtag('config', 'AW-XXXXX');

GTM tells me that this is not valid :

"Error on line 10 and caracter 9 : This language feature is only supported for ECMASCRIPT_2015 mode or better: block-scoped function declaration."

Which is really irritating me, because it's their own code... any suggestions?

jeremy
  • 105
  • 10
  • 1
    Does this answer your question? [Error in Google Tag Manager: this language feature is only supported for ECMASCRIPT6 mode or better](https://stackoverflow.com/questions/66187474/error-in-google-tag-manager-this-language-feature-is-only-supported-for-ecmascr) – Daniel W. Aug 10 '22 at 15:16

1 Answers1

3

On a Google help page, it says you shouldn't use custom html code for gtag integration.

Please try this instead, turning the gtag function declaration into an expression:

window.dataLayer = window.dataLayer || [];
var gtag = function () { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'AW-XXXXX');
Daniel W.
  • 31,164
  • 13
  • 93
  • 151
  • 1
    Indeed, Google doesnt recommend custom code but I need to use it that way And THANKS, your suggestion seems to work perfectly, thanks ! – jeremy Aug 10 '22 at 16:11