Add google analytics to your jekyll website

Table of Contents

  • Introduction
  • Method
    • Step One
    • Step Two
    • Step Three
    • Step Four
    • Final Step
  • Ending

Introduction

Google Analytics is a freemium web analytics service offered by Google that tracks and reports website traffic. You can visit here for more information.

In this post, we are going to add goole analytics to a jekyll website. This blog is an example website, having contained google analytics code already.

Method

Step One

To add google analytics, you should visit google analytics website and sign up a google account:

![image](https://raw.githubusercontent.com/LinShiwei/linshiwei.github.io/master/images/屏幕快照 2016-07-20 09.24.04.png)

![image](https://raw.githubusercontent.com/LinShiwei/linshiwei.github.io/master/images/屏幕快照 2016-07-20 09.26.22.png)

For Chinese version, you can visit here. If you have had a google account, you can log in and go to next step.

Step Two

After you have a google account and log in google analytics website, you need to follow the guide to register for google analytics.

Choose website in this page:

![image](https://raw.githubusercontent.com/LinShiwei/linshiwei.github.io/master/images/屏幕快照 2016-07-20 09.28.39.png)

Fill in website name and website url. Select one industry category.

Then click Get Tracking ID.

Now in your google analytics page, you will get a track ID such as UA-80935640-1 and some code for website tracking:

![image](https://raw.githubusercontent.com/LinShiwei/linshiwei.github.io/master/images/屏幕快照 2016-07-20 09.30.07.png)

Step Three

Copy the tracking code, create a google-analytics.html file in your jekyll website's _includes folder:

![image](https://raw.githubusercontent.com/LinShiwei/linshiwei.github.io/master/images/屏幕快照 2016-07-19 23.19.11.png)

Put the code in this .html file:

![image](https://raw.githubusercontent.com/LinShiwei/linshiwei.github.io/master/images/屏幕快照 2016-07-20 09.32.53.png)

Step Four

After creating google-analytics.html with tracking code from google analytics website, you can open the footer.html file in _include folder and add include google-analytics.html in it like the following:

![image](https://raw.githubusercontent.com/LinShiwei/linshiwei.github.io/master/images/屏幕快照 2016-07-19 23.16.44.png)

This step will simply add analytics code to all pages in your website, which helps google to analyse.

Final Step

We have added analytics code to website step by step. Now in Terminal of your website folder,let's run:

$ jekyll build

After that, you can preview your website at http://localhost:4000 by running:

$ jekyll serve

Ending

If you use github to manage your website code, you can use github desktop to commit changes to master. The google analytics will work in no time. You can see the analytics report in your google analytics page.

By the way, if you want to know how to build your own blog in Github, here is another post for you.

My Github:LinShiwei (Lin Shiwei) · GitHub

你可能感兴趣的:(Add google analytics to your jekyll website)