Add Google Analytics to Jekyll

Learn how-to add Google Analytics to your Jekyll powered website.

Google Analytics | Jekyll

Add Google Analytics to Jekyll

Learn how-to add Google Analytics to your Jekyll powered website or blog.

Add the following in between the <head></head> tags:

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

And then add the following to the _config.yml file.

google_analytics: UA-12346578-1

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