ilh*_*han 102 html javascript performance html5 google-analytics
Google Analytics网站速度功能如何_gaq.push(['_trackPageLoadTime'])
运作?有没有关于它如何工作的文件?
Yah*_*hel 181
编辑:自2011年11月16日起,该_trackPageLoadTime
函数已被弃用,其功能已设置为默认设置.(从功能上讲,它已经从选择加入功能变为退出功能.)
_setSiteSpeedSampleRate
是用于设置此功能的采样率的新功能; 其默认值为1
(以1%为单位).要选择不使用此网站速度功能,您必须传递0
给此功能:
_gaq.push(["_setSiteSpeedSampleRate", 0]);
Run Code Online (Sandbox Code Playgroud)
此报告目前支持以下浏览器:Chrome,Internet Explorer 9以及安装了Google工具栏的Internet Explorer的早期版本.更具体地说,站点速度报告需要支持HTML5 NavigationTiming界面的浏览器或安装了Google Internet Explorer工具栏
因此,它不像许多以前的homeback解决方案那样实现自己的计时器,以确定加载页面需要多长时间.相反,它使用新的HTML5功能,目前仅在上面列出的情况下支持,称为NavigationTiming.
编辑:Firefox 7现在支持此功能
(需要注意的是,它不会在每次加载时运行;相反,它目前会对大约2%的综合浏览量进行采样,但它配置为尝试跟踪10%访问次数上的所有页面加载;随着越来越多的浏览器支持NavigationTiming API,您可以预期总采样百分比开始接近10%.)
可以使用属性(so,)在DOM对象window.performance
(或早期版本的Chrome window.webkitPerformance
)下访问此界面.该对象存储所有关键页面加载事件时间的测量值,并且Google Analytics减去2个更重要的外部值以判断页面加载速度.timing
window.performance.timing
对于没有缓存的Mashable.com的负载,这里是它测量的一个示例(在Chrome 11中):
timing = {
connectEnd: 1306677079337,
connectStart: 1306677079337,
domComplete: 1306677083482,
domContentLoadedEventEnd: 1306677081765,
domContentLoadedEventStart: 1306677081576,
domInteractive: 1306677081576,
domLoading: 1306677079478,
domainLookupEnd: 1306677079337,
domainLookupStart: 1306677079337,
fetchStart: 1306677079337,
loadEventEnd: 1306677083483,
loadEventStart: 1306677083482,
navigationStart: 1306677079337,
redirectEnd: 0,
redirectStart: 0,
requestStart: 1306677079394,
responseEnd: 1306677079669,
responseStart: 1306677079476,
secureConnectionStart: 0,
unloadEventEnd: 0,
unloadEventStart: 0
}
Run Code Online (Sandbox Code Playgroud)
这些数字是1970年1月1日以来的纪元毫秒或毫秒.我没有看到任何关于它们减去哪些值来生成它们的值的文档,但是从粗略检查ga.js看起来它是loadEventStart-fetchStart
:
h&&h[c]!=k&&h.isValidLoadTime?b=h[c]:e&&e[a]&&(b=e[a].loadEventStart-e[a].fetchStart);
Run Code Online (Sandbox Code Playgroud)
对于上面的示例,这意味着它将在通话中记录4.14秒_trackPageLoadTime
.
如果要使用HTTP GET或等效的方式获取新资源,则fetchStart必须在用户代理开始检查任何相关应用程序缓存之前立即返回时间.否则,它必须返回用户代理开始获取资源的时间.
此属性必须返回当前文档的加载事件触发之前的时间.当load事件未被触发时,它必须返回零.
对于好奇的派对,排序似乎如下:
connectStart,connectEnd,domainLookupStart,domainLookupEnd,fetchStart,navigationStart,requestStart,responseStart,domLoading,responseEnd,domContentLoadedEventStart,domInteractive,domContentLoadedEventEnd,domComplete,loadEventStart,loadEventEnd
对于列出的0值:
unloadEventStart
并unloadEventStart
显示上一页加载卸载的时间(但仅当该页面与当前页面具有相同的原点时.)
redirectEnd
并redirectStart
测量页面加载链中是否存在HTTP重定向时添加的延迟.
secureConnectionStart
似乎是测量SSL连接时间的可选测量.