【发布时间】:2015-09-09 13:45:21
【问题描述】:
我正在尝试使用谷歌分析跟踪我网页中的所有社交互动,以便我可以在 Acquisition --> Social --> plugins 下查看它们。
目前我可以跟踪 facebook 的点赞和发送按钮,但不跟踪分享按钮。我找不到共享按钮的任何特定代码。网络上的大多数代码都被提到用于共享/发送,但共享没有被跟踪。我提供了下面的代码
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r; i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new
Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;
m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxxxx', 'auto');
ga('send', 'pageview');
</script>
</head>
<body>
<div id="fb-root"></div>
<script>
$(document).ready(function(){
alert('doc loaded');
});
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxxxxxxxxxxxxxx',
status : true,
xfbml : true
});
//Logged In Users
FB.getLoginStatus(function(response) {
if (response.status !== "unknown") {
ga('set', 'dimension1', 'Logged In');
}
});
//Facebook Likes
FB.Event.subscribe('edge.create', function(href, widget) {
var currentPage = $(document).attr('title');
ga('send', {
'hitType': 'social',
'socialNetwork': 'Facebook',
'socialAction': 'Like',
'socialTarget': href,
'page': currentPage,
'hitCallback': function() {
alert('like done sending data');
}
});
});
//Facebook Unlikes
FB.Event.subscribe('edge.remove', function(href, widget) {
var currentPage = $(document).attr('title');
ga('send', {
'hitType': 'social',
'socialNetwork': 'Facebook',
'socialAction': 'Unlike',
'socialTarget': href,
'page': currentPage,
'hitCallback': function() {
alert('unlike done sending data');
}
});
});
//Facebook Send/Share
FB.Event.subscribe('message.send', function(href, widget) {
var currentPage = $(document).attr('title');
ga('send', {
'hitType': 'social',
'socialNetwork': 'Facebook',
'socialAction': 'Send',
'socialTarget': href,
'page': currentPage,
'hitCallback': function() {
alert('send done sending data');
}
});
});
//Facebook Comments
FB.Event.subscribe('comment.create', function(href, widget) {
var currentPage = $(document).attr('title');
ga('send', {
'hitType': 'social',
'socialNetwork': 'Facebook',
'socialAction': 'Comment',
'socialTarget': href,
'page': currentPage,
'hitCallback': function() {
alert('comment done sending data');
}
});
});
};
// Load Facebook SDK
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.4& appId=xxxxxxxxxxxx";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<p><a href="www.example.in" >Some Text </a></p>
<script src="//connect.facebook.net/en_US/all.js#xfbml=1"></script>
<fb:like></fb:like>
<div class="fb-share-button" data-href="https://example.com" data-layout="button_count"></div>
<div class="fb-send" data-href="http://example.com"></div>
</body>
</html>
我从这个链接https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/v2.4 看到了 FB.event.subscribe 方法参数,但是没有具体的 share 参数。 我究竟做错了什么?还是无法在 facebook 中跟踪分享按钮。
【问题讨论】:
-
不幸的是,我认为这不可能与 FB 事件有关。所有可能的事件都在您提供的文档中,因此如果不存在,您将无法执行。
标签: javascript facebook google-analytics facebook-social-plugins analytics.js