Blog › Jekyll

Setting up Google AdSense and ads.txt on Jekyll Chirpy

Integrate Google AdSense into a Jekyll Chirpy blog using metadata-hook without modifying theme files, configure ads.txt, and prepare for site approval.

Setting up Google AdSense and ads.txt on Jekyll Chirpy

Adding Google AdSense to a static Jekyll blog takes only a few lines of configuration, but getting approved—and keeping Chirpy theme upgrades conflict-free—requires a bit of care. This post walks through injecting the AdSense script via _includes/metadata-hook.html, setting up ads.txt, and preparing a technical blog to pass review on the first try.

Tested with GitHub Pages, Jekyll 4.4, and jekyll-theme-chirpy on a custom domain (namju.kim).

flowchart TD
    A["Register custom domain<br/>(namju.kim)"] --> B["Inject script in<br/>metadata-hook.html"]
    A --> C["Add ads.txt at<br/>repository root"]
    B --> D["Deploy via GitHub Actions"]
    C --> D
    D --> E["Googlebot crawl & review"]
    E --> F["Site status: Ready"]

Prerequisites

Before submitting your blog for AdSense review, make sure you have:

  • A Google account with access to the Google AdSense console.
  • A custom root domain (for example, https://namju.kim) rather than a *.github.io subdomain.
  • A deployed Jekyll Chirpy blog hosted on GitHub Pages via GitHub Actions.
  • Original technical content: At least 10 substantial, original posts (not thin bookmark notes or raw code dumps).

When not to add AdSense

If your blog gets under a few hundred monthly visits, or if it serves as a strict portfolio/product docs site where any third-party ad script hurts perceived polish, skip AdSense. Third-party ad scripts add network requests and layout overhead that aren’t worth pennies per month unless you actually want to offset domain and hosting costs on a growing technical blog.


Step 1: Apply with a custom domain instead of github.io

When adding a site in Google AdSense, use your own apex domain (namju.kim) rather than <username>.github.io.

Because github.io is on the Public Suffix List and shared across millions of repositories, AdSense often rejects subdomain applications or runs into root-domain ownership verification issues. With a personal root domain, you control the root ads.txt path, own the DNS zone, and keep your AdSense approval intact even if you migrate hosting away from GitHub Pages later. (If you haven’t set up a custom domain yet, see Connecting a custom domain and HTTPS to GitHub Pages.)

Log in to the Google AdSense console, go to Sites → New site, and enter your domain. AdSense will generate an asynchronous <script> tag containing your publisher ID (for example, ca-pub-9883771255224638).


Step 2: Inject the AdSense script via metadata-hook.html

Google requires the AdSense verification script inside <head> on every page. A common mistake with Chirpy is copying _layouts/default.html or _includes/head.html from the theme gem into your repository to paste the script in. Once you override head.html, future Chirpy gem upgrades stop applying cleanly to <head>.

Chirpy solves this with an official extension file: _includes/metadata-hook.html. Anything in this file gets injected right before </head> at build time without touching theme internals.

Add the AdSense snippet to _includes/metadata-hook.html:

1
2
3
4
5
6
7
8
9
<!-- _includes/metadata-hook.html -->
<!-- Custom metadata injected via Chirpy's official hook (included at the end of <head>) -->

<!-- Google AdSense -->
<script
  async
  src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-9883771255224638"
  crossorigin="anonymous"
></script>

Keeping the async attribute prevents the AdSense loader from blocking HTML parsing, which helps protect initial render time and Core Web Vitals.

Push the change and let GitHub Actions deploy. Once live, view the page source (Ctrl+U or Cmd+Option+U) or run curl to confirm the script rendered inside <head>:

1
curl -sL https://namju.kim | grep "adsbygoogle.js"

You should see the <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-..." ...> line in the output.


Step 3: Add ads.txt at the repository root

One of the most frequent post-approval warnings in AdSense is “Earnings at risk – You need to fix some ads.txt file issues.”

ads.txt (Authorized Digital Sellers) is an IAB standard file placed at the root of your domain declaring which ad networks are authorized to sell your inventory. Without it, demand-side platforms may refuse to bid on your impressions or drop your fill rate.

Jekyll copies plain files in the repository root straight into _site/ during builds. Create a file named ads.txt at the root of your repository with a single line:

1
google.com, pub-9883771255224638, DIRECT, f08c47fec0942fa0

Replace pub-9883771255224638 with your own publisher ID. Keep f08c47fec0942fa0 as-is—it is Google’s fixed TAG Certification Authority ID.

After deploying, open https://<your-domain>/ads.txt in your browser (or check it with curl -I) to verify it returns HTTP 200 and serves the exact line above.

Browser view of namju.kim/ads.txt displaying the authorized seller record Figure 1. Verifying that /ads.txt is publicly accessible at the domain root.


Step 4: Preparing a static blog to pass AdSense review

Google AdSense review is notoriously strict for static developer blogs. Most rejections cite “Low value content” or “Site behavior: navigation.” Before clicking Request review, I checked four things across the site:

  1. At least 10 complete technical posts: Every published post should be a self-contained troubleshooting note, tutorial, or architecture deep dive—not a 200-word bookmark list or unannotated code paste. Keep rough drafts in _drafts/ so they stay out of the production build.
  2. No empty or thin categories: If your navigation sidebar exposes categories with zero or one stub post, reviewers can flag the site as unfinished. Only expose categories that have real articles behind them.
  3. Zero broken links (404s): Run htmlproofer during CI or locally to confirm there are no dead internal links, missing images, or broken navigation targets that trip up Googlebot.
  4. Clear About page and author identity: Fill out your /about/ page with who you are, what stack you write about, and links to your GitHub profile and contact email. Clear site ownership and purpose matter during review.

Verification: “Ready” status and ad rendering

Once the script and ads.txt were live, I submitted the site via Request review in the AdSense dashboard.

Review times range from a couple of business days to two weeks. With the site checks above in place, approval came through in about three days, and the domain status in Sites switched to green Ready.

Google AdSense Sites dashboard showing namju.kim in Ready status Figure 2. Google AdSense Sites panel confirming namju.kim is approved and Ready.

With Auto ads enabled, AdSense starts placing display and in-article slots automatically across posts:

Preview of an in-article ad unit rendered inside a blog post Figure 3. In-article ad unit rendered between sections of a technical post.


Caveats: protecting code readability

Once ads start serving, it’s tempting to turn on every Auto ads format to maximize impressions. For an engineering blog, that backfires quickly.

Most visitors arrive from a search engine trying to debug a production error or copy a config snippet. Full-screen vignette overlays and oversized mobile anchor banners get in the way of code blocks and drive readers straight back to search results.

Practical ad layout guardrails

  • Disable or sharply limit vignette (full-screen) ads so clicking between posts doesn’t trigger modal popups.
  • Keep mobile anchor ads off or minimal to preserve vertical space for code blocks on narrow screens.
  • Prefer in-article and bottom-of-post display units that sit cleanly between sections without shifting layout mid-read.

If you later find Auto ads placing slots in awkward spots—like right above a code fence or breaking Chirpy’s sidebar—you can switch to manual placements. I documented that layout approach in Customizing manual AdSense placement for Chirpy sidebar and mobile.

Setup checklist

  • Custom apex domain registered in AdSense (not *.github.io)
  • adsbygoogle.js snippet added to _includes/metadata-hook.html with async
  • ads.txt committed at repository root and verified at https://<your-domain>/ads.txt
  • At least 10 original posts published, zero 404s, and About page completed
  • Aggressive Auto ad formats (vignettes, heavy mobile anchors) disabled after approval
This post is licensed under CC BY 4.0 by the author.