Skip to content

UN-3543 [FIX] Use per-user distinct_id and deployment tagging for PostHog#2049

Open
chandrasekharan-zipstack wants to merge 5 commits into
mainfrom
UN-3543-posthog-per-user-identity
Open

UN-3543 [FIX] Use per-user distinct_id and deployment tagging for PostHog#2049
chandrasekharan-zipstack wants to merge 5 commits into
mainfrom
UN-3543-posthog-per-user-identity

Conversation

@chandrasekharan-zipstack

@chandrasekharan-zipstack chandrasekharan-zipstack commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

What

  • PostHog distinct_id is now the user's email (fallback orgId:userId) instead of orgId:orgName, so each user is an individual PostHog person
  • org_id, org_name and software (OSS/SAAS) are registered as super-properties, stamped on every captured event
  • New deployment super-property derived from hostname: us-prod / eu-prod / self-hosted
  • PostHog can now be disabled at container startup via VITE_ENABLE_POSTHOG=false (exposed through window.RUNTIME_CONFIG) — no rebuild needed; staging should set this
  • SDK init hardening: person_profiles: "identified_only", respect_dnt: true

Why

  • All deployments (US prod, EU prod, OSS self-hosts) report to a single PostHog project; with the org as distinct_id, every user in an org collapsed into one PostHog person — per-user analytics (DAU/WAU, funnels, retention) were impossible and person properties thrashed last-writer-wins
  • Org-level breakdowns remain possible via the registered super-properties (no paid Group Analytics add-on needed)
  • deployment tagging replaces the brittle orgName === "mock_org" check for segmenting OSS vs SaaS and US vs EU
  • Email chosen as distinct_id because bare Django user pks collide across regions/self-hosts in the shared project
  • Vite env vars are baked at image build time and the same image is promoted across environments, so a runtime-config toggle is the only way to disable PostHog on staging without forking the build

How

  • frontend/src/hooks/usePostHogEvents.js: setPostHogIdentity builds distinct_id from email, keeps existing person properties (name, org, software, email, userId), and calls posthog.register() with org super-properties
  • frontend/src/index.jsx: reads enablePosthog from window.RUNTIME_CONFIG first (falls back to build-time import.meta.env.VITE_ENABLE_POSTHOG); hostname→deployment map registered right after posthog.init
  • frontend/generate-runtime-config.sh: emits enablePosthog into runtime-config.js from the container's VITE_ENABLE_POSTHOG (or REACT_APP_ENABLE_POSTHOG) env at startup

Can this PR break any existing features. If yes, please list possible items. If no, please explain why. (PS: Admins do not merge the PR without this section filled)

  • No product features touched — analytics instrumentation only; PostHog capture failures are already swallowed by the helper
  • PostHog entities verified against the live project before this change: zero feature flags/experiments exist (no flag-bucketing reshuffle); event names and person-property names are unchanged, so existing insights/cohorts keep evaluating
  • Expected metric shifts (not breakage): unique-user counts step UP at deploy (previously counted orgs); the "All Unique Users" dashboard tile becomes one-row-per-user with accurate emails; respect_dnt drops events from DNT-enabled browsers
  • Runtime-config default preserves current behaviour: when the env var is unset, the generated value is an empty string, which falls through to the build-time env (PostHog stays enabled in prod images)
  • Rollout note: add a PostHog annotation on deploy date and notify marketing/growth about the step-change

Database Migrations

  • None

Env Config

  • VITE_ENABLE_POSTHOG is now honoured at container runtime via runtime-config.js (previously build-time only)
  • Follow-up (deploy repo): set VITE_ENABLE_POSTHOG=false on the staging frontend deployment so staging stops reporting to the shared PostHog project

Relevant Docs

  • Internal PostHog audit notes (2026-06-02) tracked in the team knowledge base

Related Issues or PRs

  • UN-3543
  • Follow-ups tracked there: central event enum, structured props, *_failed events, per-install instance_id for OSS

Dependencies Versions

  • No changes

