Repository navigation
feat(analytics): add PostHog analytics package - #16
Merged
Merged
Conversation
- Add @workspace/analytics package powered by PostHog to base template - Expose dual ./client (posthog-js) and ./server (posthog-node) entrypoints - Implement client and server event tracking, user identification, and feature flag helpers - Gracefully no-op in local development when PostHog keys are unset or use template placeholders - Validate PostHog environment variables with @t3-oss/env-nextjs and Zod - Add unit test suite for server and client analytics and feature flag evaluation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced Nov 24, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Applications built on Stackbase need product analytics, user identification, and feature flag evaluation across both the Next.js frontend (
apps/web) and the backend API (apps/api). Right now developers have to wireposthog-js,posthog-node, environment validation, and local development no-op guards manually inside each app.Change
Adds
@workspace/analytics(templates/base/packages/analytics) as a dual client and server analytics package powered by PostHog:src/server.ts,@workspace/analytics/server):getPostHogServer,captureServerEvent,identifyServerUser,isFeatureEnabled,getFeatureFlag(with fail-opendefaultValuefallbacks on network errors), andshutdownAnalyticspowered byposthog-node.src/client.ts,@workspace/analytics/client):initPostHogClient,captureClientEvent,identifyClientUser,resetClientAnalytics,isClientFeatureEnabled, andgetClientFeatureFlagpowered byposthog-jswithout pulling server dependencies into browser bundles.src/keys.ts,.env.example,turbo.json): ValidatesPOSTHOG_API_KEY,POSTHOG_HOST,NEXT_PUBLIC_POSTHOG_KEY, andNEXT_PUBLIC_POSTHOG_HOSTvia@t3-oss/env-nextjsand Zod, no-ops when keys are unset or still set to template placeholders (your-posthog-*), and registersposthog-jsandposthog-nodeintemplates/base/pnpm-workspace.yaml.Scope
Closes #15
Third module in the
stackbase addexpansion (@workspace/payments,@workspace/ai,@workspace/analytics).Verification
Verified environment schema defaults, template placeholder no-op behavior, server event capture and feature flag evaluation, graceful shutdown, and client event capture and flag checks in
templates/base/packages/analyticsusing:pnpm --dir templates/base --filter @workspace/analytics check-types pnpm --dir templates/base --filter @workspace/analytics lint pnpm --dir templates/base --filter @workspace/analytics test pnpm --dir templates/base --filter @workspace/analytics build