简体   繁体   English

Google Analytics跟踪代码缩小了

[英]Google Analytics Tracking code minified

I've setup a new property (universal, not classic) and I've copied and pasted the tracking code directly before the on my pages. 我已经设置了一个新属性(通用,而不是经典),我已经在我的页面上直接复制并粘贴了跟踪代码。

When I view the source, I see the tracking code BUT modPagespeed is automatically minifying the inline JS. 当我查看源代码时,我看到跟踪代码BUT modPagespeed会自动缩小内联JS。

If I go to my tracking code details in Analytics, it says my tracking code isn't installed. 如果我在Google Analytics中查看我的跟踪代码详细信息,则说明我的跟踪代码未安装。 Been trying for 2 hours. 已经尝试了2个小时。

Is google's pagespeed module breaking the analytics script? 谷歌的pagespeed模块是否打破了分析脚本? How can I work around this? 我该如何解决这个问题?

Maybe this can help if you are still looking for an answer or may help someone that is having the same problem now. 如果您仍在寻找答案或者可能帮助现在遇到同样问题的人,这可能会有所帮助。

If I minify my html with a minification I get page speed 93 but Chrome Console says Unexpected token. 如果我通过缩小缩小我的html,我会获得93页的页面速度,但Chrome控制台会说出意外的令牌。 It is the GA code that does it. 这是GA代码。 There is one line break that causes it in my ga code. 在我的代码中有一个换行符导致它。 Maybe same problem you are having? 也许你有同样的问题?

If I put: 如果我把:

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ <!--L I N E B R E A K-->
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXXXX-1', 'auto'); ga('send', 'pageview');

it works and I get page speed 92 它工作,我得到页面速度92

BUT if I deleted the line break and put 但是如果我删除了换行符并放了

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXXXX-1', 'auto'); ga('send', 'pageview');</script>

Google Console says js invalid token but I get page speed 93...sigh. 谷歌控制台说js无效令牌,但我得到页面速度93 ...叹息。 Seems pagespeed can spot that the code is not completely minified with that one line break that seems to break the analytics script. 似乎pagespeed可以发现代码没有完全缩小,只有一个换行符似乎打破了分析脚本。

Ideas how to fix welcome! 想法如何解决欢迎!

/Johan /约翰

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM