Google Analytics for Facebook Fan Pages

We launched our Facebook fan page earlier this month and as with all Facebook pages only Facebook Insights program is available to page administrators. Facebook Insights shows demographic details and interactions on your pages BUT limited to show information of fans only. It is far less sophisticated and comprehensive when compared to the free Google Analytics. One of the limitations of Facebook Fan pages is that you can only run limited Javascript on it and Google Analytics needs Javascript code included to correctly track visitors. We have successfully managed to get ALL functions of Google Analytics working on our Facebook fan page (including visitor statistics, traffic sources, visitor country, keyword searches with all other powerful reporting & maps overlays etc).

Google Analytics Example

How to setup Google Analytics on your Facebook fan pages

The workaround we use in our code is to include Google Analytics as an image instead of setting the standard Javascript. This method tracks every visitor to the custom facebook pages on Google Analytics. It required a combination of server side cookie management and an additional <img> tag to the bottom of the facebook fan page. Here are the steps to get Google Analytics working on your facebook fan page.

1) Setup Google Analytics account. If you already have one, create a new website profile. You can name it facebook.com or facebook.com/your_page_name. You will finally get your tracking code which looks like this UA-3123123-2
2) Create your custom img tag for each of your pages you like to track. EG: contact form, services, products etc. You can use our tool to create the Google Analytics link generator for Facebook pages.
3) Add the entire custom image html tag from step 2 to the bottom of each Facebook fan page that you need to track.

That is all there is to it! Google Analytics is not real-time, so you will need to give it some time. Approximately a day before you see the fruits of your “hard” work.

For advanced users

Use this method, if you don’t want to use our hosted link redirection as mentioned in the method above. You can download the entire source code which is just about three files to get this setup working on your own server (running PHP4.3 or above). The code is written in PHP and essentially creates the Google image tracking URL with the referrer, page information, ID, etc. The additional advantage of hosting this on your own server and domain is that visits from your website to your facebook fan page gets tracked, etc. You will also be able to customise further if you wish. Please do share any useful updates you apply to the tracking link code.

Facebook – Google Analytics Tracker v1.1 (Updated 21st Feb, 2010).  For advanced method – Download this code to use on your server.

If you don’t have a Facebook fan page yet, visit our tutorial for code and help on creating customised Facebook fan pages.

PS: We could not find any other source / blog that described how to get Google Analytics on Facebook fan pages! There is support for canvas pages and applications but nothing for StaticFBML fan pages. Hope this helps and please leave your comments below.

UPDATE:
1) A lot of users have asked how to track visits to the wall. Yes, this can be done. Please see the comments by iphp below.
2) Here is a screenshot to a staticFBML where the code should be placed
3) We have managed to set up funnels, goals and segments to separate fan and non fan activity.
4) Video: Here is a link to the Webdigi youtube channel check our favourites to get step by step walkthrough!
5) This blog and comments cover all aspects of setting up Google Analytics. If you still want help, we are available to offer paid support and installation of Analytics for your page. Please contact us here.

Also read...

