Skip to content

Add PostHog analytics integration - #116

Open
posthog[bot] wants to merge 1 commit into
mainfrom
posthog/instrumentation-ebdbf7
Open

Add PostHog analytics integration#116
posthog[bot] wants to merge 1 commit into
mainfrom
posthog/instrumentation-ebdbf7

Conversation

@posthog

@posthog posthog Bot commented Aug 3, 2026

Copy link
Copy Markdown

Summary

This PR adds PostHog product analytics to Sequence using the posthog-js browser SDK (installed via npm, posthog-js@^1.409.5).

  • src/components/posthog-client.tsx — new client component that initializes PostHog (posthog.init) with exception autocapture enabled, and identifies/resets the user against Supabase auth state (useAuth()), covering both real and demo sessions.
  • src/components/providers.tsx — mounts <PostHogClient /> inside the app-wide Providers tree.
  • src/app/global-error.tsx — new Next.js App Router global error boundary that forwards uncaught root-level errors to posthog.captureException.
  • src/app/(app)/layout.tsx, src/components/idle-timeout-modal.tsx — call posthog.reset() on sign-out (both manual sign-out and idle-timeout sign-out).
  • src/app/(auth)/login/page.tsx — calls posthog.identify() right after a successful Supabase login.
  • Client-side conversion/workflow events added at the point of confirmed success (no sensitive lead/contact data in event properties):
    • lead_created (src/app/(app)/leads/new/page.tsx)
    • lead_import_completed (src/app/(app)/import/page.tsx)
    • lead_stage_changed, lead_activity_logged (src/app/(app)/leads/[id]/page.tsx)
    • cadence_created (src/app/(app)/cadences/new/page.tsx)
    • cadence_enrolled (src/components/leads/enroll-cadence-modal.tsx)
    • template_created (src/app/(app)/templates/new/page.tsx)
    • team_invitation_sent (src/app/(app)/team/invite/page.tsx)
    • brevo_connection_tested (src/app/(app)/integrations/brevo/page.tsx)
    • document_uploaded (src/components/documents/upload-document.tsx)
    • document_request_sent (src/components/documents/request-documents-modal.tsx)
    • onboarding_completed (src/app/(onboarding)/onboarding/page.tsx)
  • .env.example — documents the two new PostHog env vars (see below).
  • package.json / package-lock.json — adds posthog-js.

No server-side PostHog SDK was added — the wizard's review step removed an unused server SDK dependency to keep the integration to client-side capture only.

Insights and dashboards created

Type Name Link
Dashboard Analytics basics (wizard) https://us.posthog.com/project/311424/dashboard/1943215
Insight Lead management activity (wizard) https://us.posthog.com/project/311424/insights/BfDbRtYG
Insight Outreach workflow activity (wizard) https://us.posthog.com/project/311424/insights/A2uWstt8
Insight Team and integration health (wizard) https://us.posthog.com/project/311424/insights/aCL92sPt
Insight Document workflow activity (wizard) https://us.posthog.com/project/311424/insights/xgp7YOdz
Insight Onboarding to lead creation (wizard) https://us.posthog.com/project/311424/insights/TqOyxaOR

How to verify

  1. Set the two environment variables from the section below, then deploy this branch (or run npm run dev locally with them set).
  2. Log in and create a lead, or complete any of the other instrumented actions (import a CSV, create a cadence, upload a document, etc.).
  3. In PostHog, open Activity — you should see events like $pageview, lead_created, etc. arriving within a minute.
  4. Open the Analytics basics (wizard) dashboard and confirm the tiles start populating.

Environment variables (action needed before PostHog works)

This app deploys to Vercel (see vercel.json for cron config), which keeps environment variables in the Vercel dashboard rather than in a file committed to this repository — there's no .vercel project link or committed .env.production in this repo for me to update automatically, so these need to be set manually before the integration will send data in production.

Environment variables are named settings your hosting provider passes to the app when it runs — they let the app know things (like the PostHog project token below) without hardcoding them into the source code. PostHog will not receive any events until both of these are set:

Name Value
NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN phc_wrbmQPXYrK6YhzZjVeZxgZHNdSJpWPlKtBKw1qBMaEp
NEXT_PUBLIC_POSTHOG_HOST https://us.i.posthog.com

To set them via the Vercel dashboard:

  1. Open https://vercel.com/dashboard and click on this project.
  2. Go to Settings, then Environment Variables in the left sidebar.
  3. For each row in the table above: paste the Name and Value, leave all environments checked, and click Save.
  4. Redeploy the app (Deployments tab, "..." menu on the latest deployment, Redeploy) — the new settings only take effect on the next deployment.

Setting environment variables via a local CLI

If you have the Vercel CLI installed and linked to this project, you can set them from a terminal instead:

echo "phc_wrbmQPXYrK6YhzZjVeZxgZHNdSJpWPlKtBKw1qBMaEp" | npx vercel env add NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN production
echo "https://us.i.posthog.com" | npx vercel env add NEXT_PUBLIC_POSTHOG_HOST production

Created with PostHog Code

Generated-By: PostHog Code
Task-Id: 445e0ae2-381a-4346-a36f-241967c83fcb
@vercel

vercel Bot commented Aug 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
brasilia Ready Ready Preview Aug 3, 2026 3:12am
mallard-connect Ready Ready Preview Aug 3, 2026 3:12am

@vinay-lgtm-code
vinay-lgtm-code marked this pull request as ready for review August 3, 2026 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants