fix(posthog): prevent redirects by whitelisting ingest route#1615
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
There was a problem hiding this comment.
Greptile Overview
Summary
Fixed a critical bug where Posthog analytics calls to /ingest/* routes were being permanently redirected due to domain redirect rules, causing performance issues and incorrect tracking behavior.
Key Changes
- next.config.ts: Added
ingestto the exclusion pattern in domain redirect rules (lines 223, 229) to prevent/ingest/*routes from being caught by the legacy domain redirect fromsimstudio.aitowww.sim.ai - provider.tsx: Reduced Posthog tracking overhead by disabling several heavy features:
- Disabled
capture_pageleaveandcapture_performance - Disabled session recording headers/body capture
- Limited
autocaptureto specific DOM events and elements only - Disabled
capture_dead_clicksandenable_heatmaps
- Disabled
The redirect fix ensures that Posthog's proxy route (which rewrites /ingest/* to https://us.i.posthog.com/*) can function correctly without being intercepted by the domain redirect middleware. The configuration changes make the tracking lighter and more performant.
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- The changes are straightforward and surgical: adding a single exclusion to prevent redirects and reducing analytics overhead. The redirect fix directly addresses the root cause (missing
ingestin the exclusion pattern), and the Posthog config changes only disable features rather than introducing new logic. Both changes are conservative and unlikely to introduce bugs. - No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| apps/sim/next.config.ts | 5/5 | Added ingest to redirect exclusion pattern to prevent Posthog API calls from being redirected |
| apps/sim/lib/posthog/provider.tsx | 5/5 | Disabled heavy tracking features and limited autocapture to reduce data collection overhead |
Sequence Diagram
sequenceDiagram
participant Browser
participant NextConfig as Next.js Redirects
participant Rewrites as Next.js Rewrites
participant PosthogProvider as Posthog Provider
participant PosthogAPI as Posthog API (us.i.posthog.com)
Note over Browser,PosthogAPI: Before Fix: Ingest calls were redirected
Browser->>PosthogProvider: Load page with Posthog
PosthogProvider->>PosthogProvider: Initialize with api_host: '/ingest'
PosthogProvider->>Browser: Track event to /ingest/...
Browser->>NextConfig: Request /ingest/...
NextConfig->>NextConfig: Check redirect rules
Note over NextConfig: Pattern: /((?!api|_next|_vercel|...).*)<br/>MISSING 'ingest' → Redirected!
NextConfig-->>Browser: 301/308 Permanent Redirect
Note over Browser: Constant redirects cause issues
Note over Browser,PosthogAPI: After Fix: Ingest route whitelisted
Browser->>PosthogProvider: Load page with Posthog (lighter config)
PosthogProvider->>PosthogProvider: Initialize with reduced tracking
PosthogProvider->>Browser: Track event to /ingest/...
Browser->>NextConfig: Request /ingest/...
NextConfig->>NextConfig: Check redirect rules
Note over NextConfig: Pattern: /((?!api|_next|ingest|...).*)<br/>'ingest' NOW EXCLUDED!
NextConfig->>Rewrites: Pass through to rewrites
Rewrites->>PosthogAPI: Proxy to us.i.posthog.com/...
PosthogAPI-->>Rewrites: Response
Rewrites-->>Browser: Response
Note over Browser: No more permanent redirects!
2 files reviewed, no comments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Type of Change
Testing
Checked network tab to see if permanent redirects stop happening
Checklist