In a previous post, we covered how to get your Jekyll blog working with Bluemix. Once you start posting your content, you’ll want to do more with it and will want to see how many pages are accessed and who’s coming knocking from where. For this, one of the easiest ways to get started is to use Google Analytics.
This is really easy to do but I’ll post the instructions here simply to show you how easy it is!
- To get started, you need to make sure you have a Google ID (e.g. by signing up for GMail or such). If not, sign up for a Google ID that you want to use.
- Next, visit Google Analaytics and log in. If you have multiple Google Accounts, I would recommend using a private browser window to log in so that your accounts do not get mixed up.
- Click on Admin so that you can create a new Google Analytics Tracking ID. Under Account, click on Create a New Account.
- Select Website and fill in the details below. Remember to set the reporting time zone to what makes sense for you.
- Then, click Get Tracking ID – this will bring up the Terms of Service Agreement. Read it and accept it.
- On the next page, you will get your Tracking ID that will start with something like: UA-11111111-1
You are now ready to get started. The page will also give you the code that you need to include into your pages. However, most Jekyll themes already include this code in the template and you only need to add the Tracking ID to the
_config.yml and just add your tracking ID to it. Rebuild your site and upload it. You’re good to go.
The first set of analytics might take up to 48 hours to start showing.
The theme will usually just wrap the Google Analytics code into Liquid tags and put it onto your page if an ID is provided. For the theme that I am using, this is what the code looks like.
The code below is included in the
_incude\footer.html which is the fragment that is included in the layouts for the footer.
You’ll see it does two main things:
- Checks if
site.google_analyticsis defined – if it is, the above code is included into your footer and therefore the page
- Outputs the
site.google_analyticsvariable into the second last line after the
'create'to identify your account
That’s all there is to it – simple, and really no magic even if you want to do it yourself!