Notes on Testing

  • bunx biome check passes on the touched files
  • Manual: log in locally → PostHog person is keyed by email with org_id/org_name/software/deployment super-properties on captured events
  • Runtime toggle: start the frontend container with VITE_ENABLE_POSTHOG=false/config/runtime-config.js carries enablePosthog: "false" and PostHog never initializes

Checklist

I have read and understood the Contribution Guidelines.

🤖 Generated with Claude Code

…tHog

- distinct_id is now the user's email (fallback orgId:userId) instead of
  the org, enabling per-user analytics (DAU/WAU, funnels, retention)
- org_id/org_name/software registered as super-properties on every event
  so org-level breakdowns work without the group analytics add-on
- deployment super-property derived from hostname (us-prod / eu-prod /
  saas-staging / dev / self-hosted) to segment the shared PostHog project
- init hygiene: person_profiles=identified_only, respect_dnt=true

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: acc5fbab-450e-42c3-ab37-cb5c70a87751

📥 Commits

Reviewing files that changed from the base of the PR and between 659dcb9 and 7f89325.

📒 Files selected for processing (1)
  • frontend/src/index.jsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/index.jsx

Summary by CodeRabbit

  • Chores
    • Runtime config now supports enabling/disabling analytics at runtime via enablePosthog.
    • Analytics initialization is more robust: won’t block app startup on failure, respects Do Not Track, and uses privacy-friendly profile handling.
    • Events now include deployment context for better environment attribution.
  • New Features
    • PostHog identity handling is now more privacy-aware: distinct IDs are computed based on deployment type, PII is only included when allowed, and events get consistent org/software super-properties (including userId when available).

Walkthrough

Adds PostHog deployment detection helpers, runtime enable flag from container config, privacy-aware initialization with error handling, and a deployment-conditional identity refactoring that gates PII and registers org-level super-properties.

Changes

PostHog Configuration and Identity

Layer / File(s) Summary
Deployment helper
frontend/src/helpers/PostHogDeployment.js
Exports getDeployment() (hostname→deployment label, default "self-hosted") and isSaasProdDeployment() (true if not self-hosted) for identity and initialization decisions.
Runtime config generation
frontend/generate-runtime-config.sh
Build script generates enablePosthog field in window.RUNTIME_CONFIG from VITE_ENABLE_POSTHOG or REACT_APP_ENABLE_POSTHOG, and logs the resolved value.
PostHog initialization with privacy and deployment
frontend/src/index.jsx
Runtime flag takes precedence over build-time config; initialization wrapped in try/catch, adds privacy options (person_profiles: "identified_only", respect_dnt: true), and registers deployment property from getDeployment().
Identity and event properties refactoring
frontend/src/hooks/usePostHogEvents.js
Imports isSaasProdDeployment; refactors setPostHogIdentity to derive distinctId with email (when SaaS and PII allowed) or org:userId fallback, always sets org and software, conditionally includes PII, adds userId independently, and calls posthog.register to attach org-level super-properties.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically identifies the main change: per-user distinct_id and deployment tagging for PostHog analytics, directly matching the PR's core objective.
Description check ✅ Passed The description follows the template structure comprehensively, covering What, Why, How, feature-break assessment, env config, dependencies, testing notes, and the required checklist affirmation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 UN-3543-posthog-per-user-identity

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.

…coded staging host

- enablePosthog exposed through window.RUNTIME_CONFIG so containerized
  envs (staging) can disable PostHog at startup without a rebuild
- drop saas-staging/dev hostname mapping; non-prod envs are expected to
  disable PostHog via VITE_ENABLE_POSTHOG

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@chandrasekharan-zipstack chandrasekharan-zipstack marked this pull request as ready for review June 12, 2026 09:54
@greptile-apps

greptile-apps Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR overhauls PostHog identity so each user becomes a distinct PostHog person (email as distinct_id, org-scoped fallback) rather than collapsing an entire org into one person, and adds a runtime toggle (VITE_ENABLE_POSTHOG) so staging containers can opt out without a rebuild.

  • Email is used as distinct_id for SaaS deployments; self-hosted/OSS installs fall back to an orgId:userId composite to avoid cross-region primary-key collisions.
  • org_id, org_name, software, and deployment are registered as super-properties on every event, enabling org-level breakdowns without Group Analytics; deployment is derived from a hostname-to-label map at init time.
  • PostHog init is wrapped in try/catch to prevent analytics failures from blocking app bootstrap, and person_profiles: "identified_only" plus respect_dnt: true are added for cost and privacy.

