I'm trying to add a Google Analytics config value to index.html
. This value will differ from staging and production, so it should be configurable, preferrably via an env file. I've seen some answers here in SO about this, but they're all very old (4+ years), so there may be a different way in modern Angular.
Basically, I need to make the following code accept variables:
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', <google analytics id>);
</script>
<!-- Google Tag Manager -->
<script>
(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', <google tag manager id>);
</script>
AppComponent
?