assayo/scripts/add-analytics.js

36 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2024-05-03 08:34:46 +00:00
const fs = require('node:fs');
const YandexMetrika = `
<script type="text/javascript" >
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
m[i].l=1*new Date();
for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }}
k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");
ym(94903985, "init", {
clickmap:true,
trackLinks:true,
accurateTrackBounce:true,
webvisor:true
});
</script>
<noscript><div><img src="https://mc.yandex.ru/watch/94903985" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
`;
2024-06-26 22:37:34 +00:00
const GoogleAnalytics = `
<script async src="https://www.googletagmanager.com/gtag/js?id=G-MRZGLE32FG"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-MRZGLE32FG');
</script>
`;
2024-05-03 08:34:46 +00:00
const html = fs.readFileSync('../build/index.html', 'utf8');
const text = html
2024-06-26 22:37:34 +00:00
.replace(/<\/body>/gim, `\n${YandexMetrika}\n${GoogleAnalytics}\n</body>`);
2024-05-03 08:34:46 +00:00
fs.writeFileSync('../build/index.html', text);