Install on Docusaurus
Docusaurus loads external scripts listed in the scripts field of its configuration file. You add the script there once and it’s included on every page.
Copy the code
In the portal, open Settings → Install and choose Docusaurus. Copy the code shown. It looks like this, with your own site key:
scripts: [
{ src: 'https://analytics.writechoice.io/s/YOUR_SITE_KEY.js', defer: true },
],Add it to the configuration
Open docusaurus.config.js (or docusaurus.config.ts) at the root of your project and add the entry to the configuration object:
export default {
title: 'My docs',
url: 'https://docs.example.com',
// ...
scripts: [
{ src: 'https://analytics.writechoice.io/s/YOUR_SITE_KEY.js', defer: true },
],
}If the configuration already has a scripts list, add the new entry to that list. Don’t create a second scripts field.
Build and deploy
Build and deploy the site as usual, then check that it works.
Notes
-
Docusaurus is a single-page application: moving between pages doesn’t reload the browser. The script records a pageview on each navigation, so you don’t need a plugin or extra code.
-
The script also loads on your local development server (
docusaurus start), so those visits are counted too, with the hostnamelocalhost. To keep them out, add the script only in production:scripts: process.env.NODE_ENV === 'production' ? [{ src: 'https://analytics.writechoice.io/s/YOUR_SITE_KEY.js', defer: true }] : [], -
To add a tag, put
'data-tag': 'v2'in the same entry, next todefer: true.
Heatmap preview
Docusaurus itself doesn’t send X-Frame-Options or frame-ancestors: those headers come from where the site is hosted. If your host or proxy adds them, the Heatmaps tab draws the clicks on a blank background. See Heatmap preview.
Site search
- DocSearch (the Algolia search that Docusaurus supports out of the box) is recorded automatically: the final search, the number of results shown, and the result the reader opens.
- With another search plugin (for example a local search plugin), call
wca.searchfrom the plugin’s search code. See Site search.