Add cookie-free, GDPR-compliant analytics to your Gatsby site in under 2 minutes. No consent banner required. Works with Gatsby v4 and v5 for both static sites and SSR.
No credit card required and setup in minutes
Replace YOUR_SITE_ID with your Beam site ID from the dashboard.
// gatsby-browser.js (create if it doesn't exist)
export const onClientEntry = () => {
const script = document.createElement('script')
script.defer = true
script.src = 'https://beam-privacy.com/js/beam.js'
script.setAttribute('data-site-id', 'YOUR_SITE_ID')
document.head.appendChild(script)
}
Gatsby's onClientEntry lifecycle fires once when the browser runtime loads. Injecting the script here ensures Beam initialises before the first route renders.
// gatsby-browser.js (add below onClientEntry)
export const onRouteUpdate = ({ location }) => {
// Gatsby handles client-side navigation without full page reloads.
// onRouteUpdate fires after every route transition.
if (typeof window !== 'undefined' && window.beam) {
window.beam.track('pageview', { path: location.pathname })
}
}
Without this hook, Beam only captures the initial page load. onRouteUpdate fires on every Gatsby client-side navigation, keeping your Top Pages report accurate across all routes.
Use this checklist after publish so you know tracking is actually live in production.
Beam is cookie-free by design — no consent UI to build, no GDPR overhead for your Gatsby site.
Beam's tracking script adds no npm packages and is lighter than most Gatsby plugins.
The onRouteUpdate hook captures every Gatsby client-side navigation so your Top Pages report is complete.
No PII, no fingerprinting, no ad-tech — just page-level metrics that work without a consent banner.
Start free, validate your first pageview, and then scale when traffic grows.