Gatsby analytics
Add analytics to Gatsby with @nextanalytica/tag: install, events, consent and AI crawlers, counted without cookies until a yes and read by your agent.
Updated
To add analytics to a Gatsby app, install @nextanalytica/tag and add it once in gatsby-config.js. It counts visits and client-side page views, where they came from and what they led to, without cookies until a visitor agrees, and your agent (Claude, Cursor, Codex) reads the numbers over MCP.
How do you add nextanalytica to Gatsby?
Install the package:
pnpm add @nextanalytica/tag@1Then add it once, in gatsby-config.js:
module.exports = {
plugins: [{ resolve: '@nextanalytica/tag/gatsby', options: { project: 'na_…' } }],
}na_… is your project's key, from Site. The package adds the same tag line and counts client-side navigation, so every route change is a page view.
How do you send events?
Send the actions that matter from your code:
import { track } from '@nextanalytica/tag'
track('signup_completed', { plan: 'team' })Calls made before the tag has loaded wait and go in order. Mark the events that count as conversions, and your agent reads conversion rates by channel and page. See Custom events.
How does consent work?
The tag counts without cookies until the visitor answers your banner, so people who never click it are still counted. Pass the answer on every page:
import { consent } from '@nextanalytica/tag'
consent(true) // or falseA yes starts a first-party id; a no stops the tag sending and removes what it kept. More in Cookieless counting and consent.
How do you record orders?
Where the order is confirmed:
import { order } from '@nextanalytica/tag'
order({ ref: 'A-10492', value: 129.9, currency: 'EUR' })ref makes a repeated call count once. Orders your server confirms can go from the server instead: see Revenue tracking.
Can you see AI crawlers?
AI crawlers such as GPTBot and ChatGPT-User never run the tag. A sender on your server passes their hits, so your agent sees which pages AI assistants read and which visits followed.
- Gatsby behind Cloudflare: a Cloudflare Worker in front of the site passes the hits.
See AI crawlers for the setup, and AI traffic analytics for what you get.
How do you check it works?
Ask your agent "Check my nextanalytica setup": check_setup lists the hosts that sent something and what to do next. Then ask:
- "How many visits did we have this week, and from where?"
- "Which pages do people land on from Google and from ChatGPT?"
- "Which channel brings sign-ups?"