通过jQuery插件进行Google Analytics事件跟踪 [英] Google Analytics Event Tracking via a jQuery plugin

查看:114
本文介绍了通过jQuery插件进行Google Analytics事件跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

概念验证始于此:

 < 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

我想告诉你,这给了我灰色头发,但这是不可能的,因为它让我把我所有的头发都拉出来。请帮忙。这真的开始打扰我了。谢谢。

也许试试 window._gaq.push



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

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

您也可以将任意函数传递给窗口。 _gaq.push()来帮助调试:

  window._gaq.push(function() {alert('推到_gaq的函数)}); 

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


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. Thanks.

解决方案

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.

这篇关于通过jQuery插件进行Google Analytics事件跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