How to Track Social Media Interaction

Jarret Streiner - January 18, 2012

We asked in a previous blog Are Your Website Visitors Socially Engaged? If the answer is yes, then you need to make sure you are correctly setting up your site to track these valuable metrics in Google Analytics. If the answer is no, then you should still know how to set up your site to track social media interaction for when you establish your social media campaigns.

Google Analytics has created three new reports to track social media interaction. The Social Engagement report tracks behavior changes for social media actions i.e. Facebook Like or Google +1. The Social Actions report tracks the number of social media sharing actions from your site. The Social Pages report tracks which pages are being creating the most social media traffic.

Before you implement any of the coding necessary to track social media interaction, you will need to start by adding this code snippet before the </head> tag.

<!– Google Analytics Social Button Tracking –>
<script type=”text/javascript” src=””></script>

Google +1 social engagement interactions are tracked by default in Google Analytics, but to track other valuable metrics such as Facebook, Twitter or LinkedIn you will have to use the _trackSocial method.

Here is a description of the _trackSocial method:

_gaq.push([‘_trackSocial’, network, socialAction, opt_target, opt_pagePath]);

Where the parameters represent:

Required. A string representing the social network being tracked (e.g. Facebook, Twitter, LinkedIn)

Required. A string representing the social action being tracked (e.g. Like, Share, Tweet)

Optional. A string representing the URL (or resource) which receives the action. For example, if a user clicks the Like button on a page, the the opt_target might be set to the title of the page, or an ID used to identify the page in a content management system. In many cases, the page you Like is the same page you are on. So if this parameter is undefined, or omitted, the tracking code defaults to using document.location.href.

Optional. A string representing the page by path (including parameters) from which the action occurred. For example, if you click a Like button on, then opt_pagePath should be set to /apis/analytics/docs/index.html. Almost always, the path of the page is the source of the social action. So if this parameter is undefined or omitted, the tracking code defaults to using location.pathname plus You generally only need to set this if you are tracking virtual pageviews by modifying the optional page path parameter with the Google Analytics _trackPageview method.

Once you have the _trackSocial set up, there are methods used to track Facebook Likes, Facebook Unlikes and Shares.

Facebook LIKES

FB.Event.subscribe(‘edge.create’, function(targetUrl) {
_gaq.push([‘_trackSocial’, ‘facebook’, ‘like’, targetUrl]);

Facebook UNLIKES

FB.Event.subscribe(‘edge.remove’, function(targetUrl) {
_gaq.push([‘_trackSocial’, ‘facebook’, ‘unlike’, targetUrl]);

Facebook SHARES

FB.Event.subscribe(‘message.send’, function(targetUrl) {
_gaq.push([‘_trackSocial’, ‘facebook’, ‘send’, targetUrl]);

View a demo of this in action:

Facebook also has buttons available from the Facebook Developers page found here:

If you use the buttons from Facebook, you will have to add this code to get tracking numbers from Google Analytics:

<script type=”text/javascript”>_ga.trackFacebook();</script>

This is Twitter’s _trackSocial set up.

To add a Twitter button:

<script src=”” type=”text/javascript”></script>
<a href=”

Another option is to use buttons provided by Twitter. Those are accessible at:

To track the Tweet Button you will have to add this code to the Tweet event.‘tweet’, function(event) {
if (event) {
var targetUrl;
if ( && == ‘IFRAME’) {
targetUrl = extractParamFromUri(, ‘url’);
_gaq.push([‘_trackSocial’, ‘twitter’, ‘tweet’, targetUrl]);

To track LinkedIn, you first need to get the code for the LinkedIn Share button from the LinkedIn Site:

Then add this code to your site:

<script src=”” type=”text/javascript”></script>
<script type=”IN/Share” data-counter=”right”></script>

You can set the data-counter to left or right. If you do not want to have a LinkedIn number, you can leave that portion out of the code.

With social media continuing to grow, being used every minute of the day and driving traffic to you site, it is an invaluable metric that should be tracked and reviewed.

Posted in: Analytics

© 2024 MoreVisibility. All rights reserved.