public
Last active

Tracking FB social actions

  • Download Gist
FB Like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<div id="fb-root"></div>
<script>
(function() {
window.fbAsyncInit = function() {
FB.Event.subscribe('edge.create', function(response) {
_gaq.push(['_trackSocial', 'facebook', 'like', response]);
});
FB.Event.subscribe('edge.remove', function(response) {
_gaq.push(['_trackSocial', 'facebook', 'unlike', response]);
});
};
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js#xfbml=1';
document.getElementById('fb-root').appendChild(e);
}());
</script>
FB Share
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<script>
FB.ui({
method: 'feed',
message: 'Come checkout Laid back radio',
name: 'Laid Back',
caption: 'on Mixcloud',
description: ‘Laid back is an internet medium...’,
link: 'http://www.mixcloud.com/laidbackradio/’,
picture: 'http://mixcloud.com/lb.jpg',
actions: [
{ name: 'fbrell', link: 'http://fbrell.com/' }
]
},function(response) {
if (response && response.post_id) {
_gaq.push(['_trackSocial', 'facebook', 'share', response]);
}
});
</script>
FB request 2.0
1 2 3 4 5 6
<script>
FB.ui({
method: 'apprequests',
message: 'You should visit Mixcloud.'
});
</script>
FB send
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<div id="fb-root"></div>
<script>
(function() {
window.fbAsyncInit = function() {
FB.Event.subscribe('message.send', function(response) {
_gaq.push(['_trackSocial', 'facebook', 'send', response]);
});
};
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js#xfbml=1';
document.getElementById('fb-root').appendChild(e);
}());
</script>

Better, more feature-rich custom code snippets to use in place of Facebook's one-line javascript integration examples.

Async FB social buttons + Async Google analytics calls.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.