Thursday, April 7, 2011

Facebook "Like" and "Share" count same -- A work around

I have been writing a post here after so long. The thing made me write this is about facebook.
We had added facebook LIKE and share buttons to our site. The client posted a bug saying the count of LIKE and share buttons is always the same. After doing some googling I found facebook guys saying the count is of interaction of the link with facebook. For example we put it on www.abc.com/xyz.aspx and someone LIKE it, it will increment the interaction. Then if someone share it on facebook this will also increment the interaction.
I found the work around by chance. :)
Here it is.
FB Share button like the one below


<div class="dvshare" style="float: right; width: 120px;">

            <a href="http://www.facebook.com/sharer.php" name="fb_share" type="button_count">Share</a><script
                src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript">
        </div>

It picks up the current URL from browser, share it and increments the count.
In my case the URL was like this http://www.mydomain.com/myfolder

The browser automatically adds "/" at the end making it "http://www.mydomain.com/myfolder/".

The LIKE button however first look for the canonical tag and send canonical tag to facebook.

Fortunately we had added the canonical tag like this.


<link rel="canonical"  href="http://www.mydomain.com/myfolder" /> i.e. without the "/" at the end.
This made it having different counts for share and LIKE button.
In my personal opinion it is a bug on facebook but.....
Happy coding...:)

2 comments:

  1. Thanks a lot! :-)

    ReplyDelete
  2. You can get your website share count data in json format from http://pgurl.com. Is free.

    ReplyDelete