google统计js不能加载解决

由于统计域名无法访问,导致网页错乱,可以将统计js添加到页面加载完成后再加载,就不会影响页面了。

  1. <!-- Global site tag (gtag.js) - Google Analytics -->
  2. <!-- Modified By Ricardo (Tongtong) Liu -->
  3. <!-- <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXX-Y"></script> -->
  4. <script>
  5. window.dataLayer = window.dataLayer || [];
  6. function gtag(){dataLayer.push(arguments);}
  7. gtag('js', new Date());
  8. gtag('config', 'UA-XXXXX-Y');
  9. window.addEventListener('load', function(){
  10. var s = document.createElement('script');
  11. s.src = "https://www.googletagmanager.com/gtag/js?id=UA-XXXXX-Y";
  12. document.body.appendChild(s);
  13. });
  14. </script>
huan

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: