Facebook "Like" button callback
Asked Answered
M

5

55

I am interested in implementing the facebook "Like" button, but I would like to know what user is clicking on this button so I can get some useful information from this. From what I have read, facebook is leaving us in the dark on who is clicking on what. ANyone have an idea on how I could track which user clicked on a like button for a particular product?

UPDATE: The like button is rendered by facebook either through an iFrame, or through xFBML. This is why it is difficult to track who clicks on what, or embed an onclick event, etc..

Manufacture answered 9/5, 2010 at 18:15 Comment(1)
D
64
<script>
  FB.Event.subscribe('edge.create', function(href, widget) {
    alert('You just liked the page!');
  });
</script>
Dup answered 30/8, 2011 at 3:42 Comment(3)
just to put some reference: developers.facebook.com/docs/reference/javascript/…Soften
this seems to be not working. looks like im missing something so obvious to others. :(Witt
can someone point me out what im missing on this question #52042904Witt
H
9

so I simply rendered a unique like button for each logged in user with a URL of www.somewebsite.com/thisIsThePageIlike/facebookUID.

won't this defeat the purpose of having a like button and mess up your facebook search ranking? Every user will be liking a different url and so facebook will think you have a ton of pages each with a single like count.

I am also having an issue with XFBML like buttons where the edge.create event isn't firing

Henequen answered 28/6, 2011 at 23:6 Comment(0)
M
6

OK, so I can let you know how I implemented it. What I wanted to get was the UID of the facebook user clicking on the "Like" button inside my facebook connect app. I noticed when a user clicks on the "like" button, facebook fetches the URL passed to it from the button, so I simply rendered a unique like button for each logged in user with a URL of www.somewebsite.com/thisIsThePageIlike/facebookUID. When a request come to the web server with this url, it works like a callback and I process and record the UID if its the first time a user has clicked "like" (ie.. a record of this 'like' does not exist in the db). works for me.

Manufacture answered 13/5, 2010 at 2:8 Comment(0)
C
0

It would be something like the one I have for my client's site such as

<iframe src="http://www.facebook.com/plugins/like.php?href=www.jesterkaraoke.com&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;" allowTransparency="true"></iframe>
Corporal answered 19/12, 2010 at 4:25 Comment(0)
C
-1
window.fbAsyncInit = function () {

    FB.Event.subscribe('edge.create', function (response) {
        alert('Liked');
        });
    }
    );
    FB.Event.subscribe('edge.remove', function (response) {
        alert('DisLiked')
    });
};

(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.7";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

HTML:-

<div id="fb-root"></div><div class="fb-like" data-href="https://www.facebook.com/testpage" data-layout="standard" data-action="like" data-size="small" data-show-faces="true"></div>
Centigram answered 9/9, 2016 at 11:52 Comment(1)
At least make sure your code is syntactically valid before posting it publicly, especially on platforms like SO where you are supposed to help othersHydrobomb

© 2022 - 2024 — McMap. All rights reserved.