How to track Facebook likes/unlikes in Google Analytics

It is nice to be able to track various statistics for your website using Google Analytics. It really helps you understand what pages web traffic tend to visit, how they get there, etc. Another nicety is to track social media responses (e.g., Facebook like button clicks) to your pages. You technically can track Facebook like button clicks using the the Facebook Insights tool (http://www.facebook.com/insights/), but it really is very limited and I have found it to be buggy. I prefer to use Google Analytics to track these social media responses because you much more easily see what pages received the responses, how many responses, and correlate it with other metrics available in Analytics. You can even track several social interactions other than just Facebook while you’re at it (like Twitter, Google +1 and even AdSense). The major selling point is accessing all of this from a single tool.

In this post I am specifically addressing how to track Facebook social responses. Tracking the Facebook likes and dislikes for your pages in Analytics is very simple. Assuming you already have added the Facebook like/unlike buttons to your site (by generating the code yourself at http://developers.facebook.com/docs/reference/plugins/like/ or by using a plugin like the WordPress “Facebook Likes You!” plugin), then you only need to add the following code to your site to start tracking the like/unlike responses.

NOTE: make sure to add the following code in the HTML somewhere after the like/unlike button code.

<script type="text/javascript">
<!--
    FB.Event.subscribe('edge.create', function(href, widget) { _gaq.push(&#91;'_trackSocial', 'Facebook', 'Like', href&#93;); });
    FB.Event.subscribe('edge.remove', function(href, widget) { _gaq.push(&#91;'_trackSocial', 'Facebook', 'Unlike', href&#93;); });
-->
</script>

4 thoughts on “How to track Facebook likes/unlikes in Google Analytics”

    1. I’m not sure what you’re asking for. Are you asking for code for a Facebook like button that will automatically grab the address of the page being viewed? If your blog or website uses a common backend like WordPress, then it is just easiest to use a plugin that does adds the Facebook like button for every page automatically, otherwise you have to go into your theme’s PHP code and start changing things manually (I consider myself an expert at PHP, but I try to avoid changing my WordPress theme code unless I really have to – just not as streamlined as simply enabling or disabling a plugin).

      1. Keep in mind that not everyone uses WordPress (or any CMS) for their site, so perhaps Seeker was looking for some insight on how to dynamically add the proper parameters to the end of the URL?

        1. Yes, I agree. Just that given the vagueness of the question, I wasn’t sure what level of answer the person was looking for – their knowledge base could range from click-to-add plugins to CMS pseudo-code to PHP & SQL.

          Being a fellow web developer, you know how many different ways a solution can be sought.

Leave a Reply

Your email address will not be published. Required fields are marked *