# Install on Docusaurus

> For the complete documentation index, see [llms.txt](https://analytics.writechoice.io/docs/llms.txt).

Add the snippet to the scripts list of docusaurus.config.js.

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.

**1. 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:

```js
scripts: [
  { src: 'https://analytics.writechoice.io/s/YOUR_SITE_KEY.js', defer: true },
],
```

**2. 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:

```js
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.

**3. Build and deploy**

Build and deploy the site as usual, then [check that it works](https://analytics.writechoice.io/docs/install/#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 hostname `localhost`. To keep them out, add the script only in production:

  ```js
  scripts:
    process.env.NODE_ENV === 'production'
      ? [{ src: 'https://analytics.writechoice.io/s/YOUR_SITE_KEY.js', defer: true }]
      : [],
  ```

- To add a [tag](https://analytics.writechoice.io/docs/install/events-and-tags/#tags), put `'data-tag': 'v2'` in the same entry, next to `defer: 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](https://analytics.writechoice.io/docs/install/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.search` from the plugin's search code. See [Site search](https://analytics.writechoice.io/docs/install/events-and-tags/#site-search).