Friday 16 March 2012

Tracking IFrames through Google Analytics

Step 1: Create a Facebook iFrame tab and get the URL. Something like this:

 http://www.facebook.com/example.in?sk=app_180487048663627

Step 2: Link it to your Facebook iFrame page placed on your Domain:

www.domain.com/facebook

Step 3: Please remove the formatting in red and replace it with your Google analytics id
1.    <script type="text/javascript">
2.     
3.    var FacebookURL = 'http://www.facebook.com/YourFacebookPage?sk=app_123456789';
4.     
5.    var _gaq = _gaq || [];
6.    _gaq.push(['_setAccount', 'UA-XXXXXX-X']);
7.    _gaq.push(['_addIgnoredRef', 'static.ak.facebook.com']);
8.     
9.    // If Google Analytics is loaded and this page isn't framed inside our Facebook URL, frame the page.
10.  if (_gaq.push && self.location == top.location) {
11.  // Create a fake URL that we can filter in Google Analytics. This pageview also sends the traffic source data to Google Analytics.
12.  _gaq.push(['_trackPageview','/facebook/campaign-tracking/']);
13.  // Tracking done, let's frame the page
14.  setTimeout(top.location.href = FacebookURL, 200);
15.  } else if (self.location == top.location) {
16.  // If Google Analytics doesn't load within 2 seconds, refresh and frame the page anyway. People dislike waiting. Change the time if you like.
17.  setTimeout(top.location.href = FacebookURL, 2000);
18.  } else {
19.  // The Page is Framed. Let's track it.
20.  _gaq.push(['_trackPageview']);
21.  _gaq.push(['_trackPageLoadTime']);
22.  }
23.   
24.  (function() {
25.  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
26.  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
27.  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
28.  })();
29.  </script>

No comments:

Post a Comment