my tech blog

To iterate is human, to recurse divine

Octopress, Google Analytics and Github Pages

The Octopress blog engine makes it easy to enable Google Analytics for your site.

First thing to do is to edit the _congif.yml file that is located in the root folder of the octopress source tree. Locate the line with the key google_analytics_tracking_id and add your tracking id that you have created on the Google Analytic site. This might be all you need to do to make the tracking working for your site, however sometimes you will need to do some extra configuration, especially if you are hosting your site on github pages like this site.

The extra configuration has to do with the use of the subdomain in the URL. In my case I had to add an extra line of javascript to the default script that octopress is using for Google Analytics. The template file can be be located here: source/_includes/google_analytics.html, in the source tree of octopress.

    _gaq.push(['_setAccount', '{{ site.google_analytics_tracking_id }}']);

The code above is only showing small section of the html file mention above. However it’s the second line that has to be added manually for supporting sites with subdomains.

This should be enough for enabling Google Analytics on your site.