Tracking multiple Facebook "Like" buttons on one page
On my blog I have a global "Like" button in the header embedded with this code:
<div id="fb-root"></div><fb:like href="http://www.domain.com/blog/" send="false" layout="button_count" width="120" show_faces="false" font="arial"></fb:like>
This shows up on every page of the site. In addition, I've got "Like" buttons for each post that app开发者_StackOverflow中文版ears on the site using this code:
<div id="fb-root"></div><fb:like href="http://www.domain.com<? the_permalink() ?>" send="false" layout="box_count" width="55" show_faces="false" font="arial"></fb:like>
In the <head>
of all pages I include the Facebook script (I replaced my app ID with X's here):
<script src="http://connect.facebook.net/en_US/all.js#appId=XXXXXXXXXXXXXXX&xfbml=1"></script>
The buttons are working perfectly well, but I'm trying to interaction with these buttons and can't seem to get any feedback with any but the first (global) button. In a scripts.js
file loaded at the bottom of the page I have this snippet of code for the tracking:
FB.Event.subscribe('edge.create', function(targetUrl) {
console.log(targetUrl);
//_gaq.push(['_trackSocial', 'facebook', 'like', targetUrl]);
});
Only the first, global "Like" button will print the targetUrl
to the console. The others on the page don't print anything to the console.
What am I doing wrong here?
If your site is still in the works, are your posts' URLs live on the Web? If not, that would explain your problem. Like Buttons only work correctly for URLs that Facebook can reach. If you're testing on a staging server, be sure that the Like Buttons are set to Like your staging URLs.
Take a look at this tutorial.
精彩评论