Getting google analytics to work with Ghost

The more observant of you may have noticed that I've moved my blog over to Ghost recently. It was a very painless excercise. You can actually create a server running Ghost using Bitnami and if you choose to run it on Amazon you can run it on a micro instance which will be completely free. As those of you who know me well will already know free just happens to be my favourite price.

One thing that is missing though from Ghost at the moment is the ability to add google analytics tracking to your website. Fortunately it's very easy to do.

If you already have the code for Ghost downloaded then simply edit the file default.hbs which is found under


This assumes you're using casper as your theme. If you're using another theme then simply replace casper above with the name of your theme.

Within your default.hbs file at the bottom you'll find something like this

    {{! The main JavaScript file for Casper }}
    <script type="text/javascript" src="/assets/js/index.js"></script>


Simply grab the google analytics tracking code and insert it in the space I've put the comment below.

    {{! The main JavaScript file for Casper }}
    <script type="text/javascript" src="/assets/js/index.js"></script>

    <!-- Google analytics stuff goes here -->


Refresh the page and you should now be sending user data over to google to do their magic with.

Of course if you're running your Ghost instance on Bitnami as I am you'll need to know how to get at the code running your blog. Fortunately again it's pretty easy to do. Simply log on to the Bitnami Access Console and navigate to the server running your blog and click Connect. You'll be presented with a box like this.

If you're running Windows you can use WinSCP to push and pull files form the server. Simply pull down the ppk file and away you go.

If you're running on a linux or OS X then download your pem file. You'll then want to limit permissions to your key. Simply run

chmod 600 bitnami-hosting.pem

Run the following to pull down the Ghost code.

scp -r -i bitnami-hosting.pem bitnami@ ghost

Make the changes as mentioned above then all you have to do is push the .hbs file back to your server.

scp -i bitnami-hosting.pem htdocs/content/themes/casper/default.hbs bitnami@

Once completed your new file will be up on the server and the next time you load the page if you view the source code you should see your additions on the page.