Install Foresite on Gatsby
Add the Tracking Script to every page's <head> from gatsby-ssr.js (or gatsby-ssr.tsx) at the root of your project:
const React = require('react')
exports.onRenderBody = ({ setHeadComponents }) => {
setHeadComponents([
<script key="foresite" defer src="https://t.foresite.dev/s/YOUR_SITE_ID.js" />,
])
}
Use the address from your own Foresite line (Settings → Install), then rebuild and deploy. Foresite counts each page change as a pageview automatically.
Visits to localhost aren't counted, so test on your deployed site: the Installation Check in Settings → Install turns green with the first pageview.