Using Google Analytics on Facebook Fan Pages

Can you use Google Analytics on Facebook fan pages and fan page walls? You betcher sweet ass you can.

If you’ve ever created a Facebook fan page, you’ve probably realized that the “reporting” that Facebook provides is basically useless. Because Facebook limits the Javascript you can use on Fan Pages, you cannot implement your own analytics packages on fan pages. Or at least, that’s what they want you to believe.

For Facebook applications, there is an FBML tag that will allow you place your Google Analytics code on the canvas page – but this FBML will not work on fan pages, application tabs, or anywhere other than the canvas page.

Fortunately, implementing Google Analytics on your Facebook fan page is possible, with a little PHP trickery. The basic gist of the workaround is to include your Google Analytics code as an image instead of placing the javascript into the FBML code.

Rather than writing something from scratch, it makes more sense to direct you to a post on the Webdigi blog that offers a free set of PHP scripts that will let you do exactly that.

The long and short of what the guys over at Webdigi are doing with their scripts is simply to call a PHP script instead of an actual image file in the <img src> code. This is not unlike the “tracking pixels” that are often used in email newsletters, since Javascript is not an option there either. So the concept isn’t new, but it’s not common knowledge that it works on Facebook.

The PHP script they are calling contains the Google Analytics code, and accepts parameters so that you can re-use the script on multiple fan pages (or different pages in an application) simply by setting different parameters.

When your Static FBML tab, application tab or non-canvas app page loads, it loads that “image” as part of the page. That “image” then pings the PHP script, which pings Google Analytics. This could be adapted for other reporting systems as well, using the same concepts.

The guys do a nice job with their script, and they even offer a wizard that helps you figure out what you need to put where.

I had rigged up a script a few months ago, but I never really had the time to package it for the general public, make it easy to configure, and so on, so go ahead and check out their script package.

Using this method, you’ll even be able to set up funnels and goals for your Facebook fan page stats, and Webdigi offers a great breakdown on how to tell the difference between fan and non-fan activity on your fan pages in your reporting.


  • Yeah, this is pretty clever shit. Thanks for turning me onto the dudes over at Webdigi. Good stuff.

  • atlantajones

    Have you actually gotten this to work and track pageviews? I've tried everything, even using the hosted IMG code from their wizard, and GA still says tracking is not installed.

  • Ran into the similar issue atlantajones ran into. They provide the code though for personal hosting, so I may give that a whirl to see if that solves it.

  • I heard facebook is removing applications' profile boxes, is that true? Is it really happening?

  • atlantajones

    Following up, the tracking is indeed working. For some reason Google still says “tracking not installed”. Maybe that only means that the regular javascript-based tracking is not installed. Must not work the same for the tracking pixel technique.

    So yes, I can confirm this actually does work. What's cool is that our apps have multiple “views” within the same tab, based on date, time and/or other factors. And we can alter the tracking data to make them appear as separate URL's in analytics.

  • Pingback: Facebook Versus the Internet | The Get Smart Blog()

  • Hey Andrew – sorry I didn't reply to this. Past month has been hell. Glad you got it all sorted though.

  • Thanks for the great app, but some how it doesn’t work for me. I have pasted the img. code in FBML on my facebook page, and analytics is also saying it is tracking, but when I or friends go to my page it doesn’t track it. It only tracked 3 visitors form america, and I think that they havn’t even visited my site. Can any body help.
    My img code looks like this:


  • Josh

    I have a question, and please pardon my ignorance … what is the “canvas page” on a Facebook account?