Skip to content
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

fix: Default api host to us.i.posthog.com #1087

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion playground/nextjs/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/posthog-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
})
})
Expand Down
6 changes: 3 additions & 3 deletions src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/utils/request-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export enum RequestRouterRegion {

export type RequestRouterTarget = 'api' | 'ui' | 'assets'

const ingestionDomain = 'i.posthog.com'

export class RequestRouter {
instance: PostHog
private _regionCache: Record<string, RequestRouterRegion> = {}
Expand Down Expand Up @@ -49,14 +51,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':
Expand Down
Loading