简体   繁体   中英

How GA tracks page load time on _trackPageView?

I am stuck in a situation where I am left with no open end on a problem. Let me put the problem first. We are trying to improve the performance of a webpage. We already have GA tracking on it. We fire '_trackPageView' on every page visit and we don't use any 'site speed tracking'. In GA reporting we find the dom load time is around 5s and the page load time is around 13s.

To reduce the page load time, we want to load all the js scripts which are not necessary at load time, asynchronously after page load. But the problem is we are not sure when the '_utm' image beacon (_tackaPageView) is fired. If it is fired only after all the asyn resources are loaded, the page load time will increase further.

So we tried debugging ga.js. _pageTrackView is fired on window onload. After that there are no other GA requests fired. But the one thing which we are not able to figure out is, how GA is able to track the dom load time, page load time etc., There's no such trace in the request. There is one epoch current time stamp, which is stored _ utma cookie, for instance ' _utma=1.417929071.1376029504.1376029504.1376040649.2'. I learnt that the last but one parameter '1376040649' is the time stamp of when user entered the page in current session. Remaining are all about the first visit, visitor id etc., There a request parameter which has no explanation anywhere 'utmht', for example 'utmht:1376040648577'. '1376040648577' is a timestamp which is equal to the __utma timestamp except for the milliseconds part. Apart from this I don't find any time stamp or anything that is related to time. But GA tracks that all. How? It has become a mystery to us. I tried figuring it out on numerous sources. Not one has any answer or explanation.

Any help would be greatly appreciated.

Finally found the answer. Posting it as it might help someone else.

_trackPageLoadTime() is deprecated.

GA does track pageload by default on _pageTrackView , but not on all requests. It uses sampling rate on client side to send 'pageload timing' information to server. The default rate is 1%. That means for every 100 _pageTrackView requests, only one time ANOTHER request is sent with all page load information. We can also set the client sampling rate to any value using _gaq.push(['_setSampleRate', '80']) . When I set the sampling rate to 100, on all the requests, pageload time tracking beacon was also sent. There ends the mystery.

This document might help, especially the notes section at the bottom which could point you in the right direction as to how page timings works.

https://support.google.com/analytics/answer/1205784?hl=en

Hope this helps

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