Confidence Score: 5/5

Analytics-only change; no product paths, database schemas, or auth flows are touched. PostHog failures are swallowed by try/catch so a broken init cannot block app bootstrap.

All changed code is limited to PostHog instrumentation. The runtime-config toggle has safe fallback semantics (empty string falls through to the build-time env). The distinct_id fallback fix from prior review rounds is present. The only remaining gap — isOpenSource still using the mock_org name check, causing software: SAAS to appear on events from self-hosted commercial installs — affects analytics accuracy but not product behaviour.

frontend/src/hooks/usePostHogEvents.js — the isOpenSource derivation that drives the software super-property could misclassify self-hosted commercial installs.

Important Files Changed

Filename Overview
frontend/generate-runtime-config.sh Adds enablePosthog field to the runtime-config.js output, correctly using the shell default-substitution pattern consistent with the existing logoUrl field.
frontend/src/helpers/PostHogDeployment.js New helper that maps SaaS hostnames to deployment tags and exports isSaasProdDeployment(); the hostname map is a closed list that will need manual updates for new SaaS domains, and isSaasProdDeployment() is re-used as the PII-gating signal in usePostHogEvents, creating a dual role that could diverge.
frontend/src/hooks/usePostHogEvents.js Rewrites setPostHogIdentity to use email as distinct_id for SaaS, fallback to orgId:userId, and registers org super-properties; isOpenSource still relies on the mock_org name check, which misclassifies self-hosted commercial installs as software: SAAS on every event.
frontend/src/index.jsx Adds runtime-config toggle for PostHog, wraps init in try/catch, and registers the deployment super-property immediately after init; logic and fallback semantics are correct.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Container startup\ngenerate-runtime-config.sh] -->|writes enablePosthog| B[window.RUNTIME_CONFIG]
    B --> C{index.jsx\nenablePosthog !== 'false'?}
    C -- No --> D[PostHog disabled\nno init]
    C -- Yes --> E[posthog.init\nperson_profiles: identified_only\nrespect_dnt: true]
    E --> F[posthog.register\ndeployment: us-prod / eu-prod / self-hosted]
    F --> G[App renders\nPostHogProvider]
    G --> H{User logs in\nsetPostHogIdentity called}
    H --> I{isSaasProdDeployment\n&& !isOpenSource?}
    I -- Yes / canSendPii --> J[distinctId = email\npersonProps += name, email]
    I -- No --> K[distinctId = orgId:userId\nno PII in personProps]
    J --> L[posthog.identify distinctId, personProperties]
    K --> L
    L --> M[posthog.register\norg_id, org_name, software]
    M --> N[All subsequent events carry\ndeployment + org_id + org_name + software]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[Container startup\ngenerate-runtime-config.sh] -->|writes enablePosthog| B[window.RUNTIME_CONFIG]
    B --> C{index.jsx\nenablePosthog !== 'false'?}
    C -- No --> D[PostHog disabled\nno init]
    C -- Yes --> E[posthog.init\nperson_profiles: identified_only\nrespect_dnt: true]
    E --> F[posthog.register\ndeployment: us-prod / eu-prod / self-hosted]
    F --> G[App renders\nPostHogProvider]
    G --> H{User logs in\nsetPostHogIdentity called}
    H --> I{isSaasProdDeployment\n&& !isOpenSource?}
    I -- Yes / canSendPii --> J[distinctId = email\npersonProps += name, email]
    I -- No --> K[distinctId = orgId:userId\nno PII in personProps]
    J --> L[posthog.identify distinctId, personProperties]
    K --> L
    L --> M[posthog.register\norg_id, org_name, software]
    M --> N[All subsequent events carry\ndeployment + org_id + org_name + software]
Loading

