Google Analytics Social Tracking – Twitter, Facebook, Google Plus and LinkedIn

In this post you will learn to track Google +1, Facebook likes, Facebook sends, Facebook unlikes, Twitter tweets, Twitter follows and LinkedIn shares in Google Analytics.

But before we move forward, you need to understand the difference between event tracking & social tracking and the difference between normal users’ interactions & social interactions:

1. Event tracking is implemented by calling the _trackEvent() method whereas social tracking is implemented by calling the _trackSocial() method.

2. Event reports are available under the ‘Behavior’ menu and Social reports are available under the ‘Acquisition’ menu in your Google Analytics account.

The ‘_TrackSocial()’ method

To send social interaction data to Google Analytics we call the _trackSocial() method wherever we have added the share button/social plugin:

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

Here,

network => Name of the social network being tracked e.g. Facebook, Twitter, LinkedIn etc.

This parameter is required to be passed to the trackSocial method.

socialAction => Type of the social action being tracked e.g. Like, Unlike, Send, Tweet etc.

This parameter is required to be passed to the method.

opt_target => This parameter is optional.

It is a URL which receives the social action.

_trackSocial seems to track only those social sharings which were done through social plugin/share button on your website. It doesn’t seem to track re-tweets or sharing done on some third-party site or third-party plugins like Tweetmeme.

So if your blog post is tweeted 10 times via a share button on your website and then later re-tweeted 65 times then also _trackSocial counts only 10 tweets.

In short, I don’t see social interactions being tracked across the web. This is not what I was expecting from Google.

Attribution Modelling in Google Analytics and Beyond
Attribution Modelling in Google Ads and Facebook

Get my best selling books on Attribution Modelling

  • Learn to implement attribution modelling in your organisation
  • Understand the customer purchase journey across devices
  • Determine the most effective marketing channels for investment

 Click book covers to find out more

Tracking Google +1 social interactions

Step-1: Make sure you are using the latest Google Analytics Asynchronous Tracking Code on your website.

Step-2: Copy the Google +1 button code from here and paste it wherever you want to display the button on your website. Google Analytics automatically tracks the social interactions associated with Google +1s once you have installed the Google +1 button on your website.  So you don’t need to place any special tracking code for Google +1 button.

Step-3:  After few days/weeks, go to ‘Plugins’ report (under Traffic Sources > Social) in your Google Analytics account. Then click on the primary dimension ‘Social Source and Action’. You will see the following report (provided your tracking is set up correctly):

linkedin-share

Get weekly practical tips on GA4 and/or BigQuery to accurately track and read your analytics data.

 


My step-by-step blueprint for selecting the best Excel charts for data analysis and reporting (40 pages)

Get the FREE e-book on Best Excel Charts For Data Analysis And Reporting (40 Pages)

Download the FREE ebook

 

Tracking Facebook social interactions

For Facebook, social actions can be: ‘like’,’unlike’, ‘follow’, ‘send’,’comment’ etc.

  • Through ‘like’ button a user can share your web page on his Facebook profile with just one click.
  • Through ‘send’ button a user can send (share) your web page to his friends.
  • Through ‘comment’ button a user can comment on any web page of your website.

Step-1: Make sure you are using the latest Google Analytics Asynchronous Tracking Code on your website.

Step-2: Upload ‘ga_social_tracking.js‘ file to your web server. You can grab this file from here.

Step-3: Enable Social Tracking by adding the following code after your Google Analytics Tracking Code and before the </head> tag:

<!-- Enabling Google Analytics Social Tracking code Starts Here -->
<script type="text/javascript" src="https://www.your-domain.com/wp-content/uploads/ga_social_tracking.js"></script>
<!-- Enabling Google Analytics Social Tracking code Ends Here -->

The final code will look like the following:

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxx-x']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'https://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<!-- Enabling Google Analytics Social Tracking code Starts Here -->
<script type="text/javascript" src="https://www.your-domain.com/wp-content/uploads/ga_social_tracking.js"></script>
<!-- Enabling Google Analytics Social Tracking code Ends Here -->
</head>

Don’t copy past this code without modification.

Replace “UA-xxxxxx-x” with your Google Analytics account number and ‘www.your-domain.com’ with your website address where you have installed the ‘ga_social_tracking.js’ file.

Step-4: Install the Facebook ‘like’ button from here. The ‘Like’ button code will look something like this:

<fb:like send="true" show_faces="false" layout="button_count" width="150"></fb:like>


Step-5
: Add following line of code just before before the <fb:like /> tag:

