How to add analytics to a Ghost blog with Code injection
Since Ghost 6.0, Ghost can count visitors on its own, without cookies, on Ghost(Pro) from the Publisher plan up and on self-hosted sites set up for it. If you want a second tool anyway, its tag goes in Code injection's site header, not in a post and not in the theme, and it stays there through every theme update.
In this article
Ghost has a setting made for this. Code injection puts a snippet in the head of every page on your site, from the home page to each post and tag page, without touching the theme. Since Ghost 6.0, Ghost can also count visitors on its own (on Ghost(Pro), from the Publisher plan up), so the first question is whether you need a second tool at all.
This guide covers both: what Ghost already counts, where a script tag goes if you still want one, and how to check that it works. The steps work for any analytics tool that installs with a script tag. The Ghost details come from its help pages and theme documentation, as of November 2026.
What Ghost already counts
Ghost 6.0 added web analytics to Ghost Admin. According to Ghost's help page on it, it shows:
- Unique visitors, counted within 24-hour windows, and total views.
- Top posts and pages, top sources and visitors by country, with a filter for public visitors, free members and paid members.
- Filters you can combine, including UTM parameters, which Ghost added in January 2026.
Ghost says its web analytics doesn't use cookies or any other persistent browser storage to recognise visitors. Next to it sits what Ghost has always tracked as a membership platform: free and paid members, recurring revenue from paid subscriptions, and newsletter open and click rates.
Whether you have it depends on where the site runs. On Ghost(Pro), Ghost's 6.0 announcement says the new analytics come with the Publisher plan and above, and the pricing page marks advanced native analytics as not included on Starter. Where it's included, Ghost's Tinybird page says it's on by default with no setup, and it can be switched off under Settings → Analytics. A self-hosted site needs Ghost 6.0 or later, installed with Ghost's Docker method, and a Tinybird account, as the same page explains. Either way, the figures start with Ghost 6.0. There's nothing from before it.
When a second tool is worth adding
A separate tool earns its place when it answers a question Ghost's doesn't. The usual ones:
Starter, or self-hosted without Tinybird
Ghost(Pro)'s Starter plan doesn't include Ghost's web traffic analytics, and on a self-hosted site they need the Docker install plus a Tinybird account. Either way, a script tag in Code injection is the usual way to count visitors, on Starter only if your plan has Code injection (see below).
Several sites in one place
If the blog is one of several sites, on Ghost and elsewhere, one dashboard for all of them is easier than a different report on each platform.
A team that lives in Google Analytics
Google's tag goes in through Code injection like any other. It sets first-party cookies such as _ga, though, which brings back the question of a cookie banner.
Visits from AI assistants as one group
ChatGPT, Claude, Perplexity and similar assistants arrive as referrers, and ChatGPT also tags its links with utm_source=chatgpt.com. The guide to tracking ChatGPT traffic shows how to find them in any tool.
If none of these applies, Ghost's own analytics is probably enough, and you can stop here.
Check your plan before you paste
Code injection has been part of Ghost since version 0.6, so a self-hosted site has it. On Ghost(Pro), check your plan first. As of November 2026, the pricing page lists third-party analytics services such as Google Analytics, Plausible and Fathom as “Basic” on the Starter plan and as included on Publisher and above, without saying what Basic leaves out. Custom themes aren't available on Starter, which matters for the theme route further down. If you can't find Code injection in your settings, ask Ghost which plan you need.
Add the tag with Code injection
Sign up for the tool you picked, add your site and copy the snippet it gives you, usually a single <script> tag 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's dashboard rather than from an email or a document, where straight quotes can turn into curly ones and quietly break the tag. Then, as Ghost's help pages describe it:
- Sign in to Ghost Admin, usually at
yoursite.com/ghost. - Open Settings and find Code injection in the Advanced section. Older tutorials show it directly under Settings.
- Paste the snippet into Site header. Ghost puts Site header code inside the page's
<head>and Site footer code just before</body>. Use the header unless your tool's instructions say otherwise. - Save.
Why not paste it into the theme
Ghost themes are Handlebars templates, and a tag pasted into the theme's default.hbs works too. It's rarely the better choice:
- It needs a theme upload. An edited theme goes back in as a theme upload, and Ghost(Pro)'s Starter plan doesn't take custom themes.
- It doesn't survive the theme. Uploading a new version of the theme replaces its files, and switching themes leaves your edit behind in the old one. Either way the tag is gone, with no warning.
- Code injection lives in Ghost's settings, not in the theme, so it stays when the theme changes.
The one thing Code injection needs from the theme is the {{ghost_head}} helper, which prints the site header code along with Ghost's meta tags and structured data. Ghost's docs for the two helpers put it just before </head> in default.hbs, with {{ghost_foot}} just before </body> for the footer code, and the theme structure docs list both among the helpers every theme needs. Official themes have both. A custom theme that left one out loses that half of Code injection.
Code injection lives in Ghost's settings, not in the theme. That's why it outlasts every theme update.
Check that it works
Don't wait a day to find out the tag is broken. Check right after you save:
- Open the blog in a private window, signed out of Ghost Admin, with any ad or tracker blocker turned off for the test.
- View the page source and search for the script's address. It should be in the
<head>. - Open the developer tools, go to the Network tab and reload. Filter by your tool's domain. You should see the script load, and usually a second request that sends the pageview.
- Open the tool's live or real-time view, if it has one, and look for your visit.
- Repeat on a post, a tag page and a static page, not only the home page.
If the numbers look wrong
- Not in the page source. The change wasn't saved, or the tag went into a post's own Code injection field instead of the site-wide one.
- In the source, but nothing loads. A blocker stopped it, or the tag itself is broken: curly quotes, a missing
</script>, or a Content Security Policy that doesn't list the tool's domain, if your server sends one. - The script loads, but no visits appear. The address in the tool doesn't match the one readers use. Check
wwwagainst nowww, and your own domain against the address Ghost(Pro) gave the site. - Everything counted twice. The tag is in Site header and in a post's field, or in Code injection and in the theme. Remove one.
- Ghost and the other tool disagree. They will. Ghost counts unique visitors within 24-hour windows, a tool with a cookie can count one person once across weeks, and blockers stop some tools and not others. Check that both rise and fall on the same days. The rest is in why no two analytics tools agree on your traffic.
A cookie-free script, but is the blog?
A cookie-free tool doesn't add analytics cookies, and Ghost's own web analytics doesn't use any either. The rest of the blog still can. Ghost keeps signed-in members logged in with a cookie called ghost-members-ssr, and embeds, fonts and other scripts may set their own.
To see what your blog actually stores, open the developer tools, clear the site data, browse a few pages and sign in as a member. Whatever appears under Cookies and Local storage came from somewhere. Whether you can do without a banner depends on that whole list, and what it takes to run a website without a cookie banner goes through it.
The short version
- Look at Ghost's own analytics first, if your plan includes it.
- Add a tool only for a question Ghost can't answer.
- On Ghost(Pro), check that your plan has Code injection.
- Settings → Advanced → Code injection → Site header, then save.
- Not in a post's own field, and not in the theme as well.
- Check the source, the Network tab and the live view on several kinds of page.
Lomen is one of the tools you could add this way, as one script tag in Ghost's Site header, with no API key, package or build step. A second copy of the tag for the same site does nothing, so a stray copy in a post's own field can't double the numbers, and pageviews only count from the domain you added and its subdomains. It sets no cookies, never stores IP addresses and by default keeps nothing in the visitor's browser. It groups visits from nine AI assistants by referrer and utm_source, and if your paid memberships run through your own Stripe account, it can read that revenue and show it on the same chart as visitors, not split by post. It has no custom events or funnels, and it doesn't see members or newsletters, which Ghost covers. Lomen is free during the public beta.