Reviews (4): Last reviewed commit: "Merge branch 'main' into UN-3543-posthog..." | Re-trigger Greptile

Comment thread frontend/src/hooks/usePostHogEvents.js Outdated
Comment thread frontend/src/hooks/usePostHogEvents.js Outdated
Comment thread frontend/src/index.jsx

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
frontend/generate-runtime-config.sh (1)

20-20: 💤 Low value

Consider logging the enablePosthog value for debugging parity.

The echo statement logs logoUrl but not the new enablePosthog setting. Adding it would help operators verify PostHog state at container startup.

🔧 Suggested enhancement
-echo "Runtime configuration generated successfully with logo URL: ${VITE_CUSTOM_LOGO_URL:-${REACT_APP_CUSTOM_LOGO_URL:-<not set>}}"
+echo "Runtime configuration generated successfully with logo URL: ${VITE_CUSTOM_LOGO_URL:-${REACT_APP_CUSTOM_LOGO_URL:-<not set>}}, enablePosthog: ${VITE_ENABLE_POSTHOG:-${REACT_APP_ENABLE_POSTHOG:-<not set>}}"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/generate-runtime-config.sh` at line 20, Update the runtime config
echo to also print the PostHog enable flag for startup debugging: read the
enablePosthog value from the same env precedence used elsewhere (e.g.,
VITE_ENABLE_POSTHOG with fallback to REACT_APP_ENABLE_POSTHOG) and append it to
the existing log message that currently prints the logo URL (the echo line).
Ensure the message clearly labels the flag (e.g., "enablePosthog: <value>") so
operators can verify PostHog state at container startup.
frontend/src/hooks/usePostHogEvents.js (2)

67-69: ⚡ Quick win

Add a defensive guard when both email and IDs are unavailable.

If email is falsy and either orgId or userId is undefined, the distinctId becomes malformed (e.g., "undefined:undefined"), which would merge all such edge-case users into one PostHog person and corrupt analytics.

Consider early-returning or logging if no usable identifier exists:

Suggested guard
+    if (!email && (!orgId || !userId)) {
+      // Insufficient identity data; skip PostHog identification
+      return;
+    }
     const distinctId = email || `${orgId}:${userId}`;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/hooks/usePostHogEvents.js` around lines 67 - 69, The distinctId
logic in usePostHogEvents.js can produce "undefined:undefined" when email is
falsy and orgId/userId are missing; update the hook (usePostHogEvents) to
defensively check before building distinctId: require either a truthy email or
both a non-empty orgId and userId, and if neither condition holds, early-return
(skip sending/posting events) and log a warning via the same logger used in this
hook; ensure all places that reference distinctId use the validated value so
malformed identifiers are never sent to PostHog.

85-93: ⚡ Quick win

Wrap PostHog calls in try-catch for consistency.

setPostHogCustomEvent already guards posthog.capture with a try-catch (lines 97-101), but identify and register are unguarded. If PostHog is disabled at runtime or the SDK is in an unexpected state, these calls could throw. Apply the same defensive pattern here.

Suggested change
-    posthog.identify(distinctId, personProperties);
-
-    // Super-properties ride on every captured event, enabling org-level
-    // breakdowns without the group analytics add-on
-    posthog.register({
-      org_id: orgId,
-      org_name: orgName,
-      software,
-    });
+    try {
+      posthog.identify(distinctId, personProperties);
+
+      // Super-properties ride on every captured event, enabling org-level
+      // breakdowns without the group analytics add-on
+      posthog.register({
+        org_id: orgId,
+        org_name: orgName,
+        software,
+      });
+    } catch {
+      // PostHog tracking is non-critical, safe to ignore
+    }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/hooks/usePostHogEvents.js` around lines 85 - 93, Wrap the
unguarded posthog.identify(distinctId, personProperties) and
posthog.register({...}) calls in the same defensive try-catch pattern used by
setPostHogCustomEvent so SDK errors don't bubble up; locate the calls in
usePostHogEvents.js (the posthog.identify and posthog.register lines), surround
each (or both together) with try { ... } catch (err) { /* log the error
similarly to setPostHogCustomEvent — e.g., console.error or existing logger with
context */ } to mirror existing error handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@frontend/generate-runtime-config.sh`:
- Line 20: Update the runtime config echo to also print the PostHog enable flag
for startup debugging: read the enablePosthog value from the same env precedence
used elsewhere (e.g., VITE_ENABLE_POSTHOG with fallback to
REACT_APP_ENABLE_POSTHOG) and append it to the existing log message that
currently prints the logo URL (the echo line). Ensure the message clearly labels
the flag (e.g., "enablePosthog: <value>") so operators can verify PostHog state
at container startup.

