Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

add rewrites for posthog reverse proxy routes unconditionally, remove unused POSTHOG_ENABLED envvar

Type of Change

  • Bug fix

Testing

Tested manually.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

…onally, remove unused POSTHOG_ENABLED envvar
@vercel
Copy link

vercel bot commented Oct 6, 2025

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

Project Deployment Preview Comments Updated (UTC)
sim Building Building Preview Comment Oct 6, 2025 4:26am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Oct 6, 2025 4:26am

@waleedlatif1 waleedlatif1 merged commit 223ecda into staging Oct 6, 2025
4 of 5 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/posthog branch October 6, 2025 04:27
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Summary

This PR fixes PostHog analytics integration by simplifying the configuration approach. The changes remove the conditional logic that previously controlled when PostHog reverse proxy routes were available, making them always accessible regardless of environment configuration.

The key changes involve two files:

  1. next.config.ts: The rewrites() function now unconditionally returns PostHog proxy routes (/ingest/static/:path* and /ingest/:path*) that forward requests to PostHog's US assets and API endpoints. Previously, these routes were only added when POSTHOG_ENABLED was truthy.
  2. lib/env.ts: Removes the unused server-side POSTHOG_ENABLED environment variable from the Zod schema validation, while keeping the client-side PostHog variables (NEXT_PUBLIC_POSTHOG_ENABLED and NEXT_PUBLIC_POSTHOG_KEY) intact.

This approach aligns with best practices for analytics integration where reverse proxy routes should always be available to avoid CORS issues and ad blocker interference. PostHog functionality is now controlled entirely through client-side environment variables, which is more appropriate since PostHog is primarily a client-side analytics service. The reverse proxy setup ensures reliable communication with PostHog's servers by routing requests through the application's domain rather than making direct cross-origin requests.

Important Files Changed

Changed Files
Filename Score Overview
apps/sim/next.config.ts 5/5 Simplified PostHog rewrites to be always available, removing conditional logic
apps/sim/lib/env.ts 4/5 Removed unused server-side POSTHOG_ENABLED environment variable from schema

Confidence score: 5/5

  • This PR is safe to merge with minimal risk as it simplifies configuration and removes unused code
  • Score reflects straightforward changes that improve reliability by removing conditional complexity
  • No files require special attention as both changes are clean removals of unnecessary conditional logic

Sequence Diagram

sequenceDiagram
    participant User
    participant App as "Next.js App"
    participant PostHog as "PostHog Analytics"
    
    User->>App: "Visit app page"
    App->>App: "Load Next.js config"
    App->>App: "Apply rewrites unconditionally"
    Note over App: "Rewrites now added without POSTHOG_ENABLED check"
    
    User->>App: "Request /ingest/static/:path*"
    App->>PostHog: "Proxy to https://us-assets.i.posthog.com/static/:path*"
    PostHog->>App: "Return static assets"
    App->>User: "Return proxied assets"
    
    User->>App: "Request /ingest/:path*"
    App->>PostHog: "Proxy to https://us.i.posthog.com/:path*"
    PostHog->>App: "Return analytics data"
    App->>User: "Return proxied response"
    
    Note over App: "POSTHOG_ENABLED env var removed from env.ts"
    Note over App: "Rewrites always active for reverse proxy"
Loading

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

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.

2 participants