通过 jQuery 插件进行 Google Analytics 事件跟踪

发布于 2024-12-26 06:59:54 字数 594 浏览 0 评论 0原文

概念验证是这样开始的:

<script type="text/javascript">
    $(document).ready(function() {
    $('.evnttrk1').click(function() {
    _gaq.push(['_trackEvent', 'coming_soon', 'footer_icons', $(this).attr('id')]);
});
});

这样,任何具有 eventrk1 类的链接都会触发 Google Analytics 事件。这效果很好。

从那里我决定将其整合到一个合适的插件中,并在此过程中添加一些功能。该插件的所有内容均有效,除了我无法使用 _gaq.push 向 Google 发送事件。我没有收到错误。我什么也没得到。

我在即将推出的页面上运行了该插件: http://AcaciaNJ.com

我想告诉你这一点给了我白发,但那是不可能的,因为它让我把所有的头发都拔掉了。请帮忙。这真的开始困扰我了。

The proof of concept started with this:

<script type="text/javascript">
    $(document).ready(function() {
    $('.evnttrk1').click(function() {
    _gaq.push(['_trackEvent', 'coming_soon', 'footer_icons', $(this).attr('id')]);
});
});

With this, any link with a class of eventrk1 would trigger a Google Analytics Event. This worked just fine.

From there I decide to roll it into a proper plugin, adding some functionality along the way. Everything about the plugin works except I can't get the _gaq.push to send events to Google. I'm not getting an error. I'm not getting anything at all.

I have the plugin running on this coming soon page: http://AcaciaNJ.com

I'd like to tell you this gave me gray hairs but that's not possible since it made me pull all my hair out. Please help. This is really starting to bother me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瀟灑尐姊 2025-01-02 06:59:54

也许尝试一下window._gaq.push

您可以通过测试 window._gaq 来检测 _gaq 对象是否可用:

if (window._gaq) {
    alert('_gaq found');
} else {
    alert('_gaq not found');
}

您还可以将任意函数传递给 window._gaq.push() 来帮助调试:

window._gaq.push(function() {alert('Pushed function to _gaq')});

我还注意到您的脚本将第五个参数传递给 _trackEventval。这必须是一个整数,如果它是一个字符串,跟踪将不起作用。

Maybe try window._gaq.push?

You can detect if the _gaq object is available by testing for window._gaq:

if (window._gaq) {
    alert('_gaq found');
} else {
    alert('_gaq not found');
}

You could also pass an arbitrary function to window._gaq.push() to help with debugging:

window._gaq.push(function() {alert('Pushed function to _gaq')});

I also noticed that your script passes a fifth argument to _trackEvent, val. This has to be an integer, and tracking will not work if it is a string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文