gitblog增加google-analytics统计功能

默认分类 · 2017-01-09

一、前提

假设已有google analytics账号及模板,并且有对应的js代码,比如我的js代码:

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-49496058-1', 'auto');
  ga('send', 'pageview');

</script>

二、修改theme对应的文件

比如我选择的quest这个主题,那修改的就是
quest/block/base.html这个文件

将前面的script代码加入到下面这部分代码的后面即可:

<body class="home blog wide">
    <div id="page" class="hfeed site">
        <a class="skip-link screen-reader-text" href="#content">Skip to content</a>
        {% block header %} {% endblock %}
        {% block content %} {% endblock %}
        {% block footer %} {% endblock %}
    </div><!-- #page -->
    <a href="#0" class="cd-top"><i class="fa fa-angle-up"></i></a>
gitblog google-analytics
Theme Jasmine by Kent Liao