【问题标题】:Google Analytics Code Returns 'Undefined Function" ErrorGoogle Analytics 代码返回“未定义函数”错误
【发布时间】:2014-10-24 02:58:57
【问题描述】:

无论我做什么,点击跟踪 Google Analytics 代码都会收到“Uncaught TypeError: undefined is not a function”错误。

页面为: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>

感谢您的帮助!!

【问题讨论】:

    标签: javascript google-analytics


    【解决方案1】:

    该错误与 Google Analytics(分析)无关。

    错误是因为您在此代码之后包含了 jQuery 库 ,该代码使用了 jQuery。将此代码移动到您的 jQuery 包含下方,或将您的 jQuery 包含移动到此代码之前,它会起作用。

    【讨论】:

      【解决方案2】:

      首先在Google Analytics 上注册您的跟踪ID。然后 Google 会为您提供一段代码,其中将包含一些带有您注册的跟踪 ID 的 javascript 代码。将该代码放入您的网页中,然后在 Google Analytics 代码下方编写上述代码。

      【讨论】:

        【解决方案3】:

        我实际上认为这是违规行:

        $('#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。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-04-18
          • 2023-03-13
          • 1970-01-01
          • 1970-01-01
          • 2014-11-11
          • 2018-03-16
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多