Tracking Your Social Engagement With Google Analytics


We’ve talked about Social Engagement before, but I thought it’d be a good idea to put everything in one spot, to make it easier for the average Joe to set up their web page to track social engagement. First though let’s go over the basics.

Social Engagement Tracking is Awesome

What is Social Engagement

Primarily this is referring to when a visitor to your website likes your page on Facebook, or clicks the Twitter button or Google’s +1, or even a share on LinkedIn. We were originally going to include Pinterest as well in this post, but we’re still having problems working nicely with their API. Hopefully they release something soon that let’s us Analytics nerds have better access.

So when someone, for instance, like’s your page, it will get recorded as that user being socially engaged. You’ll see which users are socially engaged, which pages generated the most engagement, etc.

Google’s documentation regarding social tracking can be found here.


Available Reports on Social Engagement

There are several basic reports available on social engagement by default in Google Analytics located under the Audience section.

Social Engagement in Google Analytics

Audience > Social > Engagement is the primary report where you can compare the number of pages viewed per visit, the average time on site, the bounce rate, and other normal metrics for visits. This can help you determine whether people who used social actions that are available on your site viewed fewer or more pages, than people who did not use social actions.


Audience > Social > Action compares the number of social actions for each social source, and social source-action combination. For example you can compare “Likes” and “sends” from Facebook on your site, or compare the total Facebook interactions, with the total Twitter interactions.


Audience > Social > Pages allows you to compare the number of actions for each page of your site. You will see the information by social source, and social source-action combination. For example you will be able to see which pages prompted the most Facebook actions or the most Facebook likes, or the most Twitter Tweets. On this report Page is where the social action takes place, and Social Entity is the page that was shared.


How to Set Up Social Analytics

You will need to use the _trackSocial action for everything other than Google + buttons. Those are included automatically by Google, however all Facebook and Twitter interactions need to be tracked independently. In his recent Pinterest post, Jim makes a great point about also for the moment tracking things as Events, but we’re going to keep it simple here and just do TrackSocial. Maybe we can do a second follow up post and have an advanced version of the code.


First, be sure to include your Google Analytics Code!

Be sure to have the Asynchronous Tracking Code running on all pages. This code won’t work properly without up-to-date tracking code from Google. Be sure that your tracking code is tracking to the correct account.


Include the ga_social_tracking.js file on all pages

You will need to include a file on every page that is called ga_social_tracking.js and contains the following code. This code does not need to be modified. It can also be found at


Include the Twitter JS-API Async Code in the Head

Twitter requires you to include the following code in the head of your document. This code does not need to be modified.

Here’s the code if you want to ‘cut n paste’

<!– Load Twitter JS-API asynchronously –>
var twitterWidgets = document.createElement(‘script’);
twitterWidgets.type = ‘text/javascript’;
twitterWidgets.async = true;
twitterWidgets.src = ‘’;
// Setup a callback to track once the script loads.
twitterWidgets.onload = _ga.trackTwitter;

Add the LinkedIn Share Button Code to the Head

Add the following code for LinkedIn sharing to the head of your document as well. This code does not need to be modified

Here’s that specific code:

<!– LinkedIn Share Button tracking–>
<script type=”text/javascript”>
function LinkedInShare() {
_gaq.push([‘_trackSocial’, ‘LinkedIn’, ‘Share’]);

Check the scripts in your head. They should be something like this…



/******Asynchronous Google Analytics Tracking Code******/
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-XXXXX-1’]);

(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);

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

<!– Load Twitter JS-API asynchronously –>
var twitterWidgets = document.createElement(‘script’);
twitterWidgets.type = ‘text/javascript’;
twitterWidgets.async = true;
twitterWidgets.src = ‘’;
// Setup a callback to track once the script loads.
twitterWidgets.onload = _ga.trackTwitter;

<!– LinkedIn Share Button tracking–>
<script type=”text/javascript”>
function LinkedInShare() {
_gaq.push([‘_trackSocial’, ‘LinkedIn’, ‘Share’]);


Ok now to the bottom of the page…

Add Facebook code to the Bottom of the Page

This code for Facebook needs to be included somewhere on the page. You can put it anywhere within the <body> however because it is non-async we recommend you put it at the end of the page.

<!–Facebook Scripts–>
<script src=””></script>
<script type=”text/javascript”>_ga.trackFacebook();</script>

Add Twitter code to the Bottom of the Page

Like the Facebook script above, this is non-async code, so should be placed somewhere on the page within the <body> and we recommend placing it at the end of the page.
<!– Twitter Scripts –>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);;js.src=”//”;fjs.parentNode.insertBefore(js,fjs);}}(document,”script”,”twitter-wjs”);</script>

