How to Track Clicks on the Like Button Using Google Analytics

by Joshua Unseth on July 31, 2010


So you’ve probably heard a ton about the Like Button lately. It’s sort of the new thing in marketing. Sites are integrating it in an effort to mitigate the effects of users living on the web in a different way than they used to. Whereas search has, for the past 10 years, driven users to websites, nowadays, users are being driven to new sites through a combination of both search and suggestions from their friends. Rather than them looking for content, content is being suggested to them.

The beauty of it is, if someone Likes a page, that page and perhaps a picture from it are posted to that users wall, propogated to their friends on facebook, and that can be hugely effective in getting new eyes to your site.

So how do you track it? I’m actually surprised that I haven’t seen anyone else using onclick tracking in the facebook like button, which tells me that no one knows you can do it. So to put it simply, if you’ve installed a like button on your facebook and you are using Google Analytics, add a variation of the code in yellow to your button. Below I have outlined two methods for tracking clicks on the like button below.

Virtual Pageview Method

<fb:like onclick="javascript: _gaq.push(['_trackPageview', 'THENAMEOFYOURPAGE/like']);" href="YOURSITESURL.COM"></fb:like>

This will register in GA as a pageview. What’s more, is if you use Google’s URL Builder, you can append some variables to the end to track traffic that results from those likes. That code would look like the following.
<fb:like onclick="javascript: _gaq.push(['_trackPageview', 'THENAMEOFYOURPAGE/like']);" href="YOURSITESURL.COM?utm_source=facebook&utm_medium=social&utm_campaign=like"></fb:like>

Using the URL builder will post a URL to Facebook that allows you to know that people are coming from a click on your Like Button. This means that you can track both the push and the pull of a like button. You will see in your pageviews when people click the element, and you will see the people that come from each of those clicks. From there you could actually estimate the number of visitors your site gets from each click of that button. If you are a site that operates on a CPM, that means, that you can essentially track the value of a Like.

Event Tracking Method

If you don’t want to track a pageview, this method will work to simply help you track the event. This let’s you track the push and pull of users and visitors, and it is probably a more honest way to track interactions on your page. Whereas the virtual pageview method will add a page to those who interact with the like button this will simply add an event that says an user clicked the like button.

It would look something like the following (new code in yellow):
<fb:like onclick="javascript: _gaq.push(['_trackEvent', 'Likes', 'Like', 'TITLE OF YOUR POST']);" href="YOURSITESURL.COM"></fb:like>

And again, if you want to track the Like Button’s magnetic effect using Google’s URL builder, the code would look something like:
<fb:like onclick="javascript: _gaq.push(['_trackEvent', 'Likes', 'Like', 'TITLE OF YOUR POST']);" href="YOURSITESURL.COM?utm_source=facebook&utm_medium=social&utm_campaign=like"></fb:like>


{ 10 comments… read them below or add one }

AROM_1000 August 20, 2010 at 11:14 pm

We tried using the first method on our site but found that when we created a unique URL for each post, the button counter would only show how many times that URL was shared through the button.

For instance, let’s say a post’s URL is http://www.post.com/1234, if 10 people shared it from the button with the URL http://www.post.com/1234?utm_source=facebook&utm_medium=social&utm_campaign=like then the button counter would show “10″. However, if 20 additional people shared the original URL (www.post.com/1234) on top of the 10 button clicks the counter would still only show “10″ likes/shares/tweets. This goes for the RT and Like buttons both.

We simply track clicks now so we receive a higher share/like count :)
Just thought I’d share that.

Joshua Unseth August 21, 2010 at 11:57 am

Interesting. It doesn’t seem to be the case when I’ve tested it. http://www.spidermarket.com/index/dont-discount-nofollowed-links-to-your-site/ shows more than 30 likes, for example.

Reid August 26, 2010 at 8:20 pm

I’m sorry to say, but I never got this working. I was really excited about a quality method of measurement for the Facebook Like button, but it never reported anything to the events tracking in Google Analytics for me. Thanks, though. It’s still encouraging to know that someone got it to work…

Travis Lane September 1, 2010 at 2:03 pm

This basically doesn’t work reliably.
The “onclick” event is not defined in the Facebook FBML code, so many browsers simply won’t fire it.

Second, even if it did work, it would register a “like” on the click, which doesn’t mean they actually logged in and actually completed the “like”.

There are much better solutions, just search for
“how to track facebook likes with google analytics”

Joshua Unseth October 25, 2010 at 9:50 am

@Travis, I would agree with you if it mattered. It fires reliably enough. I don’t actually care about the EXACT number of people who have clicked the like button. I care about tracking the relative number. Which means that presuming it misfires or fires in a way that is consistently inconsistent, the raw numbers are less important.

It is to say, if I am consistently getting 100 Likes every day according to GA, and it drops to 50 likes per day but my traffic stays the same, then something is wrong. It let’s you measure relative customer engagement. Analytics have never been exact and Analytics 101 is that it doesn’t need to be. Trends are what are important.

Asterisk-CGy October 25, 2010 at 2:54 pm

So if I wanted to run my own tracking function I could just replace my own function in the onclick section and it should work too right?

Joshua Unseth November 11, 2010 at 3:10 pm

@Asterisk-CGy Yeah, that should work. I think I’ll add that method to this tutorial. That might even work better. Come back and let me know.

Jorge January 5, 2011 at 7:23 am

Hi guys,

You can track Facebook Like button clicks in Facebook itself by using Insights: http://www.facebook.com/insights/

Login and click the button “Insights for your domain”. This will give you a meta tag to pop into the for your homepage and Facebook does the rest. Very quick and easier than using Analystics and javascript :)

Jim Tim April 14, 2011 at 3:18 pm

@Joshua and @Travis – I could be missing something here, but….

Both good points. Trends are definitely what you’re looking for…. however, given that analytics aren’t exact, why put yourself in a situation where they’re even less exact? I feel that, given the possibility that people who don’t even have a Facebook account could drive up your “like” numbers, it might be better to subscribe to the Facebook event that actually confirms that a “like” took place. Helpful trends will exist, but the number that gets reported will be the number of clicks, not the number of Facebook “likes”. It’s a measure for how many people enjoy your content, but it’s not a measure of how much exposure you’re getting on Facebook. Perhaps a bit misleading… Thoughts?

Joshua Unseth July 3, 2011 at 2:20 am

@Jim Tim, sort of irrelevant now since the Google Analytics API actually can track this. I’ll be posting the method in the next few days.

Leave a Comment

Notify me of followup comments via e-mail. You can also subscribe without commenting.

{ 1 trackback }