我想知道如何将下面的google analytics代码添加到所有页面都在访问的外部js文件中。
现在我所有html文件中的代码:
<script async src="https://www.googletagmanager.com/gtag/js?id=XXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'XXXXXXXXXX');
</script>
我希望它是怎样的:
html:
<head>
<script src="/js/google.js"></script>
</head>
google.js:
## Some code that does the same as the code the above. I tried adding the exact snippet, but I don't think it works because of the <script> tags, and I don't know how to remove them since one has an "SRC" attribute.
任何帮助都将不胜感激,因为我在网上其他地方找不到答案。
1条答案
按热度按时间xhv8bpkk1#
尝试将此添加到您的
/js/google.js
文件: