@tylek Пришлось еще раз обновить...
private injectGTM() {
const {
id,
isEnabled,
blackList,
} = this.config['GTM'];
if (!isEnabled) {
return;
}
if (isPlatformServer(this.platformId)) {
// ### GTM > head > script
const script = this.renderer2.createElement('script');
script.type = 'text/javascript';
script.text = `
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'
https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','${id}');
`;
this.renderer2.appendChild(this.document.head, script);
// ### GTM > body > iframe
const iframe = this.renderer2.createElement('iframe');
iframe.src =
https://www.googletagmanager.com/ns.html?id=${id};
iframe.height = 0;
iframe.width = 0;
iframe.style = 'display:none;visibility:hidden';
// ###
this.renderer2.appendChild(this.document.body, iframe);
}
}
____
PS: здесь есть проблема, с iframe еще, его нужно обворачивать в <noscript> - пока без этого сделал, иначе вставит пустой noscript без iframe
PS2: Sorry за спам, если что. :)
https://developers.google.com/tag-manager/quickstart?hl=ru