RapidWeaver Tip #2: Google Analytics

Preamble

logo_ga
Google Analytics is one of the most powerful tools out there for gathering information about your website's visitors. Sure, there's others such as Mint, but you sure can't beat the fact that this formerly three-figure-priced package is now the great price of free! One of the big bonuses seems to be the tight integration with AdSense (if you're an AdSense customer) but it's suitable for all. I'm not going to look at the features in this post, more to look at how to integrate the free Analytics account and its tracking code into your RapidWeaver-built site, but if you want to find out more, the Analytics site has the low-down.
This tutorial assumes you've now got an account for Analytics, and have some code that looks like this:
< script src="http://www.google-analytics.com/urchin.js" type="text/javascript">< /script>
< script type="text/javascript">
_uacct = "UA-xxxxxxx";
urchinTracker();
< /script>
The xxx being a series of numbers. Don't worry if there's no spaces after each < (I've done that to ensure that the code doesn't work and instead is displayed in this tutorial!). Other than the the Analytics code, you're also going to need a text editor for one of the steps (this tip requires some pasting into an HTML file). I use skEdit (shareware) but the very excellent, and very much free, TextWrangler from BareBones software is my free pick. The tutorial will modify a copy of your theme file used in the RapidWeaver file. As a result, you will need to re-publish the entire site to get the code to be placed on every single page. There is no way to get around this, so it might be worth doing the code bits before lunch and leaving RapidWeaver to publish whilst you're away as, depending on the site size, and the speed of your net connection, it could take a little while.

Disclaimer

This tutorial is produce in good faith. This technique is used on my own site, and I routinely recommend it to people who wish to use Google Analytics with RapidWeaver. However, you follow the steps at your own risk. I can offer no support if you undertake this tutorial, unless through the RapidWeaver forums. Please ensure you have a fresh backup before doing any modifications to a RapidWeaver site that is in development or in production! If there is any error with this tutorial, please let me know!

The Tutorial Starts Here!

    1. Open the RapidWeaver file you want to work with.

    lb

    2. Open the Theme View.

    3. Right click your currently used theme, and choose 'Duplicate Theme'

    lb

    4. Enter a new name for your theme.

    5. Select the duplicated theme as your site's theme. You will have to re-set all (or any) Theme Variations in the Theme Inspector (Cmnd + 1).

    6. Right click the new theme in the Theme View and choose 'Show Contents'. A window like the one below will appear.

    lb

    7. Right click the file index.html, and choose to 'Open With' -> 'TextWrangler'.

    8. In TextWrangler, hit Cmnd + F (Find) and search for '/body' (without the 's).

    9. You'll find the term almost at the very end of the file like this:

    lb

    10. Paste the Google Analytics code above the < /body> tag, but below the code above it. You should end up with it like so:

    lb

    11. Save the HTML file, ensure your project has all the Theme Variations correctly re-added, and then we're set to publish. Before you do so, however, you should ensure you Clear Publishing Cache (at the Publish dialogue) to ensure all your pages have been updated.

    12. Sit back and allow Google Analytics to collect the information - and be patient. It can take some time. (Note, if you're on Tiger, there's a damn neat dashboard widget called Dashalytics which allows you to view summary information from the OS X Dashboard).