In `@frontend/src/hooks/usePostHogEvents.js`:
- Around line 67-69: The distinctId logic in usePostHogEvents.js can produce
"undefined:undefined" when email is falsy and orgId/userId are missing; update
the hook (usePostHogEvents) to defensively check before building distinctId:
require either a truthy email or both a non-empty orgId and userId, and if
neither condition holds, early-return (skip sending/posting events) and log a
warning via the same logger used in this hook; ensure all places that reference
distinctId use the validated value so malformed identifiers are never sent to
PostHog.
- Around line 85-93: Wrap the unguarded posthog.identify(distinctId,
personProperties) and posthog.register({...}) calls in the same defensive
try-catch pattern used by setPostHogCustomEvent so SDK errors don't bubble up;
locate the calls in usePostHogEvents.js (the posthog.identify and
posthog.register lines), surround each (or both together) with try { ... } catch
(err) { /* log the error similarly to setPostHogCustomEvent — e.g.,
console.error or existing logger with context */ } to mirror existing error
handling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 119e73f1-d4d7-4da6-85bf-083e8848f00b

📥 Commits

Reviewing files that changed from the base of the PR and between 776d0fd and 1a28bba.

📒 Files selected for processing (3)
  • frontend/generate-runtime-config.sh
  • frontend/src/hooks/usePostHogEvents.js
  • frontend/src/index.jsx

@jaseemjaskp jaseemjaskp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review (PR Review Toolkit: Code Reviewer, Silent Failure Hunter, Type Design Analyzer, PR Test Analyzer, Comment Analyzer, Code Simplifier).

Scope: the 3 files changed by this PR. I've omitted findings that duplicate the existing greptile comments (degenerate distinctId at usePostHogEvents.js:69, reset() on logout at :93, and ||/empty-string semantics at index.jsx:17 — all still worth addressing). The items below are new.

Comment thread frontend/src/hooks/usePostHogEvents.js Outdated
Comment thread frontend/src/hooks/usePostHogEvents.js Outdated
Comment thread frontend/src/index.jsx Outdated
Comment thread frontend/src/hooks/usePostHogEvents.js Outdated
- email/name sent to PostHog only from Unstract-managed SaaS deployments;
  self-hosted/OSS identify with an anonymous org-scoped id (tightens the
  pre-existing behaviour of sending email person props from everywhere)
- deployment detection extracted to helpers/PostHogDeployment.js, shared
  by init and identity
- init/register and identify wrapped in try/catch so analytics failures
  (blocked storage, ad-blockers, CSP) can't break bootstrap or the app
- guard degenerate "undefined:<id>" fallback distinct_id when orgId absent
- log enablePosthog in runtime-config startup echo; dot notation nits

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
frontend/generate-runtime-config.sh (1)

8-14: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Escape runtime env values before embedding into JavaScript.

Line 8–14 currently inject raw environment values into quoted JS strings. If any value contains " or \, runtime-config.js becomes invalid and can break bootstrap.

Suggested fix
 #!/bin/sh
