Analyzing Traffic with Google Analytics
Problem
I want to know more about what users are doing within my application, and I really love using Google Analytics on my off-Facebook site, but dropping its code into my Canvas page didn’t work. How can I use it?
Solution
Use the fb:google-analytics
tag to insert your tracking code for you. The simplest form
is:
<fb:google-analytics uacct="UA-9999999-99" />
where uacct
is the _uacct
variable from your Google-provided
code block. The FBML parser will render that into:
<script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript"> </script> <script type="text/javascript"> _uacct = "UA-9999999-99"; urchinTracker(); </script>
Discussion
The first thing to note is that this tag still produces the
old-style Analytics code that calls the urchinTracker()
, rather than the
new-style code:
<script type="text/javascript"> 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")); </script> <script type="text/javascript"> var pageTracker = _gat._getTracker("UA-9999999-99"); pageTracker._initData(); pageTracker._trackPageview(); </script>
One of the features of the new code is the automatic detection of HTTP versus HTTPS, which would be wasted inside of Facebook because there are no secure connections to Facebook apps at this time. It also offers you the ability to track specific events ...
Get Facebook Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.