简体   繁体   中英

Load google analytics javascript few seconds after the page has loaded

I am wondering what happens if I lazy load Google Analytics JavaScript few seconds after the page has loaded (ie few seconds after the document and all images/stylesheet/javascript is loaded). Will it still record the statistics correctly? I am trying to defer loading of javascript in order to improve my page load time; GA-JS is one of the 6 scripts that I plan to lazy load.

PS: I know how to lazy-load the script.

It will obviously exclude all users that close their browser before your intentional delay has elapsed. So the counts will be wrong. And this will influence the "bounce rate" number reported in Google Analytics significantly. I recommend not trying to improve page the load time of Google Analytics. Google has already invested significantly in trying to optimize that. And every site that uses Google Analytics is paying the same load time penalty. So it's a level playing field. Just follow their best practices for where to put the code snippet and look for other opportunities to improve page load time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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