I found a decent way of adding Google Analytics to all pages, without using HTML Snippits (which cause analytics to track those odd page names like widget2_markup.html), that doesn't break MobileMe comments, and doesn't require
any post-processing of your iWeb site. Just Publish and go! Open up your iWeb app bundle, and drill down to Contents/Resources/Scripts/Site. Open up the file iWebSite.js in TextEdit (or your favorite text editor), and paste the following at the bottom of the file:
// Begin Google Analytics
gaTrackerId = 'ss-ddddddd-d'; // insert your tracker id here
document.observe('dom:loaded', function() {
var gaJsHost = ( ('https:' == document.location.protocol) ? 'https://ssl.' : 'http://www.') + 'google-analytics.com/ga.js';
var script = new Element('script', { 'src': gaJsHost});
var gaTrack = function() {
if (
!script.readyState
|| /loaded|complete/.test(script.readyState)
) {
var pageTracker =
gat.getTracker(gaTrackerId);
pageTracker._trackPageview();
}
};
script.observe('load', gaTrack);
script.observe('readystatechange', gaTrack);
document.body.appendChild(script);
});
// End Google Analytics
Credit to this solution goes to
this blog post. I got the idea to find a way of using Google Analytics in Prototype (since iWeb sites use
the Prototype JavaScript framework) and found that blog snippit.
And yes, since this
is editing the iWeb application bundle, you may need to reapply this hack if/when iWeb is updated. Hopefully though, some enterprising iWeb engineer is reading this and will add proper Google Analytics support to iWeb for us. 🙂