Skip to content

feat: finish PostHog analytics integration - #2

Draft
posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog/instrumentation-e014d3
Draft

posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog/instrumentation-e014d3

Conversation

@posthog-eu

@posthog-eu posthog-eu Bot commented Aug 7, 2026

Copy link
Copy Markdown

Summary

This PR finishes the PostHog analytics setup for the app (building on the posthog-js client already added in 1a7dec0). It hardens initialization and wires up capture calls across the content-production workflow:

  • src/main.tsx — only initializes PostHog when both VITE_POSTHOG_KEY and VITE_POSTHOG_HOST are present (previously fell back to a hardcoded host), enables exception autocapture (capture_exceptions), sets defaults: '2026-05-30', and throws a dev-only error if the env vars are missing/misconfigured so it's caught before shipping.
  • src/App.tsx — adds a guarded capture helper (no-ops if PostHog isn't configured) and instruments the operator workflow: manual_short_run_completed, script_generation_completed, video_production_completed, topic_created, topic_discovery_completed, topic_rejected, video_rerender_completed, analytics_sync_completed, upload_approved_for_publish, automation_toggled, youtube_connection_started, youtube_disconnected, script_judge_evaluated. All are personless browser events, each tagged with execution_mode: 'api' | 'offline' depending on whether the app is running against the live API or in offline/demo mode.
  • .env.example — un-comments VITE_POSTHOG_KEY / VITE_POSTHOG_HOST and updates the host to https://eu.i.posthog.com.
  • package-lock.json — lockfile metadata refresh (no dependency changes).

Insights and dashboards created

Type Name Link
Dashboard Analytics basics (wizard) https://eu.posthog.com/project/243137/dashboard/881881
Insight Content production funnel (wizard) https://eu.posthog.com/project/243137/insights/sG7cmuZ8
Insight Production completions over time (wizard) https://eu.posthog.com/project/243137/insights/VHg0XwQ0
Insight Topic pipeline activity (wizard) https://eu.posthog.com/project/243137/insights/xtddkVqe
Insight Workflow control activity (wizard) https://eu.posthog.com/project/243137/insights/vKcubExr
Insight YouTube integration activity (wizard) https://eu.posthog.com/project/243137/insights/gzTUO1Y8

How to verify

  1. Set the environment variables described below (locally in .env, or in Vercel once deployed).
  2. Run the app (npm run dev:all) and click through a few actions — discover a topic, generate a script, produce a video.
  3. In PostHog, open Activity — you should see the events listed above arriving within a minute, and $exception events if an error is thrown.

Environment variables (action needed before PostHog works in production)

Based on vercel.json (which proxies /api to https://shorty-production-8fc1.up.railway.app), the frontend is deployed on Vercel and the API on Railway. Vercel keeps its settings in the Vercel dashboard rather than in a file in this repository, so I could not set these up automatically.

Environment variables are named settings your hosting provider passes to the app when it builds — they let the app know things (like the PostHog project token below) without hardcoding them in the code. PostHog will not receive any data from production until these two are set on the Vercel project:

Name Value
VITE_POSTHOG_KEY phc_z8J9DsNxvyF4ZqcgLW7mqMq8LMSkrN2iEutYnE5txbuw
VITE_POSTHOG_HOST https://eu.i.posthog.com

To set them via the 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) — Vite bakes these into the JS bundle at build time, so they only take effect on the next deployment.

Setting environment variables via a local CLI

Alternatively, from a machine with the Vercel CLI linked to this project:

echo "phc_z8J9DsNxvyF4ZqcgLW7mqMq8LMSkrN2iEutYnE5txbuw" | npx vercel env add VITE_POSTHOG_KEY production
echo "https://eu.i.posthog.com" | npx vercel env add VITE_POSTHOG_HOST production

Then trigger a redeploy for the new variables to take effect.


Created with PostHog Code

Guard PostHog initialization behind both key and host, enable exception autocapture, and wire up capture calls across the content pipeline actions.

Generated-By: PostHog Code
Task-Id: 55b0b5a0-270b-42cd-92c2-bf10fd8c1e8e
@vercel

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
shorty Ready Ready Preview Aug 24, 2026 3:04am

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