<script src="https://connect.facebook.net/en_US/all.js#xfbml=1&appId=501839739845103"></script><script type="text/javascript">_ga.trackFacebook();</script>

So the final code will look like this:

<script src="https://connect.facebook.net/en_US/all.js#xfbml=1&appId=501839739845103"></script><script type="text/javascript">_ga.trackFacebook();</script><fb:like send="false" layout="button_count" width="150" show_faces="false"></fb:like>

Don’t copy-paste this code without modifying it first.

Here The “#appId=xxxxxxxxxxx” is a random app ID that Facebook generates which allows you to access Insights for the button.

Don’t use my appID. When you create your own Facebook ‘like’ button, Facebook will generate an appId for you. Use that appID.

Note: The appId is not a requirement for the ‘like’ button to work.

Step-6: Copy-paste the modified Facebook ‘like’ button code wherever you want to display the Like button.

Step-7: After a few days/weeks, go to ‘Plugins’ report (under Traffic Sources > Social) in your Google Analytics account. Then click on the primary dimension ‘Social Source and Action’. You will see the following report (provided your tracking is set up correctly):

facebook-like

If you want to track all the social actions provided by Facebook then you need to install all the social plugins of Facebook. Get the list of plugins.

Note: you can track only those social actions for which you have installed social plugins on your website. For e.g. if you want to track Facebook comments, then you first need to install Facebook comments plugin on your website.

If you are using Universal Analytics on your website, then checkout this article to track Facebook social interaction: Tracking Facebook Social Interactions with Google Analytics and Google Tag Manager

Tracking Twitter social interactions

For Twitter, social actions can be: ‘tweet’, ‘click’, ‘follow’ etc.

Step-1: Make sure you are using the latest Google Analytics Asynchronous Tracking Code on your website.

Step-2: Make sure that the file  ‘ga_social_tracking.js‘ is uploaded on your web server.

Step-3: Make sure you have enabled the Social Tracking as explained above.

Step-4: Install the official twitter button on your website. The ‘twitter’ button code will look something like this:

<!-- Twitter button code starts here -->
<a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="seohimanshu">Tweet</a><script type="text/javascript" src="https://platform.twitter.com/widgets.js"></script>
<!-- Twitter button code ends here -->

Don’t copy-past this code without modification. Use your own Twitter handle.

Step-5: Copy paste the following code just before the </head> tag:

<!-- Load Twitter JS-API asynchronously -->
<script>
(function(){
var twitterWidgets = document.createElement('script');
twitterWidgets.type = 'text/javascript';
twitterWidgets.async = true;
twitterWidgets.src = 'https://platform.twitter.com/widgets.js';
// Setup a callback to track once the script loads.
twitterWidgets.onload = _ga.trackTwitter;
document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
})();
</script>


Step-6:
After a few days/weeks, go to ‘Plugins’ report (under Traffic Sources > Social) in your Google Analytics account. Then click on the primary dimension ‘Social Source and Action’. You will see the following report (provided your tracking is set up correctly):

twitter-interactions

Note: You can’t track Twitter social actions through the Tweetmeme button or other Twitter type buttons.

If you are using Universal Analytics on your website, then checkout this article to track Twitter social interaction: Tracking Twitter and Linkedin Social Interactions in Google Analytics

Tracking LinkedIn social interactions

Step-1: Make sure you are using the latest Google Analytics Asynchronous Tracking Code on your website.

Step-2: Make sure that the file  ‘ga_social_tracking.js’ is uploaded on your web server. 

Step-3: Make sure you have enabled the Social Tracking as explained above.

Step-4: Add the following code after your Social Tracking Code and before the </head> tag:

<!-- LinkedIn Share Button tracking code starts here-->
<script type="text/javascript">
function LinkedInShare() {
_gaq.push(['_trackSocial', 'LinkedIn', 'Share']);
}
<!-- LinkedIn Share Button tracking code ends here-->

The final code will look like the following:

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxx-x']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'https://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<!-- Enabling Google Analytics Social Tracking code Starts Here -->
<script type="text/javascript" src="https://www.your-domain.com/wp-content/uploads/ga_social_tracking.js"></script>
<!-- Enabling Google Analytics Social Tracking code Ends Here -->
<!-- LinkedIn Share Button tracking code starts here-->
<script type="text/javascript">
function LinkedInShare() {
_gaq.push(['_trackSocial', 'LinkedIn', 'Share']);
}
<!-- LinkedIn Share Button tracking code ends here-->
</head>

Don’t copy-past this code without modification.

Replace “UA-xxxxxx-x” with your Google Analytics account number and ‘www.your-domain.com’ with your website address where you have installed the ‘ga_social_tracking.js’ file.


