Tracking Facebook ‘Likes’ and ‘Unlikes’ in Google Analytics

This article is in conjunction with the article ‘Guide to Social Interactions Tracking in Google Analytics‘ where I introduced the concept of social interactions tracking in Google Analytics and explained in great detail, what social interactions are and what are the requirements, for such type of tracking set up.

In this article, I will explain tracking Facebook Social Interactions (only Facebook ‘like’ and ‘unlike’ events) in order to keep the article short.

Once you understand how to track ‘like’ and ‘unlike’, you can then easily track other Facebook events like: ‘send’, ‘comment added’ and ‘comment removed’.

Following is the process for tracking Facebook ‘likes’ and ‘unlikes’ in Google Analytics, in a nutshell:

code sequence

Step-1: Install Facebook JavaScript SDK on your website.

Step-2: Add Facebook Social Interactions tracking code on your website. Place this code right below the Facebook Social Interactions tracking code.

Once you have implemented Facebook SDK and social interacting codes and tracked few Facebook social interactions (like Facebook ‘like’), you can then see the data in your GA view by navigating to: Acquisition > Social > Plugins report and then clicking on ‘Social Network and Action’ tab:

facebook like unlike

Get the App ID before Installing Facebook JavaScript SDK

You can also track Facebook social interactions in Google Analytics without using Facebook App ID.

However I would strongly suggest to get Facebook App ID first, because it has many advantages beyond social interactions tracking.

Through Facebook App ID, Facebook can identify your website, which can later be used for adding open graph protocol data, Facebook authentication, Facebook app analytics etc.

In order to get the Facebook App ID, you first need to create a new Facebook App for your website.

Get the E-book (52 Pages)

Get the E-Book (37 Pages)

Create a new Facebook APP for your website

We are going to create a new Facebook app just to get the app ID, which will later be used in installing Facebook JavaScript SDK on your website and to install various Facebook plugins (like the Facebook ‘like’ button).

Follow the steps below to create a new Facebook APP:

Step-1: Login to your Facebook account.

Step-2: Go to https://developers.facebook.com/apps  and then click on ‘+ Add a New App‘ button:

add a new app button

You will now see a dialog box like the one below:

add a new app for website

Since we are creating Facebook app for website, click on the ‘WWW‘ website icon.

Step-3: Type the name of your new APP and then click on ‘create new Facebook App ID’.

create new facebook app id
Step-4
: Enter your contact email, select ‘Business‘ from the ‘category‘ drop down menu and then click on ‘Create App Id’ button.

create new app id

Note: You need to enter your contact email, so that later you can make your Facebook APP available to the General Public.

You will now see the code for setting up ‘Facebook SDK for JavaScript’:

facebook APP ID

You don’t need to add this code to your website at this time, in order to install Facebook JavaScript SDK. Just pay close attention to the code and look for the unique Facebook APP ID and the special method called window.fbAsyncInit. Note down your Facebook App ID.

The window.fbAsyncInit method is very important because it calls the FB.init() method.

The method FB.init() is used to initialize and setup the Facebook JavaScript SDK. This is the method which enables Facebook API for you.

Step-5: Scroll down the page, enter the URL of your website (in the ‘site URL’ text box) and then click on the ‘next’ button:

about your website

Step-6: Click on the ‘Skip to Developer Dashboard’ link as shown below:

skip to developer dashboard

Step-7: Click on the ‘App Review’ link, found in the left hand navigation menu and then switch the toggle button to ‘Yes’:

make app public

Now your Facebook APP is available to the general public.

Link your Facebook App with your existing Facebook Fan Page (Optional)

Note: This is a bonus section. It has nothing to do with tracking Facebook events in Google Analytics. I have added this section to this article because I find it very useful and worth sharing.

Following are the advantages of linking your Facebook App with your existing Facebook Fan Page:

#1 Your Facebook Fan Page will turn into a powerful Facebook App Page, which can not only enhance your users’ experience on Facebook but also give you the ability to use Facebook Analytics for apps in addition to Facebook Insight:

facebook analytics app

#2 When a user likes an article on your website, it will show up on the user’s timeline activity, which can then be seen by user’s friends. In this way your article can get additional exposure on Facebook.

To link your Facebook App with your existing Facebook Fan Page follow the steps below:

Step-1: Go to your Facebook Fan page, click on the ‘About‘ link.

Step-2: Under the ‘Page Info‘ section, change the category to ‘Brands and Products‘ and sub-category to ‘App Page‘ as shown below:

