PostHog plugin for Docusaurus
Easily track and improve your Docusaurus site with PostHog. See our docs on this plugin for more information.
Installing the plugin
1npm install posthog-docusaurus --save
or
1yarn add posthog-docusaurus
Configuring the plugin
1// docusaurus.config.js
2module.exports = {
3 plugins: [
4 [
5 'posthog-docusaurus',
6 {
7 apiKey: '<ph_project_api_key>',
8 appUrl: '<ph_client_api_host>', // optional, defaults to "https://us.i.posthog.com"
9 enableInDevelopment: false, // optional
10 },
11 ],
12 ],
13}
**Note:**You can pass additional PostHog config options to the plugin, but they are passed through
JSON.stringify(), so functions (such assanitize_properties) are not supported.
Using the plugin
Once running, this autocaptures pageviews, events, and session replay (if enabled) and enables usage of other PostHog features like surveys.
Docusaurus compatibility
Verified with Docusaurus 3.10.2 and React 19.3.1 using the sample and browser tests.
The SDK captures the initial pageview, and Docusaurus's route hook captures subsequent pathname changes. The hook skips the initial load to avoid a duplicate pageview. SDK defaults and explicit options remain unchanged, preserving default pageleave capture and the landing pageview after consent is granted.