使用Google Analytics(分析)跟踪div上的点击 [英] To track clicks on a div using google analytics
问题描述
我有多个具有唯一ID的DIV.每个DIV onclick都会向下滑动并在其下方显示一些内容.
I have multiple DIVs with unique IDs. Each DIV onclick slides down and shows some content below it.
我想跟踪每个DIV的点击次数,以了解哪个DIV被点击最多.
I would like to track the clicks on each DIV to know which DIV is being clicked the most.
我该如何使用Google Analytics(分析)?
How do I do this with google analytics?
推荐答案
听起来您正在寻找Google Analytics(分析)事件跟踪".假设您已经设置了常规的GA代码段(以跟踪您的网站),则可以设置处理程序(对于div的点击,可以说是)使用jQuery执行类似的操作:
It sounds like you're looking for Google Analytics "Event Tracking." Assuming you already have your regular GA code snippet set up (to track your site), you can then set up a handler (for clicks of the div, let's say) do to something like this with jQuery:
$('.trackerClass').click(function() {
var selId = $(this).attr('id');
_gaq.push(['_trackEvent', 'Interactions', 'Click', selId]);
});
您要跟踪的每个div都可以将"trackerClass"作为类,并具有唯一的ID以帮助您识别它.
Every div that you wanted to track could have both "trackerClass" as the class, and a unique ID to help you identify it.
如果您想单独跟踪打开/关闭,则可以添加一个状态变量并也将其传递.
If you wanted to track opens/closes individually, you could add a state variable and pass that as well.
可在此处获得更多信息:
More information is available here:
编辑:对于简明的JavaScript,kennis的答案即可.
Edit: for straight JavaScript, kennis' answer will do it.
这篇关于使用Google Analytics(分析)跟踪div上的点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!