不能直接使用google analytics的手动安装代码,不能直接添加到html页面中,不然会报错;
Refused to load the script 'https://www.googletagmanager.com/gtag/js?id=G-WDMVX87J6G' because it violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
正确逻辑:
要先手动去将gtag.js下载到本地,然后通过本地代码的方式添加进去
打开这个链接,然后复制返回的js代码,新建一个gtag.js文件保存:
在本地保存一个gtag.js:
然后在工具类中添加剩余的js代码:
然后就OK了