Skip to main content
Fully automated. The CLI writes gatsby-browser.js with the onClientEntry hook.

Install with the CLI

Pick Gatsby when prompted.

Manual setup

1

Environment variable

.env.development and .env.production:
2

Wire the tracker into gatsby-browser.js

gatsby-browser.js:

Notes

  • 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).