How to Track Social Media Interaction

- 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=”http://www.yoursite.com/_js/ga_social_tracking.js”></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:

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

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

opt_target
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.

opt_pagePath
Optional. A string representing the page by path (including parameters) from which the action occurred. For example, if you click a Like button on http://code.google.com/apis/analytics/docs/index.html, 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 location.search. 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:
http://analytics-api-samples.googlecode.com/svn/trunk/src/tracking/javascript/v5/social/facebook_js_async.html

Facebook also has buttons available from the Facebook Developers page found here: http://developers.facebook.com/docs/plugins/

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=”http://platform.twitter.com/widgets.js” type=”text/javascript”></script>
<a href=”http://code.google.com/apis/analytics
data-url=”http://code.google.com/apis/analytics
>Tweet</a>

Another option is to use buttons provided by Twitter. Those are accessible at:
http://twitter.com/about/resources/buttons#tweet

To track the Tweet Button you will have to add this code to the Tweet event.

twttr.events.bind(‘tweet’, function(event) {
if (event) {
var targetUrl;
if (event.target && event.target.nodeName == ‘IFRAME’) {
targetUrl = extractParamFromUri(event.target.src, ‘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:

https://developer.linkedin.com/plugins/share-button

Then add this code to your site:

<script src=”http://platform.linkedin.com/in.js” 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: Google Analytics

Comments are closed at this time.

© 2017 MoreVisibility. All rights reserved