Install Statsdot on Gatsby
Updated October 18, 2026
Add the script to every page in gatsby-ssr.js at the root of your project:
import * as React from 'react';
export const onRenderBody = ({ setHeadComponents }) => {
setHeadComponents([
<script
key="statsdot"
defer
data-domain="yoursite.com"
src="https://statsdot.com/js/script.js"
/>,
]);
};
Restart gatsby develop after creating the file. Gatsby's router changes pages with the browser's history API, which Statsdot listens to, so every page counts. The script does nothing on localhost.
Track events with data-statsdot-event="Signup" on a button, link or form, or window.statsdot?.track('Signup') in a component. See Events and goals.