How to add analytics to Jekyll

Jekyll sites usually build the <head> from an include. Add the tracker there and wrap it in a production check so jekyll serve stays out of your stats.

No cookies, no banner ~3 KB script About 2 minutes

Before you start

Create a free Cool Analytics account and add your site. You'll get a site ID — replace YOUR_SITE_ID in the code below with it. The dashboard shows the snippet with your ID already filled in.

Install on Jekyll

  1. 1Find the include that renders <head> — often _includes/head.html. The Minima theme also supports _includes/custom-head.html for exactly this purpose.
  2. 2If the file lives in a gem theme, create a file with the same name in your site's _includes folder to override it.
  3. 3Paste the snippet wrapped in the environment check, then build with JEKYLL_ENV=production.
_includes/custom-head.html
{% if jekyll.environment == "production" %}
<script defer src="https://coolanalytics.dev/hb.js" data-site="YOUR_SITE_ID"></script>
{% endif %}

Check that it works

Open your live site in a new tab, then open your Cool Analytics dashboard. Your visit appears on the live map within seconds — with the page you're on, where you came from and your browser.

Nothing showing up? Make sure you're looking at the published site (not a preview or editor), that an ad blocker isn't blocking the script, and that you're not testing on localhost.

Track signups, purchases and clicks

Pageviews, sources, countries and outbound link clicks are tracked automatically. For the moments that matter to you, send a custom event. Events named like a signup show up as signups, and events with an amount show up as revenue — on the live map and per traffic source.

custom events
// anywhere in your Jekyll site's browser code
window.hb?.track("signup");

// with an amount, it shows up as revenue
window.hb?.track("purchase", { amount: 49 });

Jekyll tips

  • GitHub Pages builds with JEKYLL_ENV=production automatically, so the snippet appears on your live site.
  • Overriding _includes/head.html replaces the theme's whole head — copy the original contents first, then add the snippet.

Want to keep your own visits out of the stats? Open your site once with #hb-ignore at the end of the URL. That browser is excluded until you visit with #hb-track.

Jekyll analytics FAQ

Does it work on GitHub Pages?+

Yes. It's a static script tag, which GitHub Pages serves like any other HTML.

Why don't I see visits from jekyll serve?+

jekyll serve runs in the development environment, so the snippet isn't rendered. That's intentional.

Can I put it in _layouts/default.html instead?+

Yes, if that layout contains <head>. Any file that ends up inside <head> on every page works.

See who's on your Jekyll site right now.

One line of code. No cookies. 7 days free.