Skip to content

Fix PostHog tracking on v4.wedance.vip#429

Merged
razbakov merged 1 commit into
mainfrom
fix/posthog-public-key
Apr 14, 2026
Merged

Fix PostHog tracking on v4.wedance.vip#429
razbakov merged 1 commit into
mainfrom
fix/posthog-public-key

Conversation

@razbakov
Copy link
Copy Markdown
Collaborator

@razbakov razbakov commented Apr 14, 2026

PostHog project 29269 has received zero events in 30 days.

Root cause: Vercel env var NUXT_PUBLIC_POSTHOG_PUBLIC_KEY was never set, so nuxt-posthog module initialized with an empty key and dropped every event.

Fix: Inline the public phc_ key as the default in nuxt.config.ts. PostHog phc_ keys are public client-side tokens — this is the same pattern used by ikigai-team and brievcase after today's parallel fix. Env var override still works if someone wants to point v4 at a different project later.

Verification: After merge, watch eu.i.posthog.com project 29269 for incoming $pageview events within a few minutes of Vercel redeploy.

Summary by CodeRabbit

  • Chores
    • Updated service configuration settings

Vercel env var NUXT_PUBLIC_POSTHOG_PUBLIC_KEY was never set, so
nuxt-posthog module initialized with empty key and dropped all events.
PostHog project 29269 has recorded 0 events in 30 days despite
v4.wedance.vip being live.

PostHog phc_ keys are public client-side tokens — safe to inline as
the default. Env vars still override if set at deploy time.
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 14, 2026

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

Project Deployment Actions Updated (UTC)
v4 Ready Ready Preview, Comment Apr 14, 2026 11:37pm

Request Review

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 14, 2026

📝 Walkthrough

Walkthrough

The PostHog configuration in nuxt.config.ts has been updated to explicitly specify a publicKey and host URL for the EU PostHog instance, alongside existing clientOptions and environment-driven disabled flag.

Changes

