在谷歌分析中跟踪 facebook 评论小部件的最佳方法是什么? [英] What is the best way to track facebook comment widget in google analytics?

查看:29
本文介绍了在谷歌分析中跟踪 facebook 评论小部件的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将谷歌分析中的事件跟踪应用于通过 facebook 社交插件(iframe 小部件)在我们网站上发表的 facebook 评论,但我似乎找不到附加事件的方法.如果解决方案基于 jquery,我更愿意,但老实说,我对大多数建议持开放态度.

I would like to apply event tracking in google analytics to facebook comments made on our website via the facebook social plugin (iframe widget), but I can't seem to find a way to attach the event. I would prefer if the solution was jquery based, but honostly I'm open to most any suggestion.

推荐答案

您可以使用 Facebook JS SDK 事件订阅,特别是 comment.create 事件回调.

You can use the Facebook JS SDK Event Subscriptions, specifically comment.create event callback.

FB.Event.subscribe('comment.create', function(response){ 
_gaq.push(["_trackEvent", "Facebook Comment", "Posted", response.commentID]);
});

您还可以使用 comment.remove

FB.Event.subscribe('comment.remove', function(response){ 
_gaq.push(["_trackEvent", "Facebook Comment", "Deleted", response.commentID]);
});

我已经对此进行了测试,两者似乎都可以可靠地工作.如果您遇到任何问题,请尝试清除缓存,并务必查看 Facebook SDK 状态页面.

I've tested this, and both appear to work reliably. If you have any troubles, try clearing your cache, and be sure to check the Facebook SDK Status Page.

如果您以异步方式加载 Facebook SDK,则应将这些调用置于异步回调函数中.如果您同步加载 SDK,则只需将它们放在页面上低于 SDK 的位置即可.

If you're loading the Facebook SDK asynchronously, those calls should be placed in the asynchronous callback function. If you're loading the SDK synchronously, they just need to be placed lower on the page than the SDK.

如果评论是对另一个注释(否则,它被设置为 undefined).

The response object will have the commentID, as well as a href attribute, and a parentCommentID, if the comment is a reply to another comment (otherwise, it is set to undefined).

href 属性的用途不明确,但其内容似乎是这样组成的:

The href attribute's purpose is unclear, but its contents appear to be composed as follows:

http://www.facebook.com/plugins/comments_v1.php?app_id=[your-app-id]&xid=276&url=[encodeURIComponent(location.href)]

http://www.facebook.com/plugins/comments_v1.php?app_id=[your-app-id]&xid=276&url=[encodeURIComponent(location.href)]

这篇关于在谷歌分析中跟踪 facebook 评论小部件的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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