How to Track Traffic from Facebook Likes, Send or Comments in Google Analytics

Facebook Like

OK, so you have implemented Facebook Like, Send or Comments on your website, and you see from your referral data in Google Analytics that you are getting traffic from Facebook. But are that traffic caused by Like Buttons or Comments? Referral data will not show you this.

In this blog post I explain how you can get better insight into your Facebook traffic by tracking traffic from Facebook Likes, Send or Comments as campaign traffic – and of course, how to do it.

The road to better insight

Unfortunately there isn’t a easy road to what I consider to be the best solutionfor tracking Facebook Like, Send or Comments (I have tried several approaches). Here are what you will have to do:

  1. (Probably) change your Facebook Like & Send script
  2. Change your Google Analytics script
  3. Add filters to Google Analytics
  4. Exclude Facebook Parameters from your Google Analytics reports
  5. Beware of SEO implications that Facebook Parameters may cause

Facebook Like & Send

To the Facebook Like & Send script we will add something called the “ref attribute“. The purpose of the ref attribute is originally to be able to help you test different placements and types of Like buttons. Append the ref=”” attribute to the Like button, and make sure that the value you choose is less than 50 characters (a-z, A-Z, 0-9, + / = – . : _).

The ref attribute is going to be our Google Analytics Campaign Name. Since we also are going to use the ref attribute in our Google Analytics Filters, part of theref attribute must contain something that makes us able to identify the value as “Facebook”. Se example below:

When somebody “Like” or “Send” your article, the parameter fb_ref is automatically added to the URL. This makes us able to identify this as either Facebook Like or Send traffic as the example URL below shows.

  • http://www.domain.com/url-to-article?fb_ref=facebook_your-campaign-name

Where on Facebook did the Link Get Clicked?

When you use the ref parameter, Facebook will also (but not always) add afb_source parameter to the referrer URL, which includes the stream type (‘home’, ‘profile’, ‘search’, ‘other’) where the click occurred and the story type (‘oneline’, ‘multiline’) concatenated with an underscore.

The fb_source parameter will be tracked as Campaign Ad Content in Google Analytics.

Facebook Comments

You don’t have to change anything in your Facebook Comments code. Example code below:

When a user comments and posts to Facebook a fb_comment_id parameter will automatically be added to the URL like this:

  • http://domain.com/url-to-article?fb_comment_id=commentidparameter123

The fb_comment_id parameter will be tracked as Campaign Ad Content in Google Analytics.

The Google Analytics script

To be able to track traffic from Facebook Like, Send or Comments as campaign traffic you will have to add Google Analytics Campaign Tracking Code to your Google Analytics script. In the example script below the Campaign Tracking Code is bolded.

Since the script below is handling both Like/Send and Comments, I have added a simple javascript checking for either the fb_ref or the fb_comment_id parameter in the URL. You can also do this server-side as I do on this site. Just change the script part in orange.

Google Analytics Filters for Facebook Likes, Send & Comments

Without filtering the data in Google Analytics, our Campaign Name, Source and Medium reports will look like rubbish.

Facebook Like, Send & Comments Campaign Medium Filter

Field A -> Extract A Campaign Medium ^facebook_|^fbc_
Field B -> Extract B
Output To -> Constructor Campaign Medium social-media
Field A Required Yes
Field B Required No
Override Output Field Yes
Case Sensitive No

Facebook Like, Send & Comments Campaign Source Filter

Field A -> Extract A Campaign Source ^facebook_|^fbc_
Field B -> Extract B
Output To -> Constructor Campaign Source facebook.com
Field A Required Yes
Field B Required No
Override Output Field Yes
Case Sensitive No

Facebook Comments Campaign Name Filter

Field A -> Extract A Campaign Name ^fbc_
Field B -> Extract B
Output To -> Constructor Campaign Name facebook-comment
Field A Required Yes
Field B Required No
Override Output Field Yes
Case Sensitive No

Done! Now traffic from Facebook Like, Send or Comments will be tracked as campaigns in Google Analytics and will give you better understanding of your Facebook traffic.

Google Analytics Report Explanation

As mentioned in the beginning of this blog post the parameter fb_ref will automatically be added to the URL on Facebook.

Unfortunately not all traffic caused by a “Like” will have that parameter. The exception is when somebody “Like” an article, and then somebody on Facebook reshare that article. From my experience the posted URL on Facebook will then loose the fb_ref parameter, and traffic from the “Liked” URL will from now on be tracked as referral traffic in Google Analytics.

With other words, this solution isn’t perfect, but I found it to be the best method.

Facebook Campaign Name Report in Google Analytics

Below you find an example of how the Campaign Name Report may look like.

Facebook Campaign Name Report in Google Analytics

In the example above you will see that I have differentiated between “Likes” in left column or below article (I have 2 sets of Like buttons on my sites for the moment). Perhaps not the best campaign names, but I know this traffic is caused by either Facebook Likes, Send or Comments.

Facebook Campaign Ad Content Report in Google Analytics

Below you find an example of how the Campaign Ad Content Report may look like.

Facebook Campaign Ad Content Report in Google Analytics

In the beginning of this blog post I shortly explained that the fb_source parameter can be added to your URLs. If your traffic comes from a Facebook Like button, thefb_source parameter will be added.

If your traffic comes from a Facebook Send button, the fb_source parameter ismessage, but I have also experienced that it can be missing. The report above shows some traffic reported as (not set). That is in this case traffic from the Send button.

The Ad Content Report containing the fbc_xxxx value is traffic from Facebook Comments, and the value is the Comment ID.

Cleaning up your data

The parameters from Facebook will create duplicate content in your page content reports in Google Analytics. I recommend you exclude those parameters.

Cleaning up your data

Some final recommendations

Implementing Facebook scripts on your website aren’t necessary so easy as it may look like. Facebook scripts may slow down your site, cause problems for Internet Explorer, and finally, cause problems for search engines like Google (and with this, cause SEO problems).

These are my recommendations when you implement Facebook scripts on your website:

  1. Use the HTML5 solution.
  2. Load your Facebook XFBML scripts Asynchronously.
  3. Implement Open Graph protocol
  4. Use Facebook Channel URL to reduce problems with Internet Explorer.
  5. Implement Google Analytics Social Interaction Analytics
  6. Implement Canonical tag or exclude Facebook parameters in Webmaster Central to avoid SEO problems.

If you see anything that could be improved or errors (I’m not a programmer), or if you just found this article valuable, feel free to comment, Like, Tweet or G+.

Happy tracking Traffic from Facebook Likes, Send or Comments.

2 Comments on "How to Track Traffic from Facebook Likes, Send or Comments in Google Analytics"

  1. Has anyone implemented this? Is still valid with facebook?
    Im very interested in tracking which one of my pages generates more new likes to my facebook page.

    Can I create 2 buttons that look the same on each page, but track them separately and view how many each bring in google analytics?

    Thanks in advance to any response

    • The Google Analytics script in this blog post is “Classic Analytics” (not the latest version of Google Analytics). This means that the example is not valid because of that, but since the fb-ref parameter is still valid (https://developers.facebook.com/docs/plugins/faqs#ref) it should be possible to rewrite the script to work with the latest version of GA (I would however now have done this using Google Tag Manager).

      Regarding your last question if you can create 2 buttons and track them separately, yes you can.

Leave a comment

Your email address will not be published.


*