Modify iWeb sites to work with Google Analytics

Dec 22, '06 07:30:04AM

Contributed by: mooman

Not really being able to properly use Google Analytics together with iWeb has been bothering me for a while. I've been checking the source iWeb output, and came up with a rather simple, semi-automatic (lacking some AppleScript skills to make it fully automatic) solution using BBedit. (This should also work with any other text editor that supports multi-file search and replace.)

Using BBEdit's Search function, I made a multi-file search through all of the iWeb project's .html files, searching for...

</body>
...and telling BBedit to replace it with this:
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "##-######-#";
urchinTracker();
</script>
</body>
Replace the ##-######-# with your site's tracking ID. Now just save this as a search pattern, and every time after publishing your site to a folder (~/Sites in my case), just apply it to that folder.

Using AppleScript, it should even be possible to make this a more or less automatic task. It's not very sophisticated, but for my needs it does the job well. It even works if you are publishing to your .Mac account -- simply apply the rules on your specific iDisk's iWeb Folders. (For reference, this hint comes from this entry on my blog.)

Comments (4)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20061220033306772