Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌分析标签_Javascript_Google Analytics - Fatal编程技术网

Javascript 谷歌分析标签

Javascript 谷歌分析标签,javascript,google-analytics,Javascript,Google Analytics,我有当前代码来跟踪页面上滚动条的百分比 ga('create', 'UA-68653010-1', 'auto'); window.onbeforeunload = function(){ var viewportHeight = $(this).height(); var progress = $(this).scrollTop() / ($(document).height() - viewportHeight); ga('send', 'event', 'scroll', Ma

我有当前代码来跟踪页面上滚动条的百分比

ga('create', 'UA-68653010-1', 'auto');
window.onbeforeunload = function(){
  var viewportHeight = $(this).height();
  var progress = $(this).scrollTop() / ($(document).height() - viewportHeight);
  ga('send', 'event', 'scroll', Math.round(progress*100));
};
但是,每当事件发送命中时,它都会返回一个与预期不同的参数,其中一个参数是:

exd:ReferenceError:ga未定义

按照正确的顺序包含JS文件(片段)

首先包括此脚本:

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)
[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-68653010-1', 'auto') ; 
</script>

是否包含加载analytics.js库的代码?其中一个参数是全局跟踪器函数的名称,如果您传入了任何内容而不是“ga”,那么跟踪器函数将不会被定义,您需要相应地更改名称。问题就在这里!但不知何故,当我在控制台上运行代码时,点击正常发送,当我将代码放在tagmanager上时,它就不起作用了。非常感谢。
    window.onbeforeunload = function(){
      var viewportHeight = $(this).height();
      var progress = $(this).scrollTop() / ($(document).height() - viewportHeight);
      ga('send', 'event', 'scroll', Math.round(progress*100));
};