This post contains step by step guide to setup google analytics for your Jekyll powered page. The only requirements are google account and working Jekyll powered page.

  • log into analytics with your google account

  • setup analytics account and property in my case github.io and sansajn.github.io as property

  • setup Data Stream for sansajn.github.io property from previous step

  • copy Global Site Tag, in my case

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-88ZTXK100S"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-89ZTXX100S');
</script>

note: your measurement id (in my case G-89ZTXX100S) will differ so do not just copy paste from there

  • create google-analytics.html in _includes and paste GST (Global Site Tag) from previous step and save

  • copy default.html from /var/lib/gems/2.7.0/gems/minima-2.5.1/_layouts/ to _layouts in your Jekyll project

note: in Ubuntu 20.04 LTS default minima theme is stored in /var/lib/gems/2.7.0/gems/minima-2.5.1 directory

  • open copied default.html and insert
{% include google-analytics.html %}

line just after include head.html liquid statement between opening <html> and <body> HTML elements, this way

<!DOCTYPE html>
<html lang="{{ page.lang | default: site.lang | default: "en" }}">

  {%- include head.html -%}
  {% include google-analytics.html %}

  <body>

    {%- include header.html -%}

    <main class="page-content" aria-label="Content">
      <div class="wrapper">
        {{ content }}
      </div>
    </main>

    {%- include footer.html -%}

  </body>

</html>

and you are done!