From f61a50b2e41c837154c8564a767b0e04757fc9cb Mon Sep 17 00:00:00 2001 From: Ben White Date: Fri, 15 Mar 2024 17:14:46 +0100 Subject: [PATCH 1/3] Fix defaults --- README.md | 2 +- playground/nextjs/pages/_app.tsx | 2 +- src/posthog-core.ts | 6 +++--- src/utils/request-router.ts | 5 +++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5e806c19b..62c66e7a2 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Cypress: run `pnpm start` to have a test server running and separately `pnpm cyp Testing on IE11 requires a bit more setup. TestCafe tests will use the playground application to test the locally built array.full.js bundle. It will also verify that the events emitted during the testing of playground are loaded -into the PostHog app. By default it uses https://app.posthog.com and the +into the PostHog app. By default it uses https://us.i.posthog.com and the project with ID 11213. See the testcafe tests to see how to override these if needed. For PostHog internal users ask @benjackwhite or @hazzadous to invite you to the Project. You'll need to set `POSTHOG_API_KEY` to your personal API key, and diff --git a/playground/nextjs/pages/_app.tsx b/playground/nextjs/pages/_app.tsx index 7de0a2204..e7632d1e6 100644 --- a/playground/nextjs/pages/_app.tsx +++ b/playground/nextjs/pages/_app.tsx @@ -10,7 +10,7 @@ import { CookieBanner, cookieConsentGiven } from '@/src/CookieBanner' if (typeof window !== 'undefined') { posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY || '', { - api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST || 'https://app.posthog.com', + api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST || 'https://us.i.posthog.com', session_recording: { recordCrossOriginIframes: true, }, diff --git a/src/posthog-core.ts b/src/posthog-core.ts index 52d474bcf..0d7d60f54 100644 --- a/src/posthog-core.ts +++ b/src/posthog-core.ts @@ -97,7 +97,7 @@ const PRIMARY_INSTANCE_NAME = 'posthog' let ENQUEUE_REQUESTS = !SUPPORTS_REQUEST && userAgent?.indexOf('MSIE') === -1 && userAgent?.indexOf('Mozilla') === -1 export const defaultConfig = (): PostHogConfig => ({ - api_host: 'https://app.posthog.com', + api_host: 'https://us.i.posthog.com', api_transport: 'XHR', ui_host: null, token: '', @@ -1464,12 +1464,12 @@ export class PostHog { * * { * // PostHog API host - * api_host: 'https://app.posthog.com', + * api_host: 'https://us.i.posthog.com', * * * // PostHog web app host, currently only used by the Sentry integration. * // This will only be different from api_host when using a reverse-proxied API host – in that case * // the original web app host needs to be passed here so that links to the web app are still convenient. - * ui_host: 'https://app.posthog.com', + * ui_host: 'https://us.posthog.com', * * // Automatically capture clicks, form submissions and change events * autocapture: true diff --git a/src/utils/request-router.ts b/src/utils/request-router.ts index 83f50d808..9167cbc85 100644 --- a/src/utils/request-router.ts +++ b/src/utils/request-router.ts @@ -14,6 +14,7 @@ export enum RequestRouterRegion { export type RequestRouterTarget = 'api' | 'ui' | 'assets' +const ingestionDomain = 'i.posthog.com' export class RequestRouter { instance: PostHog private _regionCache: Record = {} @@ -49,14 +50,14 @@ export class RequestRouter { } if (target === 'ui') { - return (this.uiHost || this.apiHost) + path + return (this.uiHost || this.apiHost.replace(`.${ingestionDomain}`, '.posthog.com')) + path } if (this.region === RequestRouterRegion.CUSTOM) { return this.apiHost + path } - const suffix = 'i.posthog.com' + path + const suffix = ingestionDomain + path switch (target) { case 'assets': From 07b60b09be26a5a814e8c827afd076f7dfda59bb Mon Sep 17 00:00:00 2001 From: Ben White Date: Mon, 18 Mar 2024 08:32:34 +0100 Subject: [PATCH 2/3] Fix --- src/utils/request-router.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/request-router.ts b/src/utils/request-router.ts index 9167cbc85..4ec568ee6 100644 --- a/src/utils/request-router.ts +++ b/src/utils/request-router.ts @@ -15,6 +15,7 @@ export enum RequestRouterRegion { export type RequestRouterTarget = 'api' | 'ui' | 'assets' const ingestionDomain = 'i.posthog.com' + export class RequestRouter { instance: PostHog private _regionCache: Record = {} From 427499d91661e5e3bbd4393235a28594ef141dd3 Mon Sep 17 00:00:00 2001 From: Ben White Date: Mon, 18 Mar 2024 09:45:21 +0100 Subject: [PATCH 3/3] Fix tests --- src/__tests__/posthog-core.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/__tests__/posthog-core.js b/src/__tests__/posthog-core.js index 8c3d1f173..c8c65cd4c 100644 --- a/src/__tests__/posthog-core.js +++ b/src/__tests__/posthog-core.js @@ -1125,16 +1125,16 @@ describe('posthog core', () => { }) it('returns the replay URL', () => { - expect(given.lib.get_session_replay_url()).toEqual('https://app.posthog.com/replay/sessionId') + expect(given.lib.get_session_replay_url()).toEqual('https://us.posthog.com/replay/sessionId') }) it('returns the replay URL including timestamp', () => { expect(given.lib.get_session_replay_url({ withTimestamp: true })).toEqual( - 'https://app.posthog.com/replay/sessionId?t=20' // default lookback is 10 seconds + 'https://us.posthog.com/replay/sessionId?t=20' // default lookback is 10 seconds ) expect(given.lib.get_session_replay_url({ withTimestamp: true, timestampLookBack: 0 })).toEqual( - 'https://app.posthog.com/replay/sessionId?t=30' + 'https://us.posthog.com/replay/sessionId?t=30' ) }) })