How to track twitter follow us & facebook like us?

386 views Asked by At

Is it possible to track users who like us or follow us on website. Also I want to track if some one unfollowing or unlike us. If there an api or any trick to do this?

Thanks to all

2

There are 2 answers

0
avs099 On

check out edge.create event - see more here: https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/

edge.create - fired when the user likes something (fb:like).

edge.remove - fired when the user unlikes something (fb:like).

regarding capturing twitter event - see here: https://dev.twitter.com/docs/intents/events

  • Include widgets.js
<script type="text/javascript" charset="utf-8">
  window.twttr = (function (d,s,id) {
    var t, js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;
    js.src="//platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);
    return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } });
  }(document, "script", "twitter-wjs"));
</script>
  • Bind to an event when the user has clicked the Tweet Button:
twttr.events.bind('click', function(event) {
    var click_type = event.region;
});
0
CaptainBli On

avs099 is correct and the link will provide some good info. But I thought I would post some further information to help others as they find this link.

I used the FB.init() function to call a setup function that creates the callback functions for the edge.create and edge.remove.

FB.Event.subscribe('edge.create',
function(response) {
    alert('You liked the URL: ' + response);
    //ajax back to the server.
    var xmlhttp;
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("POST", "YourCapturePage.php", true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.send(response + "&add=1");
});

YourCapturePage.php or what ever processing page can then parse the response and add a record to your database back-end to track the usage of your like button on a given page. The response contains the info about what page was liked. Then you can do something similar for the edge.remove.