谷歌分析代码返回'未定义函数“;错误

Google Analytics Code Returns 'Undefined Function" Error

本文关键字:未定义 函数 错误 代码 返回 谷歌      更新时间:2023-09-26

无论我做什么,我都会收到一个关于点击跟踪谷歌分析代码的"Uncaught TypeError:undefined不是函数"错误。

页面为:http://www.purevisionmethod.com/eye-exercises/

拜托,为什么会发生这种事。。。?

<script>
$('#clicked-headerbar').on('click', function() {
  ga('send', 'event', 'website-banner', 'clicked-ad', 'headerbar', '0');
});
$('#clicked-cta-bottom').click( function() {
  ga('send', 'event', 'website-banner', 'clicked-ad', 'cta-bottom', '0');
});
$('#clicked-sidebar-image-ad-1').click( function() {
  ga('send', 'event', 'website-banner', 'clicked-ad', 'sidebar-ad-1', '0');
});
$('#clicked-sidebar-image-ad-2').click( function() {
  ga('send', 'event', 'website-banner', 'clicked-ad', 'sidebar-ad-2', '0');
});
$('#clicked-sidebar-image-ad-3').click( function() {
  ga('send', 'event', 'website-banner', 'clicked-ad', 'sidebar-ad-3', '0');
});
</script>

谢谢你的帮助!!

该错误与Google Analytics无关。

这个错误是因为您在这个使用jQuery的代码之后包含了jQuery库。将这段代码移到jQuery-include下面,或者将jQuery-inlude移到这段代码之前,它就会起作用。

首先在Google Analytics上注册您的跟踪id。然后谷歌将为您提供一个代码块,其中将包括一些带有您注册的跟踪id的javascript代码。将该代码放入您的网页,然后在谷歌分析代码的下面写上上面的代码。

我实际上将其确定为有问题的行:

$('#clicked-headerbar').on('click', function() {
  ga('send', 'event', 'website-banner', 'clicked-ad', 'headerbar', '0');
});

将.on()更改为.click(),如下所示:

$('#clicked-headerbar').click( function() {
  ga('send', 'event', 'website-banner', 'clicked-ad', 'headerbar', '0');
});

不确定为什么会发生这种情况,但是您的页面正在加载两个版本的jQuery。