How To Track Social Button Clicks On Your Site Using Google Analytics


By December 23rd, 2015





social-button-clicks


Social media is huge right now. And website owners have taken advantage of that by integrating like and share buttons on their websites which helps users share content faster and easier.


As a website owner, you always want to make sure you have tracking and analytics down correctly. If you don’t, how do you know what your users are doing? Without that crucial information, you really don’t know how well your website is performing and how well it can perform.


In the past, most website owners would simply add Google Analytics tracking script to their website and call it a day. But what if you want to track social button clicks and shares as well? Although each social network provides a way to get a count on how many total likes or shares a page has, it is very useful to have that data in an easily accessible way so you can sort through it and make business and website decisions based on that.


In this article, we’ll go over how you can track each individual share or like button clicks with Google Analytics using the Social Interactions feature.


Using A Plugin

The easiest way to accomplish this task if your website is running on WordPress platform is to use a Social Share plugin that already has built-it Google Analytics integration.


One of those plugins is the GetSocial plugin. It has a lot of features and goodies and it works pretty flawlessly. The only bad thing is that it is not free if you want advanced features suck as tracking, so you have to sign up to one of their monthly plans which starts at around $9 per month.


Using Custom Code

This section will require you to be proficient with JavaScript in order to set up each share button to be tracked in Google Analytics.


The following code can be added either in head section of your document or in the footer before the closing </body> tag.


Facebook

For Facebook, we will use the provided methods to bind functions to two Facebook events, like and share. Make sure you add your corect APP ID to the <APPID> part.

window.fbAsyncInit = function() {
FB.init({appId: ‘<APPID>’, status: true, cookie: true, xfbml: true});
FB.Event.subscribe(“edge.create”,function(url) {
if (url.indexOf(“facebook.com”) > 0) {
// if the returned link contains ‘facebook,com’. It is a ‘Like’
// for your Facebook page <br>ga(‘send’, ‘social’, ‘Facebook’, ‘like’, url);
} else {
// else, somebody is sharing the current page on their wall
ga(‘send’, ‘social’, ‘Facebook’, ‘share’, url);
});
};

Twitter

For Twitter, we’re doing a similar thing as Facebook. Simply bind functions to the tweet and follow events from Twitter.

function tweetIntentToAnalytics(intent_event) {
if (intent_event) {
ga(‘send’, ‘social’, ‘Twitter’, ‘tweet’, document.location.href);
}
}
function followIntentToAnalytics(intent_event) {
if (intent_event) {
ga(‘send’, ‘social’, ‘Twitter’, ‘follow’, document.location.href);
}
}
if (typeof twttr !== ‘undefined’) {
twttr.ready(function (twttr) {
twttr.events.bind(‘tweet’, tweetIntentToAnalytics);
twttr.events.bind(‘follow’, followIntentToAnalytics);
});
}

Google Plus

Since this is a Google product, it has an integrated Google Analytics tracking. As long as you are using the latest code for both Google Analytics and Google Plus, you should already see the tracking provided in Google Analytics.


Linkedin

For LinkedIn, their standard method was to use data-success callback feature, however, it’s buggy and doesn’t work as intended so we will have to manually wrap the button with an a href tag in order to attach an onclick method to it.


So first, go to the LinkedIn button generator page and grab the button code. It should look similar to the one below:

<script src=”http://platform.linkedin.com/in.js” type=”text/javascript”> lang: en_US</script>
<script type=”IN/Share” data-counter=”right”></script>

Then, we’ll change the code and add our a href tag wrapper. It should look like this:

<a onClick=”ga(‘send’, ‘social’, ‘LinkedIn’, ‘share’, document.location.href);”>
<script src=”//platform.linkedin.com/in.js” type=”text/javascript”> lang: en_US</script><script type=”IN/Share” data-counter=”right”></script>
</a>

And that should do it. Once you have implemented the button in the location where you want it to be, it should start tracking any LinkedIn share clicks in your Google Analytics account.


Hand-Picked Related Articles:


* Lead image adapted from jmartinezsolera




About the Author:





Haris is the lead of design and development at AdFicient, a full-service search engine marketing (SEM) and business development agency. AdFicient helps clients get more out of their advertising with conversion optimization, search engine optimization, search engine marketing, and web design.

AdFicient


How To Track Social Button Clicks On Your Site Using Google Analytics
The post How To Track Social Button Clicks On Your Site Using Google Analytics appeared first on Search Engine People Blog.

Search Engine People Blog

(17)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.