我可以爲Google分析找到一個新的(至少對我來說是新的)代碼。如果我明白,它會異步加載(至少在代碼中有單詞異步)。我在我的網站的一個頁面中使用了該代碼,Google Page Speed仍然說:利用瀏覽器緩存http://www.google-analytics.com/ga.js利用瀏覽器緩存Google Analytics
這是跟蹤Google Analytics的最後一個和最佳代碼嗎?使用Google Analytics並在Page Speed中獲得良好迴應的最佳方式是什麼?
(你必須通過自己的代碼來替代UA-XXXXX-Y)
https://developers.google.com/analytics/devguides/collection/analyticsjs/
<!-- Google Analytics -->
<script>
(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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
感謝您的解釋以簡單的方式。如果我明白,在本地託管它將解決頁面速度警告,但Google服務器託管仍然是最佳解決方案。 – Nrc
是的,Google不會在搜索結果中讓你失望,因爲在頁面速度測試中少了一個點,這也不會影響你的用戶,所以我只能按照個人的意願離開它。如果你確實想要擺脫那個警告,你可以按照我的回答。 – maembe