Add Google+ code to the Bottom of the Page

Like the Facebook and Twitter code, Google+ buttons need a little on page help. Add this code to the bottom of the page for Google+ buttons.
<!– Google+ Scripts –>
<script type=”text/javascript”>
(function() {
var po = document.createElement(‘script’); po.type = ‘text/javascript’; po.async = true;
po.src = ‘’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(po, s);

Add LinkedIn code to the Bottom of the Page

And  this code must be included once per page within the body, but preferably near the end of the page as it is non-async.

<!– LinkedIn Scripts–>
<script src=”” type=”text/javascript”></script>

Review the Bottom Code

Your code at the bottom of the page should look like this…

<!– Facebook Scripts –>
<div id=”fb-root”></div><script src=”″></script>
<script type=”text/javascript”>_ga.trackFacebook();</script>

<!– Twitter Scripts–>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);;js.src=”//”;fjs.parentNode.insertBefore(js,fjs);}}(document,”script”,”twitter-wjs”);</script>

<!– Google+ Scripts –>
<script type=”text/javascript”>
(function() {
var po = document.createElement(‘script’); po.type = ‘text/javascript’; po.async = true;
po.src = ‘’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(po, s);

<!– Linked In Scripts –>
<script src=”” type=”text/javascript”></script>



Ok it’s time to add the actual buttons. Here you have a bit more leeway because the scripts you’ve set up should now enable the social tracking on all four buttons.


Adding Facebook Buttons

With the above code installed, adding a Facebook like button is as simple as including a line of code similar to the one here where you wish the Like button to be located. Be sure to change the href value to the appropriate domain and page. If it is placed on a Blog page, it should have the URL for that page placed within the code on each page, otherwise the ‘like’ will be for the blog as a whole, rather than a specific page.

<fb:like href=”” send=”true” width=”450″ show_faces=”false” font=””></fb:like>

The attributes can also be found on this page:

You can modify the code with various attributes that are described on that page under Step 1. For instance in the line above I have “send” being true which adds the send button next to the like button. I also have show_faces as false. If true it would display profile photos beneath the URL. Width lets you control the width on the page that the button will take, it can go smaller, or wider for instance. All the attributes are on the link above, and should be reviewed.


Adding Twitter Buttons

Twitter buttons are similar to Facebook, in that you simply add the following code or something similar where you wish the Tweet button to be located.

<a href=”” data–count=”horizontal” data–url=”” data via=”yourtwittername” data–text=”Your custom message” class=”twitter–share–button”>Tweet</a>

This code also needs to be modified. The data-url should be for the page you are referring to, the URL and the page itself.  I recommend using this Twitter page to create a button:

When there you can choose which button to use, and add the button options. This might create something like this…

<a href=”” class=”twitter-share-button” data-via=”YourTwitterUsername ” data-hashtags=”SocialMedia”>Tweet</a>

<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);;js.src=”//”;fjs.parentNode.insertBefore(js,fjs);}}(document,”script”,”twitter-wjs”);</script>

With that code, simply delete the <script> section and only use the bolded a link area inline where you wish the button to be located. The script itself that you’re deleting here you added to the bottom of every page in step 6.


Adding Google+ Buttons

Google+ is automatically tracked by Google Analytics, but you still need a button. I recommend using the Google page that helps you add the button to your website:

The standard tag is:


And the most minimal tag is

<g:plusone annotation=”none”></g:plusone>

When you choose your options, simply copy the tag code such as above, and ignore the <script> render call, which you’ve already included on every page in step 7.


Adding LinkedIn Buttons

LinkedIn needs a little bit of help. Like the other buttons above it’s best to use the LinkedIn code itself located at to generate your button. The generated script on the page will look something like this:

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

Be sure to only include the second line listed, as you have included the first line in the bottom of your page in step 8. There are other options, so it’s best to use the URL to be shared in the link itself, generated by your page.

<script type=”IN/Share” data-url=”” data-counter=”right”  data-onsuccess=”LinkedInShare”></script>

Also add the line data-onsuccess=”LinkedInShare” which will activate the function included in the head to track a LinkedIn share as a social engagement.


Variations – Box Count

You like the box counts like in the first image above?

<h2>Vertical Count Buttons</h2>
<!– Vertical Count Buttons –>
<div style=”position:relative;width:270px;height:70px;margin:auto;”>
<!– Facebook Vertical Count Button –>
<div style=”position:absolute;top:0px;left:0x;”>
<div class=”fb-like” data-href=”” data-send=”false” data-layout=”box_count” data-width=”450″ data-show-faces=”true”></div>
<!– LinkedIn Vertical Count Button –>
<div style=”position:absolute;top:0px;left:60px;”>
<script src=”//” type=”text/javascript”></script>
<script type=”IN/Share” data-url=” data-counter=”top” data-onsuccess=”LinkedInShare”></script>
<!– Twitter Vertical Count Button –>
<div style=”position:absolute;top:0px;left:140px;”>
<a href=”” data-count=”vertical” data-url=” data-related=”Related Twitter Handle Like The Company” data-text=”Insert Twitter Default Message Here” data-via=”Your Twitter Handle” class=”twitter-share-button”>Tweet</a>
<!– Google+ Vertical Count Button –>
<div style=”position:absolute;top:0px;left:220px;”>
<g:plusone size=”tall” href=””></g:plusone>

Boom. There you go.

Variations – Horizontal Count

You like the lower kind, under the picture of the awesome puppy?

<h2>Horizontal Count Buttons</h2>
<!– Horizontal Count Buttons –>
<div style=”position:relative;width:370px;height:20px;margin:auto;”>
<!– Facebook Horizontal Count Button –>
<div style=”position:absolute;top:0px;”><div class=”fb-like” data-href=”” data-send=”false” data-layout=”button_count” data-width=”70″ data-show-faces=”true”></div></div>
<!– LinkedIn Horizontal Count Button –>
<div style=”position:absolute;top:0px;left:90px;”><script type=”IN/Share” data-url=”” data-counter=”right”></script></div>
<!– Twitter Horizontal Count Button –>
<div style=”position:absolute;top:0px;left:200px;”><a href=”” class=”twitter-share-button” data-url=”” data-via=”YourTwitterName” data-hashtags=”social”>Tweet</a></div>
<!– Google+ Horizontal Count Button –>
<div style=”position:absolute;top:0px;left:310px;”><g:plusone size=”medium” href=””></g:plusone></div>

Shazam. You’re welcome.

Don’t forget to add the correct domains, twitter handles, descriptions etc.


With the code above in place, you can place Facebook, Twitter, Google+, and LinkedIn buttons across any of your sites where the code is included, and all sharing on those buttons will be included as Social Engagements in your Google Analytics tracking data. There are admittedly a few steps, but it’s mostly easy cut and pasting, and before long, you should not only be helping your users share your pages with their friends and colleagues, but you’ll be able to track when they do so.

Got any questions about implementing social engagement tracking? Write us below and we’ll get back to you uncomfortably fast with the answers.

Sayf is a former LunaMetrician and contributor to our blog.

  • Tanith

    An easy option for share buttons is ShareThis. They’re automatically integrated into Google Analytics, so all you have to do is install.

    The downside is that you have to trade your shortener for their custom one, which affects counts if you or one of your sharers use another program that auto-converts links to like BufferApp.

  • Sayf Sharif

    ShareThis, also I think AddThis integrates with trackSocial now as well. Particularly if you don’t mind the default look of the plugins (or the limited options they give you) and are working within a WordPress website, they’re a great and easy way to get the tracking going.

    My problems with the plugins though aren’t just that you have to trade your shortener for theirs, but also simply in their appearance. I’ve had numerous customization problems with AddThis in particular, and ShareThis less so. If you want to do something unique on your site they can be a problem and not work the way you want either. If you have some sort of design template that for instance puts the featured image from WordPress into the top of the post, you can break the sharing plugin that gets put at the top of the page, and there really is no way to make it look JUST the way you want.

    So when you need to customize and be very specific about where you want your shares, how you want them to look, how you want them to interact, the plugins can often fail people. I was surprised just how often people use those plugins and are happy with them in all but their appearance… But they settled.

  • Ahura

    I’ve just discovered the new SEO too-it?s Colibri and it?s awesome-it can track my website position on every Google,it also find my competition or even suggest it, monitors Facebook, Twitter mentions and backlinks to my website.
    Most functional-highly recommend!

  • cesc

    Any ideas to speed up a page so heavy??

  • Does this work with DiggDigg?

  • Sayf Sharif

    I haven’t looked at DiggDigg specifically. These plugins are hit and miss for whether they do track social or not. If you’re using it, the best way to know is to look at your social engagement within GA and see whether you’re seeing engagement that mirrors the clicks on your site.

  • SGK

    I wanted to know if using Social engagemnet report can we track how many people liked FB page through the website. Example on my website, there are two LIKE buttons, one for the post and other main LIKE for the page which indicates number of FB fans. is it possible to track the MAin LIKE?
    can I track how many people liked my page through the website using this LIKE

  • Sayf Sharif

    SGK, yes that’s on the Social -> Pages report. In GA go to Audience -> Social -> Pages and you’ll see a table of “Social Entity” along with various types of social actions (tweets, likes, etc) and there you can see which pages (the social entity) were liked. So yes the main like would refer to your home page, so look for your home page URL in the social entity itself.

  • Hi, any idea how long it should take for social actions to start appearing in Google Analytics? I’ve implemented your code described above and can confirm that the buttons are working, however I’m yet to see any data appear inside GA. Also, is there any way to get historical social actions data? Cheers!

  • kate

    Audience > Social > Action compares the number of social actions for each social source, and social source-action combination. For example you can compare “Likes” and “sends” from Facebook on your site..

    This means it will tell number of people who clicked Likes and Sends buttons on my website, right?????


  • Sayf Sharif

    Blair, they should start showing up as soon as you’ve installed the code. Depending on how many visits your site gets it could take a few minutes or even several hours or more for those numbers to show up, but if you’re seeing the actual visits being recorded, but they’re not listed as socially engaged, then something isn’t working correctly.

  • Sayf Sharif

    Kate, yes if you use this code (specifically for facebook the ga_social_tracking.js code) then a visitor who clicks like or send on a page on your site will be registered. This doesn’t however register people liking your actual Facebook page itself of course, only the ones who click on the links on your actual website.

  • Matt


    Great post, really clear and simple instructions. Question: why doesn’t Google recommend using ga_social_tracking.js on their social tracking documentation page?

  • Sayf Sharif

    Matt, Google’s documentation is occasionally unreliable, out of date, and can contradict other documentation they’ve provided.

  • Matthew Challis


    Is there any way of tracking the individuals that have shared something or liked it on Facebook. For example, if you said ‘free shipping if you share this with friends’. Is there a way of tracking the people that did it?

  • pete

    this is great and all, but it doesn’t track these social engagements leading to a SALE, etc.. i’m wondering if thats possible with GAnalytics? Or better to use CoreMetrics?

  • Great post – the Chrome GA debugger extension actually works really well if you want to see if you’re sending the data without having to wait.

  • Cool – it works :))

    Question though Sharif – I’m seeing two types of action appear in my analytics for Twitter:

    1. twitter : click-tweet


    2. twitter : tweet

    Can anyone please help me to understand the difference? From what I can see, the tweet counter button has only incremented by one while running this code, so it seems that two actions have been recorded.

    Any ideas?

  • Just answered my own question by reading this post from Twitter:

    In essence, the script which powers this functionality enables differentiation between ‘intent to tweet’ (click the tweet button), and actually publishing the tweet.

    There are a number of other outcomes which can be tracked with this method so it’s worth a read.

  • sir
    plz tell me how much time it will take after entering these code to generate social plugin reports in google analytics?

  • Sayf Sharif

    I guess I stopped getting notifications for comments on this post as there are a few from april that are new to me!


    If you have a specific share button for the purpose of what you’re talking about, you could set it up with either trackSocial or an event tracker to be a specific type of social share, and then see who shares that. However once it’s shared, you wouldn’t be able to necessarily track those who clicked the shared link… UNLESS you specifically shared a link with a set parameter. You can specify to Facebook what link to share, so rather than sharing you would share and then you not only could track how many users shared that link, but whenever a user clicked it and entered via that link you could sniff for that parameter and set a custom variable on the site for that user as having come from that share, or simply look for it on your landing page reports.

  • Sayf Sharif

    Pete, per the above comment it doesn’t necessarily help you with that level of engagement unless you actively work to share links with parameters you set that you can track. Don’t just share a link on facebook, share it with a parameter attached that your site sniffs for, that way you can see precisely which shares in which mediums work, rather than a general referral.

  • Sayf Sharif

    Pavlicko, I also am fond of Firebug to look at the actual cookies to see the parameters set in the utm.gif

  • Sayf Sharif

    Blair, you’re correct you answered your own question. It’s the difference between intent and actually doing it. Not every social site has that callback functionality to the site to let you know that the user ACTUALLY tweeted or shared, but when it’s there it can be usefull, though honestly I’ve never used that aspect of it.

  • Sayf Sharif

    Vision, If you’ve installed the code correctly, and a share occurs you should see it in your code when your data appears, which could be anywhere from minutes to hours to days depending on your site. If you know the share has been clicked the previous day, and you see all your other data but no social engagement, then the code is probably installed incorrectly.

  • sir
    In ga_social_tracking.js file anything change is in place of opt_target we provide url of page…or just copied this code and nothing to edit??

  • Does anyone have a good link for adding Pinterest to this tutorial?

  • Sayf Sharif

    The ga social tracking js file should be used as is, you shouldn’t need to modify it at all. Just get that file and include it on your page.

  • Sayf Sharif

    Blair, funny you should mention Pinterest. We were initially going to include it in this, but we couldn’t perfect the tracking for it. Pinterest hasn’t released an API like the rest so we had a very kludgey version of the tracking for that, but we couldn’t get it to 100% and it took up over half the time of this blog post, so we abandoned it. We had hoped to see an API from Pinterest by this point, but alas still nothing. Maybe we’ll revisit that older code as an add in for this.

  • Peter Edstrom

    I’m getting social actions in GA, but I can only see them via a custom report, or in a dashboard widget. The Audience > Social menu item is MIA. Any ideas why?

  • Sayf Sharif

    Peter, They’ve moved the social menus from under Audience to under Traffic Source. Check there.

  • Hi,

    can I load the bottom scripts, that ones I fetch from fb and twitter) also asynchronusly?

  • Sayf Sharif

    Lars, yes there is a way to do that, i recommend looking at some posts on regarding loading them in async. There are different schools of thought though, because there are also issues with loading them that way because the subscribe buttons on the pages by default also load synchronously. So if your’e going to go async you need to make sure those buttons are also loaded async AFTER the main script loads, or you’ll kick up errors.

  • Hi,

    okay. I will use getScript() and the callback function…

  • Salik

    Hi there,

    Interesting post, thanks for sharing this. I implemented the same on my blog. Below are few issues which I am facing:

    1) Data under social->plugins->social actions doesnt matches with actual number of likes/tweets and LinkedIn shares.
    2) I have added a new custom report for this and at times, social actions are there in this report but at the same time they are not available under social->social actions tab.
    3) Whats the different between tweet and click tweet action.
    If you can answer above queries, it will be a great help for me.

  • Sayf Sharif


    1) The number in GA is just what gets clicked through the social buttons. if people tweet or like it in other ways that won’t get recorded. Also it depends on communication between services, so sometimes not all the clicks will get recorded.

    2) not sure on this, might depend on how you put together your custom report.

    3) Click tweet is when someone clicks the tweet button on your site, but tweet is if they ACTUALLY tweeted. So you’ll see people clicking tweet, but not actually tweeting.

  • Hi – looks like Audience > Social > Engagement has disappeared in GA. Wonder why?

  • Sayf Sharif

    Since the writing of this post, Social was moved under Traffic Sources. You can find it now under Traffic Sources > Social > Plugins

  • I’m having issues getting the plugins to display inside GA. I’ve gone through and added everything step by step – up until the buttons section. I’m using Shareaholic, so my buttons are displayed on each of my pages. I’m not quite sure what I’m doing wrong here…any thoughts?

    Also – I’m using a php based theme. First section is in the Head – second section is in the footer. Thanks for your help in advance.

  • Sayf Sharif

    Sorry DeWayne. Could be many things. Follow the current instructions on each site, rather than on this page and try and get one working at a time. Make sure all the necessary files are actually loading by looking at your browser web console. Best I can suggest.

  • Can yo post a sample report? Curious if you have tried adding tracking on your facebook page. I saw some links that allow you to do this. Can you find out where the users came from before they liked the FB page?

  • Sayf Sharif

    I don’t think we have used that exact method, but you won’t be able to see where they came from before they liked the page I don’t beleive.

  • Clare

    Hi Sayf,

    Great informative article, thank you. I am about to implement for an online quiz. So users take the quiz and then have option to share it on FB and Twitter. I am curious, will GA track the actual share, or just the fact that they have clicked the share on FB button?
    thanks in advance

  • Sayf Sharif

    If you set things up correctly it will track both the click and the share itself.

Contact Us.

Follow Us



We'll get back to you
in ONE business day.
Our Locations
THE FOUNDRY [map] LunaMetrics

24 S. 18th Street
Suite 100

Pittsburgh, PA 15203


4115 N. Ravenswood
Suite 101
Chicago, IL 60613


2100 Manchester Rd.
Building C, Suite 1750
Wheaton, IL 60187