Why Google Analytics Can’t Run in Facebook iFrame Apps

There has been a lot of talk lately about Facebook iFrame apps and Google Analytics.

I’ve been asked several times from people about the possibility of running Google Analytics for the new iFrame tabs.

And so I’ve been searching for a way since last week to make this happen – to make Google Analytics run within a custom iFrame tab on a Facebook Fan Page.

The benefits would be great because you’d be able to see what kind of traffic your new app was getting.

However, my searching came to end yesterday when it occurred to me why Google Analytics, or GetClicky, or any other analytics tracking code for that, cannot run on an iFrame tab.

The reason is because iFrame tabs are iFrames.

Duh… really?

I realized yesterday that because these pages are an iFrame running within Facebook, the application that you build it not generating it’s own unique pageviews, only the pageviews from within Facebook.

So in the traditional form of pasting your Google Analytics code into an iFrame app, it’s not going work.

This doesn’t mean, however, that traffic analysis is not possible – because it is.

But the analytics integration has to come from within the code and frame of Facebook, not Google Analytics.

The bottom line – is it possible to analyze traffic to your iFrame apps?

Yes.

Will it happen by pasting Google Analytics, or any other analytics code, into your iFrame tab?

No.

Stay tuned as I continue down this road of generating analytics for iFrame tabs.

  • Jason Padvorac

    I just helped someone set up Google Analytics with the Static HTML app (http://on.fb.me/gFHdQV). The comment thread is here:

    I’ll copy-paste the instructions I wrote there for convenience. :)

    – Jason

    ———–

    You’ll want to use a Google Analytics snippet that is set up for “multiple domains.” You can read about it in detail here: “>http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55503

    The good news is that for this particular instance, probably all you need to do is add two lines of code to the standard Google Analytics snippet and you’ll be fine. Or you can just copy-paste the snippet below, add your specific tracking id, and you’ll probably be fine. Let me know if it doesn’t work!

    var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);document.write(unescape(“%3Cscript src='” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));

    try{var pageTracker = _gat._getTracker(“UA-12345-1”); // Replace UA-12345-1 with your code
    pageTracker._setDomainName(“none”); // ** THIS LINE IS NEW!
    pageTracker._setAllowLinker(true); // ** THIS LINE IS ALSO NEW!
    pageTracker._trackPageview();
    } catch(err) {}

  • This doesn’t make any sense to me. Why don’t you just install the Google JS into the base page you’re loading into the parent iFrame on Facebook? You could even have nested iFrames within your app and have different instances of Google Analytics running in each, so as to measure user interaction with different areas of your app. I’m not sure what you recent articles on the subject are really about other than misunderstanding the way nested frames relate to measurement.

  • Emkayy

    You can add Google Analytics!
    The only limitation is that you won’t get the referers since facebook will always be the referer.

    Here is an article about how it works:
    http://mediafunnel.com/facebook/facebook-iframe-page-tab-web-analytics/