-
Notifications
You must be signed in to change notification settings - Fork 559
posthog migration: part 1 #7363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
## Walkthrough
This change removes all PostHog analytics React components, providers, and tracking logic from the codebase across multiple apps. Instead, PostHog is now initialized directly in new instrumentation client modules. Next.js configuration files are updated to proxy certain PostHog API and asset requests. Related environment variables and dependencies are updated accordingly.
## Changes
| File(s) | Change Summary |
|--------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------|
| .../next.config.{ts,mjs} (dashboard, nebula, playground-web, portal, wallet-ui) | Added async `rewrites` functions to proxy `/_ph` paths to external PostHog domains. |
| .../package.json (dashboard, nebula, playground-web, portal) | Updated or added `posthog-js` dependency; removed `flat` from dashboard. |
| .../src/app/layout.tsx (dashboard, playground-web, portal) | Removed all PostHog-related imports and components from root layouts. |
| .../src/app/(app)/layout.tsx, .../team/[team_slug]/layout.tsx (dashboard) | Removed PostHog provider and identifier server from layouts. |
| .../src/app/bridge/components/client/Providers.client.tsx, .../pay/components/client/Providers.client.tsx (dashboard) | Removed PostHog provider and pageview tracking from providers. |
| .../src/components/wallets/PosthogIdentifier{,Server}.tsx (dashboard) | Deleted PostHog identifier client and server components. |
| .../src/hooks/analytics/useTrack.ts (dashboard) | Removed all PostHog tracking logic from the `useTrack` hook. |
| .../src/instrumentation-client.ts (dashboard, nebula, playground-web, portal) | Added new modules to directly initialize PostHog analytics via side effect. |
| .../src/lib/posthog/Posthog{,HeadSetup,PageView}.tsx (dashboard, playground-web, portal) | Deleted all PostHog React provider, head setup, and pageview tracking components. |
| .../src/utils/errorParser.tsx (dashboard) | Removed PostHog error capture logic. |
| .../src/components/others/Feedback.tsx (portal) | Removed PostHog analytics tracking from feedback component. |
| .../src/lib/env.ts (portal) | Deleted `isProd` environment utility. |
| .../src/components/code/RenderCode.tsx, .../app/Header.tsx (portal) | Minor Tailwind z-index syntax updates (unrelated to analytics). |
| .../.env.example (nebula) | Added PostHog environment variables for local development. |
## Sequence Diagram(s)
```mermaid
sequenceDiagram
participant User
participant App
participant InstrumentationClient
participant PostHogCloud
User->>App: Loads page
App->>InstrumentationClient: (side effect) Initialize PostHog if env key present
InstrumentationClient->>PostHogCloud: Connects with config (API host, options)
Note over App,InstrumentationClient: No React PostHog providers/components used
App->>User: Renders UI (no PostHog wrappers)
User->>App: Navigates/interacts
App->>InstrumentationClient: (PostHog tracks events via SDK, if enabled) Possibly related PRs
Suggested reviewers
|
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
size-limit report 📦
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7363 +/- ##
=======================================
Coverage 52.35% 52.35%
=======================================
Files 939 939
Lines 63161 63161
Branches 4213 4217 +4
=======================================
Hits 33070 33070
Misses 29984 29984
Partials 107 107
🚀 New features to boost your workflow:
|
8235abd
to
8ac2523
Compare
8ac2523
to
ab980d8
Compare
2d67599
to
38cb3c9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: PostHog Rewrite Rules Order Issue
The PostHog rewrite rules are incorrectly ordered. The specific /_ph/decide
rule is placed after the general /_ph/:path*
rule, causing requests to /_ph/decide
to be caught by the general pattern and never reach the intended specific rule. The /_ph/decide
rule should precede the /_ph/:path*
rule.
apps/dashboard/next.config.ts#L148-L165
js/apps/dashboard/next.config.ts
Lines 148 to 165 in 38cb3c9
return [ | |
{ | |
source: "/_ph/static/:path*", | |
destination: "https://us-assets.i.posthog.com/static/:path*", | |
}, | |
{ | |
source: "/_ph/:path*", | |
destination: "https://us.i.posthog.com/:path*", | |
}, | |
{ | |
source: "/_ph/decide", | |
destination: "https://us.i.posthog.com/decide", | |
}, | |
{ | |
source: "/thirdweb.eth", | |
destination: "/deployer.thirdweb.eth", | |
}, | |
{ |
apps/nebula/next.config.ts#L51-L68
Lines 51 to 68 in 38cb3c9
serverExternalPackages: ["pino-pretty"], | |
async rewrites() { | |
return [ | |
{ | |
source: "/_ph/static/:path*", | |
destination: "https://us-assets.i.posthog.com/static/:path*", | |
}, | |
{ | |
source: "/_ph/:path*", | |
destination: "https://us.i.posthog.com/:path*", | |
}, | |
{ | |
source: "/_ph/decide", | |
destination: "https://us.i.posthog.com/decide", | |
}, | |
]; | |
}, | |
async headers() { |
apps/portal/next.config.mjs#L60-L77
js/apps/portal/next.config.mjs
Lines 60 to 77 in 38cb3c9
redirects, | |
async rewrites() { | |
return [ | |
{ | |
source: "/_ph/static/:path*", | |
destination: "https://us-assets.i.posthog.com/static/:path*", | |
}, | |
{ | |
source: "/_ph/:path*", | |
destination: "https://us.i.posthog.com/:path*", | |
}, | |
{ | |
source: "/_ph/decide", | |
destination: "https://us.i.posthog.com/decide", | |
}, | |
]; | |
}, | |
webpack: (config) => { |
apps/wallet-ui/next.config.mjs#L57-L74
js/apps/wallet-ui/next.config.mjs
Lines 57 to 74 in 38cb3c9
}, | |
async rewrites() { | |
return [ | |
{ | |
source: "/_ph/static/:path*", | |
destination: "https://us-assets.i.posthog.com/static/:path*", | |
}, | |
{ | |
source: "/_ph/:path*", | |
destination: "https://us.i.posthog.com/:path*", | |
}, | |
{ | |
source: "/_ph/decide", | |
destination: "https://us.i.posthog.com/decide", | |
}, | |
]; | |
}, | |
webpack: (config) => { |
Was this report helpful? Give feedback by reacting with 👍 or 👎
Merge activity
|
# Migrate to PostHog US Instance This PR updates our PostHog integration across all apps to use the US-based PostHog instance instead of the previous self-hosted solution. Key changes include: - Upgraded PostHog JS SDK from 1.67.1 to 1.252.0 - Added API proxying via Next.js rewrites to route PostHog requests through `/_ph` endpoints - Implemented a new initialization approach using `instrumentation-client.ts` files - Removed custom PostHog components and providers in favor of the official SDK's auto-capture functionality - Configured PostHog to capture page views on history changes automatically - Disabled session recording and exception capturing for privacy and performance - Removed the `flat` dependency which is no longer needed These changes will provide more reliable analytics while improving performance by using PostHog's official CDN and modern SDK features. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for proxying analytics-related requests to external services across multiple apps, enabling seamless integration with analytics providers. - **Chores** - Upgraded the analytics library dependency to the latest version in several apps. - Updated environment variable examples to support new analytics configuration. - **Refactor** - Replaced in-app analytics instrumentation with new centralized clients for improved control and consistency. - **Bug Fixes** - Minor CSS z-index syntax adjustments for improved styling consistency. - **Removed** - Eliminated legacy analytics components and tracking from layouts, providers, hooks, and feedback forms, simplifying application structure and reducing external tracking. <!-- end of auto-generated comment: release notes by coderabbit.ai --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on the removal of several `Posthog` components and their related files across multiple applications, as well as updating the `posthog-js` library version to `1.252.0`. It also introduces new `rewrites` in various configuration files to accommodate the updated tracking. ### Detailed summary - Deleted files related to `Posthog` from: - `apps/portal/src/lib/env.ts` - `apps/portal/src/lib/posthog/Posthog.tsx` - `apps/dashboard/src/lib/posthog/Posthog.tsx` - `apps/playground-web/src/lib/posthog/Posthog.tsx` - `apps/dashboard/src/components/wallets/PosthogIdentifier.tsx` - Updated `posthog-js` version to `1.252.0` in: - `apps/nebula/package.json` - `apps/playground-web/package.json` - `apps/portal/package.json` - `apps/dashboard/package.json` - Added `NEXT_PUBLIC_POSTHOG_KEY` and `NEXT_PUBLIC_POSTHOG_HOST` to `apps/nebula/.env.example`. - Introduced new `rewrites` in `next.config.mjs` for `apps/playground-web`, `apps/dashboard`, `apps/nebula`, and `apps/portal` to direct traffic for `Posthog`. - Removed `Posthog` components from various layouts and providers, simplifying the structure in `apps/dashboard/src/app/pay/components/client/Providers.client.tsx` and `apps/dashboard/src/app/bridge/components/client/Providers.client.tsx`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
38cb3c9
to
6b24fed
Compare
Migrate to PostHog US Instance
This PR updates our PostHog integration across all apps to use the US-based PostHog instance instead of the previous self-hosted solution. Key changes include:
/_ph
endpointsinstrumentation-client.ts
filesflat
dependency which is no longer neededThese changes will provide more reliable analytics while improving performance by using PostHog's official CDN and modern SDK features.
Summary by CodeRabbit
New Features
Chores
Refactor
Bug Fixes
Removed
PR-Codex overview
This PR focuses on the removal of several
Posthog
components and their related files across multiple applications, as well as updating theposthog-js
library version to1.252.0
. It also introduces newrewrites
in various configuration files to accommodate the updated tracking.Detailed summary
Posthog
from:apps/portal/src/lib/env.ts
apps/portal/src/lib/posthog/Posthog.tsx
apps/dashboard/src/lib/posthog/Posthog.tsx
apps/playground-web/src/lib/posthog/Posthog.tsx
apps/dashboard/src/components/wallets/PosthogIdentifier.tsx
posthog-js
version to1.252.0
in:apps/nebula/package.json
apps/playground-web/package.json
apps/portal/package.json
apps/dashboard/package.json
NEXT_PUBLIC_POSTHOG_KEY
andNEXT_PUBLIC_POSTHOG_HOST
toapps/nebula/.env.example
.rewrites
innext.config.mjs
forapps/playground-web
,apps/dashboard
,apps/nebula
, andapps/portal
to direct traffic forPosthog
.Posthog
components from various layouts and providers, simplifying the structure inapps/dashboard/src/app/pay/components/client/Providers.client.tsx
andapps/dashboard/src/app/bridge/components/client/Providers.client.tsx
.