Cohort / File(s) Summary
PostHog Configuration
nuxt.config.ts
Added explicit publicKey and host (https://eu.i.posthog.com) fields to the PostHog configuration object.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

  • Posthog #412: Modifies PostHog configuration settings in nuxt.config.ts to update publicKey and host fields.

Poem

🐰✨ A config hop, a key in place,
EU PostHog finds its rightful space,
Public and proud, the settings align,
Analytics flow on the metrics line! 📊

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and directly describes the main change: fixing PostHog tracking on a specific domain by adding the missing public key configuration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/posthog-public-key

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@nuxt.config.ts`:
- Around line 35-36: The runtimeConfig.public.posthog entries currently default
to empty strings causing server-side capture in server/utils/posthog.ts to bail
out; update nuxt.config.ts to populate runtimeConfig.public.posthog with the
same fallback values used for the client (set public.posthog.publicKey to
'phc_N7rtjDNLzyAGTOkhwhPBrEPybpxBwLlMpfPI9j1xZWB' and public.posthog.host to
'https://eu.i.posthog.com') so that the server-side capture logic in
server/utils/posthog.ts reads non-empty values from runtimeConfig.public.posthog
and will send events when env vars are not provided.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 53a447f0-4cad-4c4b-b2be-0d07492b14b5

📥 Commits

Reviewing files that changed from the base of the PR and between c8c4e52 and a1ff197.

📒 Files selected for processing (1)
  • nuxt.config.ts

Comment thread nuxt.config.ts
Comment on lines +35 to +36
publicKey: 'phc_N7rtjDNLzyAGTOkhwhPBrEPybpxBwLlMpfPI9j1xZWB',
host: 'https://eu.i.posthog.com',
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

For nuxt-posthog v1.6.3 with Nuxt 3.16.x, what is the precedence between posthog.publicKey/posthog.hostset innuxt.config.tsandNUXT_PUBLIC_POSTHOG_PUBLIC_KEY/NUXT_PUBLIC_POSTHOG_HOST environment variables at runtime?

💡 Result:

In nuxt-posthog v1.6.3 with Nuxt 3.16.x, environment variables like NUXT_PUBLIC_POSTHOG_PUBLIC_KEY and NUXT_PUBLIC_POSTHOG_HOST take precedence over posthog.publicKey and posthog.host set directly in nuxt.config.ts. The module configuration reads from environment variables by default: publicKey reads POSTHOG_API_KEY from .env, and host reads POSTHOG_API_HOST. In Nuxt 3, NUXT_PUBLIC_* prefixed variables populate runtimeConfig.public, following Nuxt's standard runtimeConfig behavior where runtime (env) values override nuxt.config.ts values. Nuxt modules typically use addAutoImport and resolveRuntimeConfig, so runtimeConfig.public.posthogKey (from env) would override config file settings. The official docs confirm env vars are the default source, and GitHub issue #97 notes this module "Supports runtime config (this needs to be documented)", confirming runtimeConfig/env support with precedence.

Citations:


🏁 Script executed:

#!/bin/bash
# First, let's find and examine the nuxt.config.ts file
fd -t f -name "nuxt.config.ts" -o -name "nuxt.config.js" | head -5

Repository: we-dance/v4

Length of output: 285


🏁 Script executed:

#!/bin/bash
# Look for the posthog configuration section in nuxt.config.ts
fd -t f -name "nuxt.config.ts" -exec wc -l {} \;

Repository: we-dance/v4

Length of output: 285


🏁 Script executed:

#!/bin/bash
# Check the server-side posthog utility to see how it reads config
fd -t f -path "*/server/utils/posthog.ts" -o -path "*/server/posthog.ts" | head -5

Repository: we-dance/v4

Length of output: 223


🏁 Script executed:

#!/bin/bash
# Find nuxt.config.ts and show its line count
find . -name "nuxt.config.ts" -type f -exec wc -l {} +

Repository: we-dance/v4

Length of output: 114


🏁 Script executed:

#!/bin/bash
# Find and read the nuxt.config.ts file to check PostHog config (Lines 30-45 and 145-155)
find . -name "nuxt.config.ts" -type f -exec head -160 {} +

Repository: we-dance/v4

Length of output: 3651


🏁 Script executed:

#!/bin/bash
# Find server-side PostHog utility
find . -path "*/server/utils/posthog.ts" -o -path "*/server/*posthog*" | head -10

Repository: we-dance/v4

Length of output: 80


🏁 Script executed:

#!/bin/bash
# Read the server-side posthog utility file
cat -n ./server/utils/posthog.ts

Repository: we-dance/v4

Length of output: 682


🏁 Script executed:

#!/bin/bash
# Search for any references to runtimeConfig in nuxt.config.ts or PostHog setup
rg "runtimeConfig.*posthog" -A 2 -B 2

Repository: we-dance/v4

Length of output: 37


🏁 Script executed:

#!/bin/bash
# Check if there are any other PostHog configuration files or setup
find . -type f -name "*posthog*" | grep -v node_modules | head -20

Repository: we-dance/v4

Length of output: 80


🏁 Script executed:

#!/bin/bash
# Check if there's a .env.example or .env file with PostHog env vars
find . -name ".env*" -type f | head -10

Repository: we-dance/v4

Length of output: 106


🏁 Script executed:

#!/bin/bash
# Search for any initialization or setup that might populate runtimeConfig.public.posthog
rg "NUXT_PUBLIC_POSTHOG" -t ts -t js | head -20

Repository: we-dance/v4

Length of output: 136


🏁 Script executed:

#!/bin/bash
# Check the package.json to confirm nuxt-posthog version
rg '"nuxt-posthog"' package.json

Repository: we-dance/v4

Length of output: 83


🏁 Script executed:

#!/bin/bash
# Check the .env.example to see what PostHog vars are declared
cat -n ./.env.example | grep -i posthog

Repository: we-dance/v4

Length of output: 167


🏁 Script executed:

#!/bin/bash
# Get full .env.example to understand the expected configuration
cat ./.env.example

Repository: we-dance/v4

Length of output: 1100


Provide fallback values in runtimeConfig.public.posthog for server-side capture

Server-side PostHog capture (server/utils/posthog.ts line 9-15) reads from runtimeConfig.public.posthog, which has empty string defaults. With empty env vars (default in .env.example), the capture utility returns early without logging events. The module config has hardcoded fallbacks (lines 35-36) for client-side, but the server relies on runtimeConfig which lacks these fallbacks. To ensure consistent behavior, populate runtimeConfig.public.posthog with the same fallback values:

Suggested fix
+const posthogPublicKey =
+  process.env.NUXT_PUBLIC_POSTHOG_PUBLIC_KEY || 'phc_N7rtjDNLzyAGTOkhwhPBrEPybpxBwLlMpfPI9j1xZWB'
+const posthogHost = process.env.NUXT_PUBLIC_POSTHOG_HOST || 'https://eu.i.posthog.com'
+
 export default defineNuxtConfig({
   ...
   posthog: {
-    publicKey: 'phc_N7rtjDNLzyAGTOkhwhPBrEPybpxBwLlMpfPI9j1xZWB',
-    host: 'https://eu.i.posthog.com',
+    publicKey: posthogPublicKey,
+    host: posthogHost,
     ...
   },
   ...
   runtimeConfig: {
     ...
     public: {
       posthog: {
-        publicKey: '',
-        host: '',
+        publicKey: posthogPublicKey,
+        host: posthogHost,
       },
       ...
     },
   },
 })
🧰 Tools
🪛 Betterleaks (1.1.2)

[high] 35-35: Detected a PostHog Project API Key, which may expose product analytics data and event tracking to unauthorized access.

(posthog-project-api-key)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@nuxt.config.ts` around lines 35 - 36, The runtimeConfig.public.posthog
entries currently default to empty strings causing server-side capture in
server/utils/posthog.ts to bail out; update nuxt.config.ts to populate
runtimeConfig.public.posthog with the same fallback values used for the client
(set public.posthog.publicKey to
'phc_N7rtjDNLzyAGTOkhwhPBrEPybpxBwLlMpfPI9j1xZWB' and public.posthog.host to
'https://eu.i.posthog.com') so that the server-side capture logic in
server/utils/posthog.ts reads non-empty values from runtimeConfig.public.posthog
and will send events when env vars are not provided.

@razbakov razbakov merged commit c77efe1 into main Apr 14, 2026
3 of 5 checks passed
@github-project-automation github-project-automation Bot moved this from Triage to Released in v4 Launch Apr 14, 2026
@razbakov razbakov deleted the fix/posthog-public-key branch April 14, 2026 23:57
razbakov added a commit that referenced this pull request Apr 15, 2026
PR #429 set the module-level posthog.publicKey but runtimeConfig.public.posthog
still defaulted to empty strings, which override the module config at runtime
when Vercel env vars are unset. Result: deployed __NUXT__.config.public.posthog
showed publicKey:'' and the client never initialized.

Set the same public phc_ key here so both layers agree.
razbakov added a commit that referenced this pull request Apr 15, 2026
PR #429 set the module-level posthog.publicKey but runtimeConfig.public.posthog
still defaulted to empty strings, which override the module config at runtime
when Vercel env vars are unset. Result: deployed __NUXT__.config.public.posthog
showed publicKey:'' and the client never initialized.

Set the same public phc_ key here so both layers agree.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Released

Development

Successfully merging this pull request may close these issues.

1 participant