Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

Summary

  • Make Posthog config lighter temporarily.
  • Prevent ingest calls from being constantly redirected.

Type of Change

  • Bug fix

Testing

Checked network tab to see if permanent redirects stop happening

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)

@vercel
Copy link

vercel bot commented Oct 13, 2025

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

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Oct 13, 2025 6:06pm

@icecrasher321 icecrasher321 merged commit ec73e2e into staging Oct 13, 2025
9 checks passed
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

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 ingest to the exclusion pattern in domain redirect rules (lines 223, 229) to prevent /ingest/* routes from being caught by the legacy domain redirect from simstudio.ai to www.sim.ai
  • provider.tsx: Reduced Posthog tracking overhead by disabling several heavy features:
    • Disabled capture_pageleave and capture_performance
    • Disabled session recording headers/body capture
    • Limited autocapture to specific DOM events and elements only
    • Disabled capture_dead_clicks and enable_heatmaps

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 ingest in 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!
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