a device for turning coffee into software
Spacelag is now completely hosted by Google Apps and Blogger. This is the most recent in a long line of experiments for me. I have tried Confluence, Wordpress, TiddlyWiki, Drupal and a slew of others all running on a hosted virtualized server. These all worked fine, but Google is free, faster and I do not have to be my own sysadmin!

Blogger works fine as a blog, but I really wanted a simple wiki for spacelag. The only options Google Apps provides for website hosting is Google Page Creator. If you have used it, you will know it isn't especially flexible and there are no options for server-side scripting. That's when I returned to TiddlyWiki.

I have used TiddlyWiki off and on over the past couple of years, mostly for personal note keeping. I have also used TiddlyWiki at work for deploying documentation and tutorials with web applications. I have even used TiddlyWiki with server-side extentions as a wiki for spacelag. This time around it's just a stock TiddlyWiki served as a file on www.spacelag.com/.

That's definitely simple and I love not having to maintain mysql and the rest of the software stack. But how will I know if people are actually visiting the site? For this, Google provides Google Analytics. Signing up was easy and the code snipped required to enable the blog was simple enough, but TiddlyWiki required a little more thinking. I could have just hacked the code to include the required scripts, but this is not the TiddlyWiki way.

After a little bit of googling, I came across Tracking TiddlyWiki with Google Analytics by Phil Hawksworth. He provided almost exactly what I needed. You can follow the link for details, but I will provide a brief recap.

The first step is easy, simply add the markup provide by Google Analytics to the MarkupPostHead tiddler. TiddlyWiki will inject this into the loaded page just after the HTML head element. This will now register a page hit whenever someone loads the wiki.

The second step is to enable tracking individual tiddlers by overriding the displayTiddler function to call urchinTracker("/" + titles) before displaying the tiddler.

The only change I made to Phil's code is to call urchenTracker only when readOnly == true. This way I do not make calls to google when I view and edit offline. I chose readonly because I set my blog to be readonly when it's online. You could also check window.location to make sure it contains a specific URL or some other trick.

Below are my versions of the required tiddlers.

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">

CustomTracker (tag with "systemConfig")
// Specify your account number here!
_uacct = "UA-1234567-1";

// CustomTracker as a namespace for tracking related functions
var CustomTracker = {
// store a reference to the original displayTiddler function
displayTiddler: story.displayTiddler

CustomTracker.track = function() {
if (readOnly) {
urchinTracker.apply(this, arguments);

CustomTracker.trackAndDisplayTiddler = function(srcElement, titles) {
// log with the tracker
CustomTracker.track('/' + titles);
// call the original displayTiddler function

// replace the default displayTiddler function with a tracking version
story.displayTiddler = CustomTracker.trackAndDisplayTiddler;

// Call once for the initial page load