Track Facebook Like Button Event

Why Track Facebook Like Button Event

Lets take an example of any online Store.

We want to show some coupon code, when user Like my Product.
In That case we need to '''Track Facebook Like Button Event'''.

'''We can track the Facebook like Activity  '''
To Track the Activity following Points are Important:

  1. We can Track Facebook Like button Click only by XFBML Method.

  2. '''FB.Event.subscribe''' Method is used to Track the Like and Unlike.




Sample Code

<html>
<head>
<script type="text/javascript" src="jquery-latest.js"></script>
<script src="http://connect.facebook.net/en_US/all.js#appId=197607353625066&amp;xfbml=1"></script>
<script type="text/javascript">
$(document).ready(function() {


window.fbAsyncInit = function() {
FB.init({appId: '', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('edge.create', function(href, widget) {
$('#response').html('You have subscribed it.');
});
FB.Event.subscribe('edge.remove', function(href, widget) {
$('#response').html('you have unsubscribed it.');
});
};
});

</script>
</head>
<body>

<div id="response"></div>
<div id="fb-root"></div>
<fb:like href="http://subjekt.com" send="false" width="450" show_faces="false" font=""></fb:like>
</body>
</html>

This Method executes when you Perform Like Activity.

FB.Event.subscribe('edge.create', function(href, widget) {
$('#response').html('You have subscribed it.');
});


This Method executes when you Perform UnLike Activity.

FB.Event.subscribe('edge.remove', function(href, widget) {
$('#response').html('you have unsubscribed it.');
});

Comments

Popular posts from this blog

How to check browser cookie enabled with php and javascript

cookie and subdomains

Output buffering in php