如何_gaq.push([' _trackPageLoadTime '])的工作吗?

时间:2021-10-25 15:18:15

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

谷歌分析站点速度特性_gaq.push(['_trackPageLoadTime'])如何工作?有关于它如何工作的文档吗?

1 个解决方案

#1


180  

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.)

编辑:到2011年11月16日,_trackPageLoadTime函数已经被弃用,其功能被设置为默认设置。(从功能上来说,它已经从一个选择加入的特性变成了一个选择退出的特性。)

_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:

_setSiteSpeedSampleRate是为该特性设置采样率的新函数;它的默认值是1(1%)。要选择不使用这个站点速度特性,您必须将0传递给这个函数:

_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

该报告目前支持以下浏览器:Chrome, ie9和ie浏览器的早期版本,安装了谷歌工具栏。更具体地说,网站速度报告要求浏览器支持HTML5 NavigationTiming接口或安装谷歌Internet Explorer工具栏

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.

因此,它不像许多以前的homeback解决方案那样,实现自己的计时器来计算加载一个页面需要多长时间。相反,它使用了新的HTML5特性,目前只支持上面列出的案例,名为NavigationTiming。

EDIT: This is now supported in Firefox 7

编辑:这在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%.)

(需要注意的是,它并不是在每个负载上运行;相反,它目前抽样了大约2%的页面浏览量,尽管它被配置为试图跟踪10%的访问量的所有页面负载;随着越来越多的浏览器支持NavigationTiming API,您可以期望总采样百分比开始接近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.

此接口可在DOM对象窗口中访问。性能(或者,在Chrome的早期版本中,windows . webkitperformance),使用timing属性(因此,windows .performance.timing)。对象存储所有关键页面加载事件时间的测量值,谷歌分析减去2个更重要的外部值来判断页面加载速度。

For a load of Mashable.com without cache, here's an example of what it measures (in Chrome 11):

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

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:

这些数字是历元毫秒,或者自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);

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

对于上面的示例,这意味着它将在_trackPageLoadTime调用中记录4.14秒。

From the W3C Navigation Timing spec:

fetchStart attribute

fetchStart属性

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.

如果使用HTTP GET或等效项来获取新资源,fetchStart必须在用户代理开始检查任何相关的应用程序缓存之前返回时间。否则,它必须返回用户代理开始获取资源的时间。

loadEventStart attribute

loadEventStart属性

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

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

For the 0 values listed:

对于列出的0个值:

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.)

unloadEventStart和unloadEventStart显示前一页装载卸载的时间(但前提是该页面的起点与当前页面相同)。

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

redirectEnd和redirectStart度量在页面加载链中存在HTTP重定向时所增加的延迟。

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

secureConnectionStart似乎是用来度量SSL连接时间的一个可选度量。

#1


180  

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.)

编辑:到2011年11月16日,_trackPageLoadTime函数已经被弃用,其功能被设置为默认设置。(从功能上来说,它已经从一个选择加入的特性变成了一个选择退出的特性。)

_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:

_setSiteSpeedSampleRate是为该特性设置采样率的新函数;它的默认值是1(1%)。要选择不使用这个站点速度特性,您必须将0传递给这个函数:

_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

该报告目前支持以下浏览器:Chrome, ie9和ie浏览器的早期版本,安装了谷歌工具栏。更具体地说,网站速度报告要求浏览器支持HTML5 NavigationTiming接口或安装谷歌Internet Explorer工具栏

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.

因此,它不像许多以前的homeback解决方案那样,实现自己的计时器来计算加载一个页面需要多长时间。相反,它使用了新的HTML5特性,目前只支持上面列出的案例,名为NavigationTiming。

EDIT: This is now supported in Firefox 7

编辑:这在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%.)

(需要注意的是,它并不是在每个负载上运行;相反,它目前抽样了大约2%的页面浏览量,尽管它被配置为试图跟踪10%的访问量的所有页面负载;随着越来越多的浏览器支持NavigationTiming API,您可以期望总采样百分比开始接近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.

此接口可在DOM对象窗口中访问。性能(或者,在Chrome的早期版本中,windows . webkitperformance),使用timing属性(因此,windows .performance.timing)。对象存储所有关键页面加载事件时间的测量值,谷歌分析减去2个更重要的外部值来判断页面加载速度。

For a load of Mashable.com without cache, here's an example of what it measures (in Chrome 11):

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

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:

这些数字是历元毫秒,或者自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);

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

对于上面的示例,这意味着它将在_trackPageLoadTime调用中记录4.14秒。

From the W3C Navigation Timing spec:

fetchStart attribute

fetchStart属性

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.

如果使用HTTP GET或等效项来获取新资源,fetchStart必须在用户代理开始检查任何相关的应用程序缓存之前返回时间。否则,它必须返回用户代理开始获取资源的时间。

loadEventStart attribute

loadEventStart属性

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

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

For the 0 values listed:

对于列出的0个值:

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.)

unloadEventStart和unloadEventStart显示前一页装载卸载的时间(但前提是该页面的起点与当前页面相同)。

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

redirectEnd和redirectStart度量在页面加载链中存在HTTP重定向时所增加的延迟。

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

secureConnectionStart似乎是用来度量SSL连接时间的一个可选度量。