How to Add Social Tracking For Google Analytics In Your Site

For all of you who have implemented the social sharing buttons on your blog/website, don’t you wish that you can track the traffic generated from the clicks of these buttons? You can’t do that in the past, but with the new social tracking feature in Google Analytics, you can do it now. By adding a few lines of code to your existing Google Analytics code, you can quickly get GA to track the number of clicks on your social sharing buttons and the effectiveness of your social media campaign.

At the moment, the social tracking feature in GA only supports Facebook, Twitter and Google +1. The Google +1 tracking is already integrated to GA, so you don’t have to add any extra code. This article will show you how to implement the tracking code for Facebook and Twitter.


Before we start, I have to assume that you are using the newer asynchronous Google Analytics code on your site. It should look something like this:

If not, go to your Google Analytics account, grab the new code and add it to your site.

Adding the tracking script

Download this minify javascript and upload to your server (the original script can be found here).

Add the following code to your header file, just before the </head> tag:

Replace “url-to-script” to the actual URL where you upload the javascript file.

Adding Facebook Like button tracking code

In your web page, locate the section where you display the Facebook Like button code. It should look something like this:

Just below this code, add the following:

The complete code should look like this:

Adding Twitter button tracking code

For Twitter’s Tweet button, we need to add a callback function to activate the tracking. All you have to do is to copy/paste the code to your <head> tag.

Implementing Social Tracking in WordPress

If you are using WordPress, one plugin that you can use to implement the tracking code is Social Media Tracking.

Viewing the Analytics

Log into your Google Analytics account. If you have not switched to the new version, do it now.


Under the “Visitor” section, you should see a “social” link. click the “Engagement” link and you should be able to view your social engagement statistics.


That’s it.

Damien Damien

Damien Oh started writing tech articles since 2007 and has over 10 years of experience in the tech industry. He is proficient in Windows, Linux, Mac, Android and iOS, and worked as a part time WordPress Developer. He is currently the owner and Editor-in-Chief of Make Tech Easier.