Integrations Gatsby

Cookie-Free Analytics for Gatsby

Gatsby static sites benefit from analytics that matches their performance focus. GhostlyX loads asynchronously, tracks page changes via the Gatsby browser API, and adds under 1.5 kB.

Get started free Free plan available · Setup in 5 minutes

Installation guide

1

Add the script in gatsby-ssr.js

Create or open gatsby-ssr.js in the root of your project and use the onRenderBody API to inject the script.

Code
import React from 'react'

export const onRenderBody = ({ setHeadComponents }) => {
    setHeadComponents([
        <script
            key="ghostlyx"
            defer
            src="https://cdn.ghostlyx.com/gx.js"
            data-site-id="YOUR_SITE_ID"
        />,
    ])
}
2

Track client-side navigation in gatsby-browser.js

GhostlyX detects SPA navigations automatically. No additional code is required in gatsby-browser.js to track route changes.

Why Gatsby users choose GhostlyX

Gatsby sites are often high-traffic content sites or SaaS marketing pages that depend on fast load times and good Core Web Vitals scores. Adding a heavy analytics bundle can hurt Lighthouse scores. GhostlyX's under-1.5 kB deferred script has a negligible impact on performance metrics.

Cookie-free tracking

No consent banner required under GDPR or PECR

Under 1.5 kB script

Negligible impact on page speed and Core Web Vitals

Real-time dashboard

See visitors as they arrive, updated every few seconds

Free plan available

Start tracking without a credit card

Replacing Google Analytics on Gatsby?

See how GhostlyX compares feature by feature, including script size, GDPR compliance, and pricing.

GhostlyX vs Google Analytics

Ready to add GhostlyX to Gatsby?

Free plan available. Setup takes 5 minutes. No cookie consent banner required.

Get started free