Skip to main content
Back to Guides
Setup2 min read

Jekyll Cookie Consent: Add GDPR Compliance to Your GitHub Pages Site

How to add a cookie consent banner to a Jekyll site hosted on GitHub Pages. Covers _includes setup, blocking analytics scripts, and working within Jekyll's static-site constraints.

Jekyll and cookies: what you need to know

Jekyll generates static HTML. No server, no database, no session cookies by default. But the moment you add Google Analytics, a comments widget, an embedded YouTube video, or any third-party JavaScript, your site sets cookies. And if EU visitors land on your site, you need their consent first.

GitHub Pages makes this trickier because you can't run server-side code. Everything has to work client-side. The good news: a consent management script runs entirely in the browser, so it works perfectly on GitHub Pages.

Quick setup

Add the CookieBeam script to your Jekyll site's head include. Open _includes/head.html (or _includes/head-custom.html if you're using a remote theme) and add this before the closing </head>:

<script src="https://cdn.cookiebeam.com/banner/YOUR_BANNER_ID/default/loader.js" async></script>

Replace YOUR_BANNER_ID with your banner ID from the CookieBeam dashboard. That's it. Every page that uses this include now has cookie consent.

Blocking Google Analytics until consent

If you're using Jekyll's built-in Google Analytics support (the google_analytics config key), the tracking script loads unconditionally. To make it consent-aware:

Option 1: Let CookieBeam auto-block it

CookieBeam's auto-blocking detects the Google Analytics script and blocks it until the visitor consents. If you load GA via a standard script tag, this works automatically.

Option 2: Conditional include with Liquid

Create a custom analytics include that only outputs the script tag when consent is given. Since Jekyll is static, you can't check consent at build time, but you can use CookieBeam's JavaScript API to conditionally load scripts at runtime.

GitHub Pages and custom domains

If your Jekyll site uses a custom domain (not username.github.io), make sure the domain is listed in your CookieBeam banner's allowed domains. The consent banner validates the domain it's running on to prevent unauthorized use of your banner ID.
Does this work with GitHub Pages?
Yes. CookieBeam is a client-side script that runs entirely in the browser. It doesn't need a server, so it works on GitHub Pages, Netlify, Vercel, or any static host.
Will it slow down my Jekyll site?
The CookieBeam script is under 15KB gzipped and loads asynchronously. It won't block your page from rendering. Jekyll sites are already fast because they're static HTML; the consent script adds minimal overhead.
I use a Jekyll theme that I can't modify. Can I still add consent?
Most Jekyll themes support _includes/head-custom.html for adding custom scripts without modifying the theme. If yours doesn't, you can add the script via a Jekyll plugin or directly in your layout file.
Jekyll Cookie Consent: GDPR Banner for GitHub Pages | CookieBeam