Analytics Setup
Setting Up PostHog Analytics (Optional)
If you want to enable analytics for your documentation site, follow these steps:
1. Get a PostHog API Key
- Sign up for a free account at PostHog
- Create a new project
- Copy your project API key from the project settings
2. Add Environment Variable
- Open the
.env
file in the root directory - Add your PostHog API key:
# Add this line with your actual API key:
POSTHOG_API_KEY=your_posthog_project_key
3. Add PostHog Configuration
- Open
docusaurus.config.ts
- Find the
plugins: [
array around line 88 - Add the PostHog plugin configuration:
plugins: [
// ... existing plugins ...
// Add PostHog analytics
[
'posthog-docusaurus',
{
id: 'posthog',
apiKey: process.env.POSTHOG_API_KEY,
appUrl: 'https://us.i.posthog.com', // optional
enableInDevelopment: false, // optional
},
],
],
4. Install PostHog Package
If not already installed, add the PostHog Docusaurus plugin:
npm install posthog-docusaurus
5. Verify Setup
After configuration:
- Build and serve your site:
npm run build && npm run serve
- Check the browser developer tools for any errors
- Verify analytics are being recorded in your PostHog dashboard
Configuration Options
Available PostHog configuration options:
- apiKey: Your PostHog project API key (required)
- appUrl: PostHog instance URL (defaults to
https://us.i.posthog.com
) - enableInDevelopment: Set to
false
to disable analytics in development mode
Privacy Considerations
- PostHog respects user privacy preferences
- Consider adding a privacy policy if collecting analytics
- Users can opt out using browser settings or privacy extensions
No Analytics Needed?
The site works perfectly without any analytics configuration. Simply skip this setup if you don't need usage tracking.