Learn how-to add Google Analytics to your Jekyll theme.

Add the following code snippet to your themes default.html file in-between the <head></head> HTML tags.

{% if site.google_analytics %}
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics }}"></script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ site.google_analytics }}');
{% endif %}

In your theme’s _config.yml file, add the following:

google_analytics: UA-12346578-1

Replace UA-12346578-1 with your Google Analytics property tracking ID number.

Share this post