Reputation: 4774
I have more Facebook like buttons on my websites and I was wondering if there's any way to track which one of them was used.
Is there any way of doing this ?
Upvotes: 0
Views: 1959
Reputation: 4306
To track your Facebook Like Buttons the easiest way is to use the XFBML like button. You'll need a Facebook Application ID to do so.
Steps to implement, you need to add a custom XML namespace to the <html>
tag else it won't work in IE, e.g.:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="https://www.facebook.com/2008/fbml">
Then place the following code under the <body>
tag:
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function () {
FB.init({
appId: 'YOUR_FB_APPID',
status: true,
cookie: true,
xfbml: true
});
FB.Event.subscribe('edge.create', function (href, widget) {
// do stuff when something is liked
});
FB.Event.subscribe('edge.remove', function (href, widget) {
// do stuff when something is unliked
});
};
(function () {
var e = document.createElement('script');
e.async = true;
e.src = 'http://connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
} ());
</script>
Then add your Facebook Like buttons on your web page like so:
<fb:like href="http://mydomain.com/path/to/page" send="false" layout="button_count" width="80" show_faces="false" font=""></fb:like>
Cheers!
Upvotes: 6
Reputation: 38135
Have you checked the Like Plugin FAQ in the documentation?
What is the best way to know which Like button on my page generated the traffic?
Add the 'ref' parameter to the plugin (see "Attributes" above).
Examples:
<fb:like ref="top_left"></fb:like>
<iframe src="...&ref=top_left"></iframe>
I suppose the info should appear in the Facebook Insights page.
Upvotes: 6
Reputation: 449425
If you mean "track" directly on the page, no. The "Like" button is in an iframe
element, you will have no access to it due to the Same Origin Policy.
If you mean "track" as in track it afterwards through the API, I asked a similar question once: Creating "Like" buttons for arbitrary elements on my site, and reading back the status - possible? and got a hint about the API - not sure whether this can be done there (I never followed up on it), but maybe worth a look.
Upvotes: 2