fan page category

Step-3: Go to https://developers.facebook.com/apps and then click on your app.

Step-4: Click on ‘App Details‘ link as shown below:app details

Step-5: Scroll down to ‘Contact Info’ section, click on the ‘Select an existing page‘ drop down menu:

select an existing page

Step-6: select your Facebook fan page and then click on the ‘save changes’ button:

select facebook app page

Install Facebook JavaScript SDK on your website

One you have got your Facebook App ID, you now need to install Facebook JavaScript SDK on your website, in order to track Facebook events in Google Analytics. Follow the steps below:

Step-1:  Go to https://developers.facebook.com/docs/plugins/like-button, enter your Facebook Fan Page URL in the ‘URL to Like’ text box and then click on the ‘Get Code’ button:

facebook like button code

Once you have clicked on the ‘Get Code’ button, you will then see the Facebook Javascript SDK code (which contains your Facebook APP ID) along with Facebook Like and Share button code, as shown below:

select facebook app id
Step-2
: Copy-paste the Facebook JavaScript SDK code, right after the opening <body> tag on each page of your website.

Step-3: Copy-paste the plugin code (Facebook ‘like’ button code), wherever you want the plugin to appear on your website.

Note: You can track only those Facebook actions for which you have installed the right Facebook plugin on your website. For e.g. if you want to track Facebook ‘send’ event then you first need to install Facebook ‘send’ button on your website.

If you want to track Facebook ‘comment’ then you first need to install Facebook ‘comment’ plugin on your website. In order to learn more about social interactions tracking in general, read this article: Guide to Social Interactions Tracking in Google Analytics

Add Facebook App ID to your Facebook SDK code

If the Facebook SDK code is already installed on your website, then you need to find it and add your APP ID to it.

In following cases, the Facebook JavaScript SDK is already installed on your website:

  1. If you are already using a Facebook Plugin (like Facebook Like button) on your website.
  2. If you are using a SEO plugin which let you add Facebook open graph protocol meta data to your website. As soon as you enable the open graph meta data setting, via your plugin, Facebook SDK is automatically installed on your website.

But even if the Facebook SDK is already installed on your website, you should still add your App ID to it.

Since I use the ‘wordpress SEO by Yoast‘ plugin on my website, all I have to do to add the App ID to my Facebook JavaScript SDK code,  navigate to: WordPress Admin panel > SEO > Social > Facebook and enter my Facebook APP ID: 

facebook app id wordpress

Note (1): Even if you use Google Tag Manager, you still need to copy-paste the Facebook JavaScript SDK code right after the opening <body> tag on each page of your website. This is because Facebook JavaScript SDK code can’t be deployed via GTM.

Note (2): You need to add Facebook JavaScript SDK code only once on your website.

Note (3): You can also track Facebook social interactions in Google Analytics without creating a new Facebook App and without using Facebook App ID. I have used Facebook App ID because it has many advantages, as explained before.

Note (4): You don’t need to add the Facebook JavaScript SDK code every time you install a new Facebook plugin on your website. Though Facebook will ask you to do so.

Introduction to Facebook Social Interactions Tracking

Before you can track Facebook likes and Unlikes in Google Analytics, you first need to capture them. You can capture these events by using a method called FB.Event.subscribe(). This method is used to subscribe to a Facebook event (like liking a page) and to define callback function:

Syntax: FB.Event.subscribe(event, callback)

Here event is the name of event type. It can be:

#1 edge.create – this Facebook event is fired when someone likes the page using Facebook like button

#2 edge.remove – this Facebook event is fired when someone unlikes the page using Facebook like button

#3 message.send – this Facebook event is fired when someone use the Facebook ‘send’ button.

#4 comment.create – this Facebook event is fired when someone posts a comment using Facebook Comments Plugin

#5 comment.remove – this Facebook event is fired when someone deletes a comment in the Facebook Comments Plugin

callBack is the callback function which is triggered when a Facebook event is fired.

Through callback function, you can send Facebook events to Google Analytics via the ‘send’ command or push Facebook events into GTM data layer.

Following is an example of how you can use the callback function to send Facebook ‘like’ event to Google Analytics via the ‘send’ command:

FB.Event.subscribe(‘edge.create’, function(targetURL){

 ga(‘send’, ‘social’, ‘Facebook’, ‘like’, targetUrl);

});

Similarly, you can use the callback function to send Facebook ‘unlike’ event to Google Analytics via the ‘send’ command:

