Skip to content
Frameworks

Gatsby analytics with Reveata

2 min read · Updated · By the Reveata team

Short answerAdd the Reveata script to every page's head with Gatsby's onRenderBody API in gatsby-ssr. Gatsby's client-side navigation is tracked by the script itself, so there is no plugin or route listener to add.

Gatsby builds static pages and then behaves like a single-page app in the browser. Reveata follows both: the script is rendered into each page's head at build time and follows navigation through the History API afterwards.

What you get

  • Every page view, the first full load and every client-side navigation after it.
  • Traffic sources and campaigns for each visit, including AI assistants, search engines and tagged links (UTM and ref parameters).
  • Scroll depth, outbound clicks and time on page, recorded by the script by default.
  • Goals from attributes or code (custom goals).
  • Revenue attribution for payment links and checkouts started from your pages.

How to install it

Use onRenderBody in gatsby-ssr.js (or .tsx) to add the script to every page:

jsx
export const onRenderBody = ({ setHeadComponents }) => {
  setHeadComponents([
    <script
      key="reveata"
      defer
      data-website-id="ws_your_tracking_id"
      src="https://reveata.com/js/script.js"
    />,
  ]);
};

Rebuild and deploy. If you prefer to build the tag from options, @reveata/next/snippet exports scriptSrc and scriptAttributes. The API is described in Gatsby's gatsby-ssr reference (opens in a new tab).

Revenue from a Gatsby site

How you sell How the sale finds its visit
Stripe Payment Link or Buy Button on a page The script adds the visitor id on click (details)
A serverless function that creates a checkout Send window.reveata.metadata() and put the ids in the checkout metadata
Your own billing The Payments API

Serving the script from your own domain

A static Gatsby site can use its host's rewrites (Proxy through your own server) or the managed proxy, which needs one DNS record.

Frequently asked questions

Do I need a Gatsby plugin?

No. onRenderBody is part of Gatsby itself, and the script handles navigation on its own.

Can I keep some pages out of the numbers?

Yes. Add data-exclude-paths to the tag, for example /admin/*,/preview, or set exclusions for everyone in Settings → General → Exclusions (exclusions).

Will local development visits show up?

No. gatsby develop runs on localhost, which the script ignores by default.

See it with your own numbersReveata ties every visit and sale to the source that brought it. Add your website in a minute.
Get started
Was this page useful?
IntegrationStripe Payment Links analytics without codeThe Reveata script adds the visitor and session ids to every Stripe Payment Link, Buy Button and Pricing Table on your pages as a client_reference_id. Stripe stores it on the payment, and Reveata uses it to credit the sale to the visit, with no code to write.IntegrationAngular analytics with ReveataPaste the Reveata snippet before the closing head tag of src/index.html. ng build keeps it in the built page, server-side rendering included, and the Angular Router's History API navigation is counted automatically. HashLocationStrategy needs data-hash="true".IntegrationAstro analytics with revenue attributionPaste the Reveata snippet with is:inline into the Astro layout that renders the head of every page. Astro then leaves the tag as written, view transitions are tracked, and payment links or checkouts started from your pages are credited to the visit behind them.IntegrationDjango analytics with revenue attributionPaste the Reveata snippet before the closing head tag of the base template your Django templates extend. Every page is tracked, the Django admin is not, and two hidden form fields let your checkout view put the visitor id into the payment's metadata.IntegrationDocusaurus analytics for documentation sitesAdd the Reveata script to the scripts array in docusaurus.config.js, or build the entry with @reveata/next/snippet. Page changes inside the docs are tracked by the script, so every page a reader opens is counted.IntegrationExpress.js analytics with a first-party proxyPaste the Reveata snippet into the layout, static HTML or front-end index.html your Express app serves. Two Express routes can serve the script from your own domain with your proxy secret, and your checkout route can copy the visitor id into the checkout metadata.