Step-4:
 Install the official LinkedIn share button on your web page(s). The button code will look like this:

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


Step-5:
 Modify the LinkedIn button code by adding: data-onsuccess="LinkedInShare" like this:

<!-- Linkedin button & tracking code starts here -->
<script src="https://platform.linkedin.com/in.js" type="text/javascript"></script>
<script type="IN/Share" data-counter="right" data-onsuccess="LinkedInShare"></script>
<!-- Linkedin button & tracking code ends here -->


Step-6:
  Copy-paste the modified button code wherever you want to display the LinkedIn button.


Step-7:
After a few days/weeks, go to ‘Plugins’ report (under Traffic Sources > Social) in your Google Analytics account. Then click on the primary dimension ‘Social Source and Action’. You will see the following report (provided your tracking is set up correctly):

linkedin-share

If you are using Universal Analytics on your website, then checkout this article to track LinkedIn social interaction: Tracking Twitter and Linkedin Social Interactions in Google Analytics

  1. Understanding Facebook Referral traffic in Google Analytics
  2. Learn to correctly track Facebook Referral traffic in Google Analytics
  3. Tracking Facebook ‘Likes’ and ‘Unlikes’ in Google Analytics
  4. Why Facebook and Google Analytics data do not match
  5. Complete Guide to Google Analytics for Facebook
  1. How to see Organic Search Keywords in GA4 (Google Analytics 4)
  2. Google Analytics Ecommerce Tracking Tutorial
  3. Google Tag Manager Event Tracking Tutorial
  4. Google Analytics Event Tracking Tutorial
  5. Google Analytics Store Visits Tracking Tutorial
  6. Offline Conversion Tracking in Google Analytics – Tutorial
  7. Ecommerce Tracking Google Tag Manager (GTM) – Tutorial
  8. Tracking Virtual Pageviews in Google Tag Manager – Tutorial
  9. Google Tag Manager YouTube Video Tracking
  10. Google Analytics Virtual Pageviews Tutorial
  11. Google Analytics YouTube Integration & Analysis Tutorial
  12. Google Analytics for Facebook Tutorial
  13. Cross Domain Tracking in Google Analytics – Complete Guide
  14. How to use two Google Analytics codes on one page
  15. How to correctly use referral exclusion list in Google Analytics
  16. Google Analytics Calculated Metrics – Tutorial
  17. Creating your own Google Analytics Tag Auditing System
  18. Google Tag Manager Search Tracking without Query Parameter
  19. Tracking Google Analytics Paypal Referral and other payment gateways
  20. How to Track Phone Calls in Google Analytics 4 – Call Tracking Tutorial
  21. How to track leads in Google Analytics via CRM
  22. Postbacks in Google Analytics Explained
  23. Subscription & Recurring Revenue Analytics in Google Analytics
  24. Track the Impact of Google Analytics Cookie Consent on Website Traffic
  25. Tracking Offline Conversions in Google Ads
  26. Implementing Scroll Tracking via Google Tag Manager
  27. Scroll Depth Tracking in Google Tag Manager – Tutorial
  28. Site Search Tracking In Google Analytics Without Query Parameters
  29. Google Tag Manager Youtube Video Tracking via YouTube Video Trigger
  30. How to Correctly Measure Conversion Date & Time in Google Analytics
  31. Google Analytics Social Tracking – Twitter, Facebook, Google Plus and LinkedIn
  32. Cross Domain Tracking in Google Analytics – Complete Guide
  33. Google Analytics Linkedin & Twitter Tracking
  34. Creating Content Group in Google Analytics via tracking code using gtag.js
  35. Google Analytics Site Search Tracking via Query Parameters
  36. Google Analytics Site Search Tracking Tutorial
  37. Creating and Using Site Search Funnel in Google Analytics
  38. How to add Facebook Pixel to Google Tag Manager
  39. AMP Google Analytics Tracking – Learn to track AMP pages
  40. Setting up Sales Funnel across websites in Google Analytics
  41. Google Analytics 4 Regex (Regular Expressions) Tutorial

My best selling books on Digital Analytics and Conversion Optimization

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and BeyondSECOND EDITION OUT NOW!
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.

About the Author

Himanshu Sharma

  • Founder, OptimizeSmart.com
  • Over 15 years of experience in digital analytics and marketing
  • Author of four best-selling books on digital analytics and conversion optimization
  • Nominated for Digital Analytics Association Awards for Excellence
  • Runs one of the most popular blogs in the world on digital analytics
  • Consultant to countless small and big businesses over the decade