FB.Event.subscribe(‘edge.remove’, function(targetURL){

 ga(‘send’, ‘social’, ‘Facebook’, ‘unlike’, targetUrl);

});

Add Facebook Social Interactions tracking code on our website.

At this stage, we now have the new Facebook App ID and we have the Facebook JavaScript SDK and Facebook Social Plugins installed on our website. All we have to do now, is to add the Facebook Social Interactions tracking code on our website. Copy paste the following code right after your Facebook JavaScript SDK code on each page of your website:

<!-- Facebook Social Interaction Tracking -->
<script>
 window.fbAsyncInit = function(){
  FB.Event.subscribe('edge.create',function(targetURL) {
       ga('send', 'social', 'Facebook', 'like', targetURL);   

      }
  );

   FB.Event.subscribe('edge.remove',function(URL) {
       ga('send', 'social', 'Facebook', 'unlike', URL);   

      }
  ); 

  FB.Event.subscribe('message.send',function(location) {
       ga('send', 'social', 'Facebook', 'send', location);   

      }
  );  

   FB.Event.subscribe('comment.create',function(href) {
       ga('send', 'social', 'Facebook', 'comment added', href);   

      }
  ); 

   FB.Event.subscribe('comment.remove',function(loc) {
       ga('send', 'social', 'Facebook', 'comment deleted', loc);   

      }
  );  

};
</script>
<!-- Facebook Social Interaction Tracking -->

Remember the sequence in which, the various tracking codes will be added to your website:

code sequence

Following is a visual summary of tracking Facebook social interactions tracking in Google Analytics:

tracking facebook likes without gtm

Related Articles

 

Do you know the difference between Digital Analytics and Google Analytics?


99.99% of course creators themselves don’t know the difference between Digital analytics, Google Analytics (GA) and Google Tag Manager (GTM).

So they are teaching GA and GTM in the name of teaching Digital analytics.

They just copy each other. Monkey see, monkey do.

But Digital analytics is not about GA, GTM.

It is about analyzing and interpreting data, setting up goals, strategies and KPIs.

It’s about creating strategic roadmap for your business.


Digital Analytics is the core skill. Google Analytics is just a tool used to implement ‘Digital Analytics’.

You can also implement ‘Digital analytics’ via other tools like ‘adobe analytics’, ‘kissmetrics’ etc.

Using Google Analytics without the good understanding of ‘Digital analytics’ is like driving around in a car, in a big city without understanding the traffic rules and road signs.

You are either likely to end up somewhere other than your destination or you get involved in an accident.


You learn data analysis and interpretation from Digital analytics and not from Google Analytics.

The direction in which your analysis will move, will determine the direction in which your marketing campaigns and eventually your company will move to get the highest possible return on investment.

You get that direction from ‘Digital analytics’ and not from ‘Google Analytics’.


You learn to set up KPIs, strategies and measurement framework for your business from ‘Digital analytics’ and not from ‘Google Analytics’.

So if you are taking a course only on 'Google Analytics’, you are learning to use one of the tools of ‘Digital analytics’. You are not learning the ‘Digital analytics’ itself.

Since any person can learn to use Google Analytics in couple of weeks, you do no get any competitive advantage in the marketplace just by knowing GA.

You need to know lot more than GA in order to work in digital analytics and marketing field.


So what I have done, if you are interested, is I have put together a completely free training that will teach you exactly how I have been able to leverage digital analytics to generate floods of news sales and customers and how you can literally copy what I have done to get similar results.

Here what You'll Learn On This FREE Web Class!


1) The number 1 reason why most marketers and business owners are not able to scale their advertising and maximise sales.

2) Why you won’t get any competitive advantage in the marketplace just by knowing Google Analytics.

3) The number 1 reason why conversion optimization is not working for your business.

4) How to advertise on any marketing platform for FREE with an unlimited budget.

5) How to learn and master digital analytics in record time.

 
 

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

Himanshu Sharma

Digital Marketing Consultant and Founder of Optimizesmart.com

Himanshu helps business owners and marketing professionals in generating more sales and ROI by fixing their website tracking issues, helping them understand their true customers purchase journey and helping them determine the most effective marketing channels for investment.

He has over 12 years experience in digital analytics and digital marketing.

He was nominated for the Digital Analytics Association's Awards for Excellence.

The Digital Analytics Association is a world renowned not-for-profit association which helps organisations overcome the challenges of data acquisition and application.

He is the author of four best-selling books on analytics and conversion optimization:

error: Alert: Content is protected !!