How to track clicks on a facebook like button
Posted by navaneeth on Nov 14, 2012 in Javascript | No comments yet
Sometime its necessary to check whether someone clicks on or makes like on the facebook like button
and the facebook provide an call back function
this is the normal code to add facebook like button
<div id="fb-root"></div> <script type="text/javascript"> (function() { var e = document.createElement('script'); e.type = 'text/javascript'; e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; e.async = true; document.getElementById('fb-root').appendChild(e); }()); </script> <fb:like href="URL" layout="standard|button_count" show-faces="true|false" width="450" action="like|recommend" colorscheme="light|dark" font="arial|lucida grande|segoe ui|tahoma|trebuchet ms|verdana"></fb:like>
By adding this snippet of code to the above code we can track the likes
window.fbAsyncInit = function() { FB.init({appId: 'YOUR_FACEBOOK_APP_ID', status: true, cookie: true, xfbml: true}); FB.Event.subscribe('edge.create', function(href, widget) { // Do something, e.g. track the click on the "Like" button here alert('You just liked '+href); }); };
And we can only track the like as there is no method to track dislikes
Leave a Reply