_gaq.push(['_trackPageLoadTime'])如何工作? [英] How does _gaq.push(['_trackPageLoadTime']) work?

查看:241
本文介绍了_gaq.push(['_trackPageLoadTime'])如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google Analytics网站速度功能 _gaq.push(['_ trackPageLoadTime'])是如何工作的?有没有关于它是如何工作的任何文档? 截至2011年11月16日, a href =http://code.google.com/apis/analytics/community/gajs_changelog.html#release-2011-11 =nofollow noreferrer> _trackPageLoadTime 功能已被弃用,其功能已被设置为默认设置。 (从功能上讲,它已经从一个选择退出功能变为退出功能。)



_setSiteSpeedSampleRate 是用于设置此功能上采样率的新功能;其默认值是 1 (如1%)。要选择不使用此网站速度功能,您必须将 0 传递给此函数:

  _gaq.push([_ setSiteSpeedSampleRate,0]); 






Google Analytics帮助中心


此报告目前支持下列浏览器的
:Chrome,Internet
资源管理器9和以前版本的
Internet Explorer并安装了Google
工具栏。更具体地说,网站速度报告
需要支持HTML5
NavigationTiming界面的
浏览器或安装
Google Internet Explorer工具栏

浏览器


因此,它并没有像许多先前的回传解决方案一样实现自己的计时器,以确定页面加载需要多长时间。相反,它使用了一种新的HTML5功能,目前仅在上面列出的情况下才支持,名为NavigationTiming。

编辑:现在在火狐7



(重要的是要注意,它不会不会在每次加载时运行;相反,它目前占浏览量的2%左右,尽管它被配置为在尝试访问10%的网页时跟踪所有页面加载;随着更多浏览器支持NavigationTiming API, )

这个接口可以在DOM对象下访问window.performance (或者在早期版本的Chrome中, window.webkitPerformance ),使用 timing 属性(所以, window.performance.timing )。对象存储所有关键页面加载事件时间的测量值,Google Analytics(分析)会减去2个较重要的外部值来判断页面加载速度。



对于没有缓存的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
}

这些数字是自纪元毫秒或以来的毫秒数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); 

对于上面的示例,这意味着它会在 4.14秒 _trackPageLoadTime 呼叫。

来自W3C Navigation Timing规范:

lockquote

fetchStart属性 p>

如果要使用HTTP
GET或等价的方式获取新的
资源,fetchStart必须
返回紧接在$ b $之前的时间b用户代理开始检查任何
相关的应用程序缓存。
否则,当用户代理开始获取
资源时,它必须返回时间



loadEventStart属性



这个
属性必须在
加载事件之前立即返回时间
,当前文档被触发。它的
必须在加载事件
没有被触发时返回零。


对于好奇的参与者,看起来如下:

lockquote
connectStart,connectEnd,
domainLookupStart,domainLookupEnd,$ b $ f fetchStart,navigationStart,
requestStart,responseStart,
domLoading,responseEnd,
domContentLoadedEventStart,
domInteractive,
domContentLoadedEventEnd,domComplete,
loadEventStart,loadEventEnd

对于列出的0值:

unloadEventStart unloadEventStart 显示上一次页面加载卸载的时间(但只有当该页面与当前页面具有相同的原点时才可用。)


$ b $如果在页面加载链中存在HTTP重定向,则测量所添加的延迟。如果在页面加载链中存在HTTP重定向,则会添加新的延迟。


secureConnectionStart 似乎是衡量SSL连接时间的可选衡量指标。

How does the Google Analytics Site Speed feature, _gaq.push(['_trackPageLoadTime']), work? Is there any documentation about how it works?

解决方案

Edit: As of November 16th 2011, the _trackPageLoadTime function has been deprecated and its functionality has been set as a default setting. (Functionally speaking, it has gone from being an opt-in feature to being an opt-out feature.)

_setSiteSpeedSampleRate is the new function for setting the sample rate on this feature; its default value is 1 (as in 1%). To opt out of using this the Site Speed feature, you have to pass a 0 to this function:

_gaq.push(["_setSiteSpeedSampleRate", 0]);


From the Google Analytics Help Center:

This report currently supports the following browsers: Chrome, Internet Explorer 9 and previous versions of Internet Explorer with the Google Toolbar installed. More specifically, the Site Speed reports require browsers that support the HTML5 NavigationTiming interface or have the Google Internet Explorer toolbar installed

So, it doesn't implement its own timer, like many prior homeback solutions had, to figure out how long it takes a page to load. Instead, it uses a new HTML5 feature, currently only supported in the above listed cases, called NavigationTiming.

EDIT: This is now supported in Firefox 7

(Important to note that it doesn't run on every load; instead, it currently samples around 2% of pageviews, though it is configured to try to track all page loads on 10% of visits; as more browsers support the NavigationTiming API, you can expect the total sampled percentage to begin to get closer to 10%.)

This interface is accessed under the DOM object window.performance (or, in earlier versions of Chrome, window.webkitPerformance), using the timing attribute (so, window.performance.timing). The object stores measured values of all of the key page load event times, and Google Analytics subtracts 2 of the more important outer values to judge page load speed.

For a load of Mashable.com without cache, here's an example of what it measures (in 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
}

Those numbers are epoch milliseconds, or milliseconds since January 1, 1970. I have not seen any documentation as to which values they subtract to generate their values, but from a cursory inspection of the ga.js, it looks like it is loadEventStart-fetchStart:

h&&h[c]!=k&&h.isValidLoadTime?b=h[c]:e&&e[a]&&(b=e[a].loadEventStart-e[a].fetchStart);

For the above sample, that means it would record 4.14 seconds in the _trackPageLoadTime call.

From the W3C Navigation Timing spec:

fetchStart attribute

If the new resource is to be fetched using HTTP GET or equivalent, fetchStart must return the time immediately before the user agent starts checking any relevant application caches. Otherwise, it must return the time when the user agent starts fetching the resource.

loadEventStart attribute

This attribute must return the time immediately before the load event of the the current document is fired. It must return zero when the load event is not fired yet.

For curious parties, the ordering appears to be as follows:

connectStart, connectEnd, domainLookupStart, domainLookupEnd, fetchStart, navigationStart, requestStart, responseStart, domLoading, responseEnd, domContentLoadedEventStart, domInteractive, domContentLoadedEventEnd, domComplete, loadEventStart, loadEventEnd

For the 0 values listed:

unloadEventStart and unloadEventStart show the times for the previous page load's unloading (but only if that page has the same origin as the current one.)

redirectEnd and redirectStart measure the latency added if there was an HTTP redirect in the page load chain.

secureConnectionStart appears to be an optional measurement for measuring the SSL connection time.

这篇关于_gaq.push(['_trackPageLoadTime'])如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