Tracking Facebook Likes, Share, Send & Comments as Social Engagement in Google Analytics
- 07.08.2011
- Eivind Savio
There are already posted "tons of articles out there" about how to track Facebook Likes, Send & Comments as Social Engagement in Google Analytics, but since I also uses my own blog as a reminder of how to do things and a "script bank", I decided to write this blog post nevertheless.
To be able to track Facebook Likes, Share, Send & Comments on your web site, you have to use the XFBML version (Javascript SDK).
Below I have listed what that this article covers, and what you should do (or consider doing):
- Change your <html> opening tag
- Implement Facebook Meta Tags (Facebook AppID & AdminID)
- Register your web site as a Facebook App
- Implement Open Graph Protocol (Meta Tags)
- Use Facebook XFBML version (Javascript SDK) and load the script asynchronous
- Implement the Google Analytics Social Media Tracking Script
- Implement my script for tracking Traffic from Facebook Likes, Send & Comments in Google Analytics (and read that article as well)
Facebook and Open Graph Meta Tags
I recommend that you implement both Facebook and Open Graph Meta Tags. Open Graph Tags will give you better control of how your shared content will appear on Facebook and Google+ (Google+ is also using the Open Graph Meta Tags).
It's recommended that you change your <html> opening tag when implementing these meta-tags. Your new <html> tag should look something like the code below.
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://ogp.me/ns#" >
Facebook AppID and AdminID Meta Tag
To administer your page, you need to associate it with either your Facebook account or your Facebook Platform application. It is valid to associate your page with both user accounts and a Facebook Platform Application.
To associate the page with your Facebook account, add the additional property fb:admins to your page with a comma-separated list of the user IDs or usernames of the Facebook accounts who own the page.
Register your web site as a Facebook App, and implement the meta-tags below.
- <meta property="fb:app_id" content="130796876963854" />
- <meta property="fb:admins" content="12345678" />
Replace values in red with your values.
Open Graph Protocol (Meta Tags)
The Open Graph Protocol gives you better control of how your content are presented on Facebook and Google+.
Since Google+ also uses this data, I recommend that the size of your og:image (Object Type) has a width of minimum 150 pixels and not 50 pixels (as recommended by Facebook) .
What kind of og:type (Object Types) you should use can always be discussed. In the example code above I'm using "article" as Object Type, which is recommended for a blog post like this. However, if you use a different Object Type, Facebook Insight will show you deeper information about "Likes" for that particular page, and you can post follow up messages on Facebook to those who have liked the page.
See also Open Graph protocol information on Facebook.
Facebook XFBML version (Javascript SDK)
- <div id="fb-root"></div>
- <script type="text/javascript">
- window.fbAsyncInit = function() {
- FB.init({appId: 'YourAppID',
- status: true,
- cookie: true,
- xfbml: true,
- channelUrl : 'http://www.yourdomain.com/facebook/include/channel.html' // add channelURL to avoid IE redirect problems
- }); };
- (function() {
- var e = document.createElement('script'); e.async = true;
- e.src = document.location.protocol +
- '//connect.facebook.net/en_US/all.js';
- document.getElementById('fb-root').appendChild(e);
- }());
- </script>
Replace values in red with your values. The best place to put this code is right before the closing </body> tag according to Facebook.
See also Javascript SDK information on Facebook.
Facebook channelURL
The contents of the channel.html file should be this single line.
- <script src="http://connect.facebook.net/en_US/all.js" ></script>
See also FB.init information on Facebook.
Google Analytics Social Media Tracking Script for Facebook
Now that all the basic Facebook stuff is implemented, it is time to implement the script that will track Likes, Share, Send & Comments as Social Media in Google Analytics.
Replace values in red with your values. I also recommend that you don't implement this script as inline javascript, but instead save the script into a javascript file and point to that file to improve page speed.
Place this code below all your other Facebook scripts (before </body>).
The script above is inspired from Google Analytics and from Yoast. In addition I have also added tracking of Facebook Comments.
Yoast's version tracks interaction with Facebook Like & Send buttons (this will be tracked as "Share" or "Send"), and with the Facebook Like Box (this will be tracked as "Like").
Now that all the basic code and tracking scripts are in place, it's time to implement buttons, boxes or comment fields on your site.
Facebook Share & Send Button
See also Like Button info on Facebook and my article about How to Track Traffic from Facebook Likes, Send or Comments in Google Analytics.
Facebook Like Box
- <fb:like-box href="http://www.facebook.com/Savio.no" width="265" show_faces="true" stream="true" border_color="#ccc" header="false" ref="facebook_fb-page"></fb:like-box>
See also Like Box info on Facebook.
Facebook Comment Box
- <fb:comments width="500" num_posts="2" href="http://domain.com/canonical-url-to-article"></fb:comments>
Just so I have mentioned it, if you comment on your own site, your comments will not be tracked in Google Analytics.
See also information on Facebook about the Comment Box.
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 Facebook Likes, Share, Send & Comments as Social Engagement in Google Analytics.
Related articles
Du kan følge kommentarer til denne posten med RSS. Du må ha javascript aktivert for å kunne kommentere. Tilbaketråkk er deaktivert.
- Meir
- 10.08.2011 16:28:31
Tried to implement it in our Facebook applications, but all I see is "Not Socially Engaged" line in "Social Type" view. What could be the problem? Thanks
- Eivind Savio
- 10.08.2011 17:30:16
Without seeing/checking the implementation is difficult to say. Can you share the URL to the web site where this is implemented?
Eivind
- Meir
- 12.08.2011 18:38:07
Thanks for posting and help!
I am looking on a screenshot at the top of this article and I wish I found it long ago....
We develop native FB applications (Magento based) - this is the app I implemented your solution:
http://apps.facebook.com/rosoling/?___store=en_us
Meir
- Eivind Savio
- 12.08.2011 20:27:51
Unfortunately one line of my code were missing in my article:
if (FB && FB.Event && FB.Event.subscribe) {I have updated the script in this article, and hopefully it's correct now (if not my script is "live" here: http://www.savio.no/includes/script/social-media-sharing/SoMe.js)
With that said, I also see that some of your Google Analytics script are placed in the wrong order:
- _trackPageview must come after _setDomainName
- Script for Tracking traffic from Facebook Like & Send as Campaign traffic must come before _trackPageview
Eivind
- Meir
- 13.08.2011 11:43:01
I think there is another mistype in your code - line 37 is unnecessary (you have no instruction to close anymore)
-Meir
- Eivind Savio
- 13.08.2011 13:24:50
Fixed and tested that the code work.
Thanks for your feedback.
Eivind
- Ann
- 11.08.2011 23:58:47
Thank you for posting this you have made my life much easier.
-Ann
- Baptiste
- 22.08.2011 16:22:45
Looking at your source, I see that in your SoMe.js file you also use a bit of code which seems to be used to track Twitter events.
Since I'm very interested BUT very new to GA and Twitter APIs, would you explain, or at least, comment the snippet you use ?
Hope you'll find time to do this, I'm rather sure it would help a lot of people :)
Cheers,
Baptiste
- Eivind Savio
- 22.08.2011 17:53:10
The Twitter script I'm using comes from Yoast:
http://yoast.com/social-buttons/
The only difference between my script and his, is that he wrote that article before Social Interaction became a separate report type in Google Analytics. Because of this that article is tracking Social Interactions using Event Tracking (_trackEvent), while my SoMe.js file is using _trackSocial.
- Eivind -
- Simon
- 22.08.2011 19:46:35
I implemented your code but it seems not to interact well with GA.
Maybe I wanted to do too much and also added your code from this article : http://www.savio.no/blogg/a/107/how-to-track-traffic-from-facebook-likes-send-or-comments-in-google-analytics
Maybe they are some conflicts between the 2 scripts, as a results I have re-integrated the basic GA script to see if it will track well again.
Maybe you could tell me if there are some conflicts? or if the code you first wrote is obsolete with the social tracking implementation.
Thanks for your help, these articles are great by the way :)
Simon
- Eivind Savio
- 22.08.2011 21:24:26
Those 2 scripts runs fine together, I run them both myself.
Is it the site you are linking to you have problem with?
With re-integrated the basic GA script, are you talking about app.tabpress.com? I see you are running their Facebook Tracking script.
- Jo_c
- 21.10.2011 00:46:35
I tried your code above and it works for everything else except the like box.
I find that the edge.create only works with the like button but not with the like box.
Have you also encountered the same issue?
Thanks.
- Eivind Savio
- 22.10.2011 11:45:59
I haven't experienced that issue. Works fine for meg.
- Dasago
- 11.11.2011 01:59:57
Do you know if Facebook interactions that are located within an iframe can be tracked?
Thank you!
- Eivind Savio
- 13.11.2011 12:47:21
As long as you can implement code/script into the iFrame, interactions can be tracked.
- koffyn
- 16.01.2012 09:17:35
Check please my test page http://pravdaodurove.com/rini_fblike2.html
I did what you said with FB LikeBox, but still in my GA Reports all visitors are Not Socially Engaged, even if they've pushed the Like button :(
- Eivind Savio
- 26.01.2012 18:21:08
You must provide a real AppID in your script.
FB.init({appId: 'YourAppID', status: true, cookie: true, xfbml: true});Eivind
XClick to move the comment field
