html Google AnalyticsJavaScript增强功能:将网络时间效果数据推送到GA自定义变量中

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html Google AnalyticsJavaScript增强功能:将网络时间效果数据推送到GA自定义变量中相关的知识,希望对你有一定的参考价值。

<html>
<head>
<script type="text/javascript">var yoHeadTime = new Date().getTime();</script>
</head>
<body>
<script type="text/javascript">
//<![CDATA[
var _gaq = _gaq || [];
(function() {
  var reportTimeSegment = function(index, name, start, end, scope) {
    if( (start && end) && (end-start > 0) ) {
      var distance = Math.round( (end-start)/100 )*100;
      _gaq.push(["_setCustomVar", index, name, distance, scope]);
    }
  };
  var onLoadHandler = function() {
    var onLoadTime = new Date().getTime();
    reportTimeSegment(1, "headToOnLoad", yoHeadTime, onLoadTime, 3);
    var webTiming = ( window.performance || 
                      window.mozPerformance ||
                      window.msPerformance ||
                      window.webkitPerformance );
    if( webTiming && webTiming.timing ) {
      var navTime = webTiming.timing.navigationStart || null;
      var responseEndTime = webTiming.timing.responseEnd || null;
      reportTimeSegment(2,"navToResponseEnd", navTime, responseEndTime, 3);
      reportTimeSegment(3,"navToOnLoad", navTime, onLoadTime, 3);
    }
    _gaq.push(["_setAccount","UA-xxxxxxxx-yy"],
              ["_trackPageview"]);
  };
  if(!window.addEventListener) {
    window.attachEvent("onload", onLoadHandler);
  } else {
    window.addEventListener("load", onLoadHandler, false);
  }
  var ga = document.createElement('script');
  ga.type = "text/javascript"; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(ga,s);
})();
//]]>
</script>
</body>
</html>

以上是关于html Google AnalyticsJavaScript增强功能:将网络时间效果数据推送到GA自定义变量中的主要内容,如果未能解决你的问题,请参考以下文章

Google 协作平台 HTML 框 - 剥离 Javascript

HTML Google翻译-适用于中国和世界其他地区

搜索值,然后在Google表格中查找并使用google apps脚本在html中显示行值

如何在 HTML 页面中使用 Google 字体

带有 HTML 工具提示的 Google 图表

google hosts