Install Foresite on Docusaurus
With the Foresite plugin
Install docusaurus-plugin-foresite:
npm install docusaurus-plugin-foresite
Then add it to docusaurus.config.js (or .ts) with your Site ID: the s_… part of your Foresite line, before .js (Settings → Install):
export default {
// ...the rest of your config
plugins: [['docusaurus-plugin-foresite', { siteId: 'YOUR_SITE_ID' }]],
}
If you set up a custom domain, add it as host: 'stats.example.com'. The plugin adds the script to production builds only, so docusaurus start sends nothing.
Without a plugin
Docusaurus adds the scripts listed in its config to every page's <head>:
export default {
// ...the rest of your config
scripts: [{ src: 'https://t.foresite.dev/s/YOUR_SITE_ID.js', defer: true }],
}
Use the address from your own Foresite line. Keep defer: true, so the script doesn't hold up your pages.
Check it's working
Build and deploy. Docusaurus switches pages without reloading; Foresite counts each page change as a pageview automatically. Visits to localhost aren't counted, so test on your published docs: the Installation Check in Settings → Install turns green with the first pageview.