Comments

  1. Stijn said on :

    Thanks a lot but it doesn’t bring back an data in Google analytics. I reconfigured, let’s hope it works in a couple of hours.

    In the meantime, I tried to add this in a text widget on my wordpress.com blog. Any idea if this could work?

  2. Anupama said on :

    Just checked that you’ve added an update for tracking wall visits -This is Super-Awesome!!!!!!!

  3. Custom Applications said on :

    This is awesome. Now there’s no need to invest with those companies that sell social media analytics. Thanks!

  4. Alexis said on :

    Hello,

    Thank you for this awesome explanation. I think I got the first steps right (getting the code, then installing staticFBML application, then adding it/ customizing it for the page) – however, I didnt get exactly where and how many times I should CC the codes generated by your appli.

    For example, let’s say I would like to track the wall and the discography page.
    I then created TWO “FBML” boxes: one named “Discography”, where I CC’d the code generated for the discography page, and one “Wall” where I did the same.

    Am I right? Because so far, GA warns me that the code is unknown…

    Thanks in advance, and I hope I was clear enough!

  5. Anna said on :

    Two weeks ago I added this to a Facebook page and everything seemed to be working fine, but after a week I was surprised to see that the number of Absolute Unique Visitors was still 100%. Now after two weeks the number of visits are 19 517 and the number of absolute unique visitors are 19 515. Any idea what I did wrong? I used the solution for advanced users. This is the page: facebook.com/kondomeriet

    Thanks for a great post, and for your patience answering all the comments, you’re great 🙂

  6. iphp said on :

    @ Anna, I don’t think your self hosted method is correctly keeping track of cookies. Can you please check if cookies are working from your server and it is maintaining this? The hosted solution shows a non 100% for new visits.

    @Vytautas, Can you please turn on error reporting? I see you are using the advanced self hosting method. The code is not redirecting correctly.

    @Anupama, Francesc, Good work!

    @Alexis, you have to generate a new code for each page that you are looking to track

  7. Alexis said on :

    Hi,

    @iphp – thanks for your answer, but by “page” do you mean “Fan page” (which includes several sub-pages, such as wall, discography, infos, etc.) or each sub-page of a fan page? That’s where it gets confusing.

    Thanks!
    A.

  8. iphp said on :

    @Alexis, by page I mean every tab/staticFBML within your fan page. The contact form should have a different code to the one from the wall and the discography a different one from portfolio, etc.

  9. Loois said on :

    Hello Webdigi,

    First, big thanks to you guys for sharing and supporting this great tracking technique!

    I’ve installed codes on every tabs and wall (except discussion and notes tabs but there’s no traffic on these pages), using your server. I’m getting data my page is facebook.com/weloveshortfilms.

    Thank you very much for your help.

  10. JT said on :

    Can this work on normal profile pages, i.e. not fan pages, but my individual page? I cannot seem to get StaticFBML installed on it?

  11. Lithyem said on :

    This is a great find, thank you!

  12. KiH said on :

    We recently released a tool that tracks your web visitors mouse movements. There’s a lot of insight in that sort of information. It’s free, see: picnet com.au/met There’s a few other cool features like heatmaps etc, but never thought about making it work on Facebook. Might be really useful to track how your visitors are viewing your Facebook page considering that 85% of places that your eyes visit your mouse also visits. Check in with MET over the next few months to see if we release a facebook solution. Thanks for your post.

  13. Karpacz Noclegi said on :

    Oh I didn;t know about it, thx for all information 🙂

  14. Jean-Louis said on :

    Hello Webdigi and thanks a lot for your amazing solution !

    Everything seems to work fine except that I get only new visits (100%) and very high bounce rates.. I’m using your server > could you help me to understand what’s wrong? My fanpage is facebook.com/weloveshortfilms

    Thank you

  15. Jean-Louis said on :

    And traffic sources are not identified properly (ex: visits from Adwords seem to be identified as facebook referral > is it something related to an automatic redirect ?

    Thank you

  16. janelle said on :

    Hi, thanks for sharing this!
    I managed to input the codes for the wall page, but what about the tabs? Currently each tab is quite fixed, and there’s nowhere to add them…. Does this mean I’ll have to convert them all the StaticFBML pages, so that I can add them in?

    Thanks,
    Elle

  17. A Week In The Life of A Redhead said on :

    We have the same WordPress theme! I am trying to figure out a way to track facebook in Google, and I stumbled on to you – Catherine

  18. Daniel said on :

    Is it possible to track user activity on non-FBML tabs such as the Info or Wall tab?

    Perhaps there is a workaround?

    Thanks, great work!

  19. iphp said on :

    @Jean, how many pages are you tracking?

    @Daniel, yes you can track the wall tab by using staticFBML and changing application settings to add box and removing tab.

  20. Zyelon said on :

    Thanks a lot for really nice information sharing…

  21. Markus said on :

    Thanx, awesome post! Works nice…

    Just wondering: I tried to track how many users left the page via external links in my staticFBML code, so I used <a href=”http://www.example.com” rel=”nofollow”> in combination with your code… Thought this should be working but it does not. Any ideas on this?

    Cheers, Markus

  22. Markus said on :

    Ouch! Your blog swallowed half of my posted code – this is what I used to track links to external sites:

    a href=”http://www.example,com” onClick=”javascript: pageTracker._trackPageview (‘/external/example_com’);”

    Cheers,
    Markus

  23. Jean-Louis said on :

    Hello iphp

    I’m tracking 4 pages :
    – the wall/info via “brussels short film festival” box in left column
    – “concept” tab (= landing page)
    – “festival” tab
    – “selection” tab
    (-even “notes” tab but it seems not to work)

    Thank you very much for your help

  24. faiz said on :

    Can someone tell me that GA on my page is working? facebook.com/universityofmalaya .Thanks in advance.

  25. Jules said on :

    Hello I’m a beginner so am not too savvy with all this. So I’m following the top 3 steps… Once I get to step 3, HOW to do I put the code on my Facebook page? I don’t see anywhere to edit??? Thank you so much, this is such a brilliant idea!

  26. Marion said on :

    @iphp, I use Google Chrome and the form kept giving me problems while trying to create the image links. Every time I clicked on a field, it kept putting focus on the `Analytics Code` field.

    I re-wrote some of the HTML to fix this problem, and I also switched out the JavaScript to use jQuery (directly from Google). If you’re interested you can download the form code from here:

    figmentthinking.com/ft_downloads/fbgat-jquery-index.zip

    I did not repackage the full code, only the index.php that I modified.

  27. John said on :

    You mention that you’re able to see traffic sources and keyword searches using this approach. I’m not clear from the code where that’s coming from. I understand how it would be possible to track things like AdWords PPC but are you able to track Google Organic (source/keywords) and Facebook search keywords? Thanks

  28. Tom said on :

    @iphp, I agree with @Marion, I use Safari and the focus would not stay on a field in the form without clicking-holding whilst I typed in the data. Otherwise it would jump straight back to the ‘Analytics Code’ field.

    Great piece of work overall though, got analytics working like a dream – thanks!

  29. Pepe said on :

    Hi, amazing technique!

  30. Shalaco said on :

    This article has a lot of the FBML steps that was skipped, if you are a beginner, here is some tutorials on the subject: facebookmarketingreview.com/tutorials/advanced-facebook-page-customization-fbml

  31. ollie said on :

    anyone able to help me? I posted april 7 with my enquiry.

  32. Roacha said on :

    Hey @iphp, first great job. Two quick questions:
    1) I setup my wall with a page link of /wall. I have some unique FB apps like Web Appz, when I hit the WebAppz tab the url ends in “v=app_19827163485” so do I create my new box with a page link of “app_19827163485”?

    2) After I add additional FBML boxes and custom GA links they all show up under the Boxes tab. Don’t I need to move these to each of the unique tabs/pages that I want monitored? The only option is to move to the wall or delete, how do I get them to the proper tab/page?

  33. Roacha said on :

    Also can you check out my configuration on my wall. facebook.com/DudeImGettingMarried

    Thanks

  34. id1 said on :

    hi, the code integrates fine in my FBML, but it shows that there is a broken or missing image at the bottom of the page. How do I get rid of that, to keep my design clean?

    The doesn’t actually go to a transparent gif or anything.. should it?

  35. Pingback: WASP Blog» Blog Archive » Google Analytic, Facebook and WASP

  36. Cynaera said on :

    I am still having a problem getting this to work. I’ve tried multiple methods, creating the FBML box and pasting it, and also pasting the code on the “bottom” of my page. But that is was i am not understanding, can you please be more specific on what the “bottom of my page” is? Greatly appreciated.

    Thanks for your help…
    Cynaera

  37. Gus said on :

    We have developed a couple of Facebook application that we are trying to track their usage with GA. We are using iframe based apps. and have added the GA tracking code to our ‘iframe” pages. The problem with GA and IE is that GA does not track all of the IE hits! Browser distribution by GA is : Firefox, Chrome, safari, IE. We have verified GA is greatly under-reporting hits by IE.
    I have read some complains about GA an IE issues but no solutions. Does anybody have experience with GA in a Facebook Iframe application deployment?

    Thank you,
    Gus

  38. Bart De Latte said on :

    Thx for this really usefull information in a world of social media!

  39. Sean Weigold Ferguson said on :

    Just implemented this to test it out on facebook.com/pages/Sean-Weigold-Ferguson/112141502160971. Would love if you visited it to help me work out the kinks.

  40. Andrew said on :

    So how do I paste the code into the bottom of my pages? I there something I am missing in step 3? Can you explain this a bit better?

  41. Louise said on :

    This is great, but am I correct in thinking that the code can only be added to the static FBML pages? And if it can’t be loaded on the “wall” and “info” pages, wouldn’t it lose track of the visitor and give incorrect data?

  42. Richard said on :

    This really is a fantastic tool and I was excited to add the functionality that self-hosting would allow, but as previously mentioned, the package to self-host seems to have a scripting error in it. This results in the appearance of a broken image link on the facebook page. It gives a T-error on line 23 of Galvanize.php when you enter the link directly into the browser.

  43. iphp said on :

    @Richard, Are you running PHP version greater than 5?
    @Louise, to add to the wall you need to create a box which is mentioned on this page within comments.
    @Andrew, Just copy the code from the FBGAT generator and put it on the staticFBML as shown on the update image.

    I am not able to keep up with most comments. I would love to see you answer questions to other people awaiting answers. Or atleast sharing your positive experience to keep them going.

  44. Nadine said on :

    Is there a way to tag the rest of the tabs? Currently, there’s no way to drop the boxes into the Video, Links, and Photos tab. We have the boxes for those tabs resting in the Boxes tab- will it only pick up tracking when the user is at the boxes tab? Is there another work around to get tracking in these tabs, such as embedding code into the images that are uploaded into facebook? Please advise.

    Word is facebook is planning on getting rid of the boxes tab in Fall 2010, and there will be a new platform in which to build new apps in instead of Static FBML- are their new plans in development to get GA into the new format?

  45. Max said on :

    Thank you, this is a great move and very well written. I successfully put a FBML Box on my Fanpage which includes the tracking code and now I am receiving data.

  46. Brent Han said on :

    Thats a lot of info to take in but very informative,thanks.

  47. Cassy said on :

    Good morning iphp! I downloaded the code and placed it in a “facebook” folder within my website’s directory. from there, i used the generator to generate the code (already set up a facebook.com profile in our GA account) and added the FBML box to the wall with the code within it. The box is titled “TFT Blog”. I saw in one of your comment posts to type in the url and it should redirect you to google analytics. The link isn’t redirecting, only takes me to a blank page but still under our domain and the FBML box on our page show’s a broken image icon. when you have a chance, i’m curious as to what i may be doing incorrectly. facebook.com/topfloortech – thank you much in advance!

  48. iphp said on :

    @Cassy, Please use the hosted version, there is something wrong with the image URL. Are you sure you are running a PHP version greater than 5? Please turn on error reporting there definitely is some kind of error. Ideally you should get redirected to Google (and shown a blank page) when you visit the FBGAT link on your browser.

  49. Guy said on :

    Great tool – also useful for hosted WordPress blogs

  50. Pingback: How To Add Google Analytics to Your Facebook Business Page

  51. Pingback: Well, what is a good digital music strategy ? » Article » owni.fr, digital journalism

  52. Clacton said on :

    Great, thanks a million for this. Tracking all my visitors perfectly!!

  53. Brandon Tran said on :

    I installed fbga on a custom tab application which facebook caches the image. Will that affect the results? Should I add a datetime variable to the end of the url or will it work as is?

    facebook.com/pages/Jake-Night/125934074087372?v=app_123865557631259

  54. Paolo said on :

    Well, probably a silly question, but… HOW can I add an image to the bottom of an fb fan page?

  55. Paolo said on :

    Ok, I was able with “Static FBML”.
    Now, tell me: “/” will refer to the wall page?
    Or do I have and use “/wall”?

  56. Stanley said on :

    I cant thank enough for this!

  57. Collin Condray said on :

    I’ve added a static FBML box to my wall but it looks like all the code has been escaped and the image is loading. I’ve got the image in the “Thanks For Visiting” box in the lower left of facebook.com/pages/Fayetteville-AR/Township-Baptist-Church/89000767842 . Did I skip a step somewhere or is there a box to turn the escape off?

    Thanks for the great tip!

  58. iphp said on :

    @Clacton, Awesome, glad you got this working, thanks for reporting back!

    @Brandon, For applications (canvas applications), I suggest you use Fb:google-analytics. If you search developer documentation or on Google, you will get answers to this. If you prefer to use this, yes you need to add variable

    @Paolo, / or /wall should do the trick. I prefer /wall. It looks like you figured out how to add image to the bottom of the page. A screenshot is at the footer of the actual article, before comments.

    @Collin, I visited your page and it looks like things are working correctly, you should see logs appear on Google Analytics soon!

  59. erik said on :

    big thx to you, awesome info!

  60. erik said on :

    hey there, i got it working perfectly, but i tried it on a page with seo-friendly urls first. now i wanna integrate it into a page with smaller amount of fans and crappy urls. how deep should i define the url path? is like
    /BlaBla ok?
    or do i need /pages/BlaBla ?
    or even /pages/BlaBla/101963159841418
    or (! one more, sorry^^!) /pages/BlaBla/101963159841418?v=app_4949752878 (in case there is an app)

    still big thanks, for seo frndly urls working perfect.

  61. Awesomeness said on :

    Thanks for the post, it works great!

    @erik, Anything is file /BlaBla should work correctly. Please remember to create a new Google Analytics profile and code, if this is your second it will look something like this UA-9292929-2, A 2 in the end.

  62. erik said on :

    hey @awesomeness : thx, thats probably why its not working

  63. John said on :

    Got this working great. Thanks for the cool tip! I can even see visits to my wall that isn’t an application. Anyone got ideas about how to continue tracking wall visits after Facebook removes boxes from it?

  64. Collin Condray said on :

    I was using an old tracking code related to the fan page and the tracking information wasn’t showing up. When I created a new profile in Google Analytics and used that instead, it started working again. I’m still not sure how to get a different code on the Wall and Info page though.

    Thanks!

  65. Ryan said on :

    This is cool. One question I have is enabling FBML on standard tabs like Discussions, Photos, Video, etc. I want to track analytics on such tabs but not sure how/where to insert the code unless I’m overthinking things!

  66. Giulia said on :

    Hi all,
    I need your help.
    Im customizing a fan page with 2 new tabs (newsletter, shops)- Each tab is made with a img that links to the website. Does UTM parametres (source,content..) works in the fbml code?
    Plus, I have some questions for the generator code

    Analytics Code: is the one of my website (already existing) or the one of the new analytics profile facebook.com/myfanpage)

    Domains on analytics: is it mywebsite.com or facebook.com?

    page link: is it the link (ie /newsletter.php) linked to the img in the tab?

    Thank you

  67. Muther said on :

    First I wanted to tell you that you made a grate product
    Second I have several facebook pages of US brads in Argentina, the thing is in some of them I am receiving a lot of visits for the US, even more that form Argentina, to me this seems strange because the pages are in Spanish and targeted to the argentine audience.
    I been looking in the data and found that most of the visits from US come from facebook inc as a service provider. Can it be a that facebook has cached my page? Or are there really facebook employees?

  68. Jarl said on :

    Wonderful! You guys are the bee’s knees.

  69. Fort Henry said on :

    Does this work for just a regular Facebook page? rather then just a fan page? and where in the bottom do you insert the code?

Comments are closed.