How to add Google Analytics Tracking ID to GitHub Pages

前端 未结 8 573
广开言路
广开言路 2020-12-07 06:36

Could be a simple question but I am full of doubts right now about adding Google Analytics Tracking ID to GitHub page.

I am using G

8条回答
  •  生来不讨喜
    2020-12-07 07:10

    If you are using the minima template provide by Jekyll then -

    1. Add google_analytics: UA-xxxxxxxx-x to your _config.yml
    2. Create a file _includes/google-analytics.html and add the google analytics js code in it.

    Replace

    ga('create', 'UA-xxxxxxxx-x', 'auto');
    

    with

    ga('create', '{{ site.google_analytics }}', 'auto');
    

    and you are set!

    The google analytics code will now display if your site is built in production environment. For reference see the template's source code here - https://github.com/jekyll/minima

    You can follow the same approach if you are using a different template by referencing the template's source code and replacing the corresponding files.

提交回复
热议问题