@@
+# Escape values for safe inclusion in JS string literals
+js_escape() {
+  printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'
+}
+
+FAVICON_PATH_RAW="${VITE_FAVICON_PATH:-${REACT_APP_FAVICON_PATH}}"
+LOGO_URL_RAW="${VITE_CUSTOM_LOGO_URL:-${REACT_APP_CUSTOM_LOGO_URL}}"
+ENABLE_POSTHOG_RAW="${VITE_ENABLE_POSTHOG:-${REACT_APP_ENABLE_POSTHOG}}"
+
+FAVICON_PATH_ESCAPED="$(js_escape "$FAVICON_PATH_RAW")"
+LOGO_URL_ESCAPED="$(js_escape "$LOGO_URL_RAW")"
+ENABLE_POSTHOG_ESCAPED="$(js_escape "$ENABLE_POSTHOG_RAW")"
+
 cat > /usr/share/nginx/html/config/runtime-config.js << EOF
 // This file is auto-generated at runtime. Do not modify manually.
 window.RUNTIME_CONFIG = {
-  faviconPath: "${VITE_FAVICON_PATH:-${REACT_APP_FAVICON_PATH}}",
-  logoUrl: "${VITE_CUSTOM_LOGO_URL:-${REACT_APP_CUSTOM_LOGO_URL}}",
-  enablePosthog: "${VITE_ENABLE_POSTHOG:-${REACT_APP_ENABLE_POSTHOG}}"
+  faviconPath: "${FAVICON_PATH_ESCAPED}",
+  logoUrl: "${LOGO_URL_ESCAPED}",
+  enablePosthog: "${ENABLE_POSTHOG_ESCAPED}"
 };
 EOF
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/generate-runtime-config.sh` around lines 8 - 14, The
runtime-config.js generator currently inserts raw env values into quoted JS
strings (window.RUNTIME_CONFIG), which breaks if values contain " or \; fix by
JSON-escaping each injected value before writing them. Replace direct expansions
like "${VITE_FAVICON_PATH:-${REACT_APP_FAVICON_PATH}}" with a
JSON-encoded/escaped form of the chosen variable (e.g., use a small helper that
picks the fallback variable then passes it through a JSON encoder such as jq -R
-s `@json` or python/json.dumps) for each field (faviconPath, logoUrl,
enablePosthog) so the output in runtime-config.js is always valid JavaScript
strings.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@frontend/generate-runtime-config.sh`:
- Around line 8-14: The runtime-config.js generator currently inserts raw env
values into quoted JS strings (window.RUNTIME_CONFIG), which breaks if values
contain " or \; fix by JSON-escaping each injected value before writing them.
Replace direct expansions like "${VITE_FAVICON_PATH:-${REACT_APP_FAVICON_PATH}}"
with a JSON-encoded/escaped form of the chosen variable (e.g., use a small
helper that picks the fallback variable then passes it through a JSON encoder
such as jq -R -s `@json` or python/json.dumps) for each field (faviconPath,
logoUrl, enablePosthog) so the output in runtime-config.js is always valid
JavaScript strings.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9ec33c3c-a83b-4ffe-a83d-27cbec5d9b0b

📥 Commits

Reviewing files that changed from the base of the PR and between 1a28bba and 659dcb9.

📒 Files selected for processing (4)
  • frontend/generate-runtime-config.sh
  • frontend/src/helpers/PostHogDeployment.js
  • frontend/src/hooks/usePostHogEvents.js
  • frontend/src/index.jsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • frontend/src/index.jsx
  • frontend/src/hooks/usePostHogEvents.js

…ser-identity

# Conflicts:
#	frontend/src/index.jsx
Comment thread frontend/src/hooks/usePostHogEvents.js
@github-actions

Copy link
Copy Markdown
Contributor

Frontend Lint Report (Biome)

All checks passed! No linting or formatting issues found.

@sonarqubecloud

Copy link
Copy Markdown

@jaseemjaskp jaseemjaskp self-requested a review June 16, 2026 07:06

@jaseemjaskp jaseemjaskp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed with the PR Review Toolkit (code-reviewer, silent-failure-hunter, type-design-analyzer, pr-test-analyzer, comment-analyzer, code-simplifier). The substantive issues from the prior pass — PII-as-distinct_id gating, unguarded identify/register, bootstrap-abort risk, and the degenerate fallback id — are all addressed in the current code. Remaining observations are doc-wording, defensive-structure, magic-string, and test-coverage suggestions that don't rise to a blocking bar. LGTM.

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.

3 participants