Google Analytics Glossary

Add Google Analytics to Github Pages

Image of Iron Brands

Published on Dec 23, 2022 and edited on Apr 8, 2024 by Iron Brands

Gathering insights into your website performance is vital for every business and Google Analytics can help with that. To make your life easier, we’ve created this article to show you how to add Google Analytics to GitHub pages step by step.

Let's dive in!

  1. Step-by-step integration
    1. Set up a Google Analytics property
    2. Add the tracking code to your website
    3. Include the analytics in your site's layout
    4. Push your changes
  2. Google Analytics not showing data
  3. Final Thoughts

Before we dig in I want to show you something. I promise it's worth it...

Google Analytics is great, but also complex and a bit clunky. If you just want a straightforward dashboard with the insights you need, GA is not a great place to start. Additionally, Google doesn't care about privacy and GA requires an annoying cookie banner.

That's why I built Simple Analytics, a privacy-friendly and simple analytics tool - no personal data, no cookies, just the insights you need in a straightforward dashboard.

Here is how it looks vs GA. Feel free to check our live analytics to get an idea for your project. (It is free btw)

All right, enough about us. Now let's get into answering your question!

Can you spot the difference between the dashboards?

Step-by-step integration

Set up a Google Analytics property

  • Log into your GA account (or create one, if you haven't already).
  • Create a GA property for your website.
  • Inspect your property and note its Measurement ID. You will need this ID later.

Add the tracking code to your website

For a Jekyll-based GitHub Pages site, create a new file called _includes/analytics.html and paste your Google Analytics tracking code snippet into this file. If your site is not built with Jekyll, simply add the tracking code snippet to the head section of every HTML file on your site.

Include the analytics in your site's layout

For Jekyll-based sites, add {% include analytics.html %} to your site's default layout file (_layouts/default.html) just before the closing head tag. This will include your Google Analytics tracking code on every page of your site. For non-Jekyll sites, ensure that the tracking code is added to each HTML file.

Push your changes

Commit and push your changes to your GitHub Pages repository. Google Analytics will start tracking user activity on your website within 24 hours.

Google Analytics not showing data

If Google Analytics is not showing any visitor data, try the following troubleshooting steps:

  • Verify that your tracking code is installed correctly and appears on all pages.
  • Check that your tracking ID matches the property ID in your Google Analytics account.
  • Ensure that your website is accessible and not experiencing downtime.
  • Double-check that you do not have any filters or settings in Google Analytics that block specific traffic sources or user data.
  • Give it some time. It may take a few hours or up to 24 hours for Google Analytics to start displaying data.

Final Thoughts

Adding Google Analytics to your website can give you great insights. However, ask yourself: is Google Analytics the right tool for you?

GA is an overpowered solution for straightforward analytics. If you're looking for a simple and intuitive dashboard with the insights you need, there are better alternatives. Yes, I’m talking about my own product (Simple Analytics), but there are others out there as well.

I hated using Google Analytics for my projects. It's clunky, there are hundreds of dashboards and it doesn't look appealing. Also Google doesn't care about privacy or ethics. That's why I decided to build my own and more intuitive web analytics tool.

If this resonates with you, feel free to give Simple Analytics a spin. You just need to add the script to your site and off you go. This takes about one minute- and there is a free version as well!

Enjoy!