Fully automated. The CLI writes gatsby-browser.js with the onClientEntry
hook.
Install with the CLI
Pick Gatsby when prompted.
Manual setup
Environment variable
.env.development and .env.production:Wire the tracker into gatsby-browser.js
gatsby-browser.js only runs in the browser, so itβs a safe place to
instantiate the tracker at module scope.
onClientEntry fires once, right after Gatsby boots β before any routes
render β which means the tracker catches the very first page view.
- The
GATSBY_ prefix makes the variable available in both process.env
(server build time) and import.meta.env (not used here).