less than 1 minute read

  • Sign up for new Google Analytics account using this link.

  • Paste the Google Analytics tracking code into a new file named _includes/analytics.html file under your Jekyll project. This step enables the tracking code template for use for all available Jekyll pages.

_includes/
├── analytics.html
  • Insert {% include analytics.html %} after {% include head.html %} line in the _layouts/default.html file. This step ensures that the tracking code template will be included in all generated Jekyll pages.
    {% include head.html %}
+   {% include analytics.html %}
  • Run jekyll build to generate the Jekyll site using the Google analytics template. You will notice that Google Analytics tracking code is included in the generated pages. For example, _site/index.html.

  • Otherwise, run jekyll serve or bundle exec jekyll serve command to serve and test your site locally at localhost:4000.

Credits

Read Michael Lee’s post or Jekyll documentation on further customizing Google analytics for Jekyll for use only in production environment.

Updated: