In this article
GitHub Pages is static hosting. It serves your files and runs none of your code on a server, so analytics on a Pages site comes down to one thing: a script tag that runs in the visitor's browser and reports each pageview to an analytics service.
Pasting the tag takes a minute. Finding the right file is what catches people out, especially on a Jekyll theme whose layouts aren't in the repository at all. Here's where the tag goes for each kind of Pages site, how to check that it fires, and what to weigh when you pick the tool.
What you're adding: one script tag
Most analytics tools give you a snippet shaped roughly like this:
<script defer src="https://analytics.example.com/script.js" data-site="YOUR-SITE-ID"></script>That's a placeholder, not a working tag. Copy the exact one from your tool, because the address and attributes differ from tool to tool. Follow its placement instructions too. Google, for example, asks for its tag immediately after the opening <head> on every page.
Whatever the tool, the part that matters is "every page". A page without the tag simply doesn't exist as far as your analytics is concerned.
Which kind of Pages site you have
Open the repository that publishes the site and look at the folder Pages publishes from.
- Plain HTML:
index.htmland other.htmlfiles, and no_config.yml. - Jekyll: a
_config.yml, often with folders such as_layouts,_includesor_posts. When you publish from a branch, GitHub builds the site with Jekyll by default. - Another generator (Hugo, Eleventy, Astro and so on): a GitHub Actions workflow in
.github/workflowsbuilds the site, or the published branch holds ready-built files and a.nojekyllfile. Put the tag in the base layout or head partial in the generator's source, not in the built output, which is replaced on every build.
Plain HTML: every page gets the tag
A plain HTML site has no shared layout, so each page needs its own copy of the tag.
- Open each
.htmlfile, including the ones in subfolders. - Find the closing
</head>tag. - Paste the analytics tag on the line above it, unless your tool asks for a different spot in the head.
- Commit and push.
To find a page you missed, run this in the root of the repository. It lists every HTML file that doesn't contain the script's address, so swap in your own tool's domain:
grep -rL --include="*.html" "analytics.example.com" .No output means every page has the tag. Pages you add later need it too, and a forgotten new page is an easy way to end up with one page that never shows a single visit.
Jekyll: find the file your theme uses for the head
Jekyll builds every page from layouts, so the tag goes in once. The question is which file, and with a theme the answer is often a file that isn't in your repository yet. Jekyll looks at your site's own files before the theme's, so a file you create at the same path as one of the theme's layouts or includes replaces it. That's how the tag gets in.
| Your setup | File to put the tag in | Where in it |
|---|---|---|
| Your own layouts | _layouts/default.html | Just above </head> |
| Minima 2.5.1 | _includes/head.html | Just above </head>, in a full copy of the theme's file |
| GitHub's themes, such as Cayman, Minimal or the default Primer | _includes/head-custom.html | A new file with just the tag. The theme already loads it inside <head> |
| Minimal Mistakes | _includes/head/custom.html | A new file. The theme includes it at the end of <head> |
| Just the Docs | _includes/head_custom.html | A new file. The theme inserts it before </head> |
Minima has no empty slot. Minima is the theme jekyll new sets up, and in version 2.5.1, the one GitHub Pages builds with as of November 2026, the whole <head> lives in _includes/head.html. Copy that file from the theme into the same path in your repository and add the tag just above </head>. Copy the whole file, not only the tag. It also carries the theme's stylesheet link, SEO tags and feed link, and anything you leave out disappears from every page. The original is in the jekyll/minima repository under the v2.5.1 tag. If you run Jekyll locally, bundle info --path minima prints where the theme's files are.
GitHub's own themes have one. Several of the themes GitHub supports out of the box, Cayman and Minimal among them, load a file called _includes/head-custom.html inside <head>. So does Primer, which GitHub Pages applies when _config.yml names no theme. Create that file in your repository with your tag in it. Your file replaces the theme's copy, which in Cayman holds little more than a hook for the theme's own Google Analytics code.
Other themes usually name theirs in the README. Search the theme's documentation for "head" before you copy a whole layout. Copying a layout works too, but you then miss any fixes the theme makes to it later.
Keep local previews out of your numbers
When you preview the site with jekyll serve, Jekyll builds it in development mode unless you say otherwise. If your analytics tool doesn't ignore localhost, your own previews get counted. Jekyll exposes the mode as jekyll.environment, so you can leave the tag out of everything but the production build:
{% if jekyll.environment == "production" %}
<!-- your analytics tag -->
{% endif %}Sites published from a branch are built by GitHub's build action, which sets JEKYLL_ENV to production, so the tag appears on the live site. GitHub's starter workflow for Jekyll sets it too. If you wrote your own workflow, check that its build step sets JEKYLL_ENV: production, or the tag will be missing from the live site as well.
Publish, then check that it works
Commit and push. GitHub says changes can take up to 10 minutes to publish. Every deployment runs as a workflow, so its progress and any errors show up in the repository's Actions tab, and when a site published from a branch fails to build, GitHub also emails your primary address. If you've just edited a layout or include, a mistyped Liquid tag is the first thing to look for.
Once it's live, check in three places:
- The page source. Open the live site, view the source and search for the script's address. If it isn't there, the build hasn't finished, or the tag went into a file this page doesn't use.
- The Network tab. Open the browser's developer tools, reload the page and filter by the script's domain. You should see the script load, and usually a second request that sends the pageview. A blocked or failed request is marked as an error.
- The tool's real-time view. Visit the site in another browser and watch the visit arrive. In Google Analytics that's the Realtime report, which covers the last 30 minutes.
If the script is blocked, look at your own browser first. Content blockers and some privacy browsers stop analytics scripts, and some of your visitors use them too, which is one reason no two analytics tools agree on your traffic.
Don't stop at the home page. Check a blog post and a page in a subfolder as well, because they often use a different layout, and a tag in the wrong layout only shows up on some pages.
On a project site, served at owner.github.io/repository, an account's Pages sites share one hostname and differ only by path, unless they have a custom domain. If you track more than one of them, keep them apart in your tool, as separate sites or by filtering on the path, so their numbers don't mix. And if you later move to a custom domain, update the domain in your tool's settings if it has one.
Which tool goes in the tag
Many guides to analytics on GitHub Pages show Google Analytics. It does far more than count pages, and it's a fair choice if you need events, funnels or advertising reports. It also recognises returning visitors with first-party cookies, _ga and _ga_<container-id>, which last two years by default. In the EU that kind of cookie generally needs the visitor's consent, and asking for it is what a cookie banner is for.
For a lot of Pages sites, such as documentation, a portfolio, a personal blog or a project's landing page, the questions are smaller:
- How many people came?
- Which pages did they read?
- Where did they come from?
A tool that answers those without cookies can be enough. Whether that also lets you drop a banner depends on what else your site loads, and what it takes to run a website without a cookie banner goes through that.
If you'd rather host the analytics yourself, Pages can't be the host, because it runs nothing on a server. A self-hosted tool needs a server of its own, and the tag on your Pages site points at it. As of November 2026, Plausible Community Edition runs with Docker and recommends at least 2 GB of RAM, and Umami needs Node.js 20.19 or newer and a PostgreSQL database.
A short checklist
- Put the tag in the file every page shares, or on every page.
- On a theme, use its head slot, or copy the theme's whole head include.
- For Google Analytics, paste the current tag rather than relying on
google_analytics. - Keep local previews out with
jekyll.environment. - Check the page source, the network request and the real-time view.
- Check a post and a subfolder page, not just the home page.
Lomen is one of the script-tag tools this guide assumes. It has no GitHub-specific integration: its one <script> tag goes into the head include or onto every page as described above, with no API key, SDK or build step, and the docs show the tag. The script sets no cookies, IP addresses are never stored, and by default nothing is kept in the visitor's browser. It shows pageviews, visitors, top pages, sources, countries and devices, with a live view that's handy for the test visit. It doesn't do custom events, funnels or self-hosting, so if you need those, a larger tool is the better fit. It's free during the public beta.