• Blog
  • Documentation
  • Courses
  • Changelog
  • AI Starters
  • UI Kit
  • FAQ
  • Supamode
    New
  • Pricing

Launch your next SaaS in record time with Makerkit, a React SaaS Boilerplate for Next.js and Supabase.

Makerkit is a product of Makerkit Pte Ltd (registered in the Republic of Singapore)Company Registration No: 202407149CFor support or inquiries, please contact us

About
  • FAQ
  • Contact
  • Verify your Discord
  • Consultation
  • Open Source
  • Become an Affiliate
Product
  • Documentation
  • Blog
  • Changelog
  • UI Blocks
  • Figma UI Kit
  • AI SaaS Starters
License
  • Activate License
  • Upgrade License
  • Invite Member
Legal
  • Terms of License
    • How Monitoring works
    • Sentry
    • Signoz
    • Posthog
    • Baselime

Configuring PostHog monitoring in your Next.js Supabase SaaS kit

Learn how to configure Posthog Monitoring in your Next.js Supabase SaaS kit

PostHog is released as a plugin, so it's not in the core of the SaaS kit by default.

To install Posthog's plugin, you have 2 options:

  1. Use the Makerkit CLI
  2. Clone the plugin repository and add it manually by coping the files in the plugins folder

Using the Makerkit CLI

Run the following command:

npx @makerkit/cli@latest plugins install

And choose the posthog option.

NB: skip this step if you already have the plugin installed (for example, the Posthog plugin for Analytics, they're the same).

Registering the Monitoring Service

At packages/monitoring/api/src/get-monitoring-provider.ts, add posthog to the list of providers:

packages/monitoring/api/src/get-monitoring-provider.ts

export const MONITORING_PROVIDER = z
.enum(['sentry', 'posthog', '']) // <-- Add posthog here
.optional()
.transform((value) => value || undefined);

At packages/monitoring/api/src/services/get-server-monitoring-service.ts, register the Posthog service:

packages/monitoring/api/src/services/get-server-monitoring-service.ts

// Register the 'posthog' monitoring service
serverMonitoringRegistry.register('posthog', async () => {
const { PostHogServerMonitoringService } = await import(
'@kit/posthog/monitoring/server'
);
return new PostHogServerMonitoringService();
});

At packages/monitoring/api/src/components/provider.tsx, register the Posthog Provider:

packages/monitoring/api/src/components/provider.tsx

// Register the PostHog provider
monitoringProviderRegistry.register('posthog', async () => {
const { PostHogProvider } = await import('@kit/posthog/provider');
return {
default: function PostHogProviderWrapper({
children,
}: React.PropsWithChildren) {
return <PostHogProvider>{children}</PostHogProvider>;
},
};
});

API Keys

You can skip this step if you already have the Posthog API key. Otherwise, please copy the API key from Posthog and add it to the environment variables:

Please follow the Posthog Analytics plugin configuration to add the Posthog API Keys to your Makerkit app.

That's it!

On this page
  1. Using the Makerkit CLI
    1. Registering the Monitoring Service
      1. API Keys