PostHog

Add PostHog analytics tracking and feature flags to your Convex backend functions with server-side event capture and A/B testing.

Installation

npm install @posthog/convex

About PostHog

The PostHog Convex package integrates PostHog analytics and feature flags directly into your Convex backend. It enables event tracking, product analytics, and feature flag evaluation from within Convex functions without requiring client-side instrumentation for backend events. This is the official PostHog library for Convex, maintained by the PostHog team.

Benefits

Use cases

how to track events in Convex mutations

Use @posthog/convex to capture analytics events directly from your Convex mutations and actions. The component provides server-side PostHog integration that lets you track user actions, conversions, and custom events without relying on client-side tracking.

feature flags in Convex backend functions

Implement feature flags in your Convex functions using @posthog/convex to control backend behavior. You can gate database operations, API calls, and business logic based on PostHog feature flag configurations.

PostHog analytics with Convex actions

Track third-party API calls and external service interactions by integrating PostHog analytics into your Convex actions. This enables comprehensive product analytics across your entire backend workflow.

server-side A/B testing with Convex

Run server-side A/B tests in your Convex functions using PostHog feature flags. Test different database query strategies, business logic variations, or API integrations based on user segments.

Frequently asked questions

Does @posthog/convex work with both mutations and actions?

@posthog/convex can be used in both Convex mutations and actions to track events and check feature flags. Since it integrates with PostHog's server-side APIs, it works in any Convex function context.

How does PostHog integration affect Convex function performance?

The @posthog/convex component makes HTTP requests to PostHog's APIs, which adds network latency to your functions. Consider using it in actions rather than mutations for time-sensitive operations, or implement async event tracking patterns.

Can I use PostHog feature flags to control database queries in Convex?

Yes, @posthog/convex allows you to check feature flags within your Convex functions to conditionally execute different database queries or business logic. This enables server-side experimentation with your data layer.

Do I need PostHog client-side tracking if I use this component?

@posthog/convex provides server-side tracking only and complements client-side PostHog integration. You typically use both together for comprehensive analytics covering frontend interactions and backend operations.

Links