From afd77b9bd37c68ddf3838f62f932220f8137eff1 Mon Sep 17 00:00:00 2001 From: Ben White Date: Thu, 28 Mar 2024 15:58:25 +0100 Subject: [PATCH] Fix to include project in urls --- src/__tests__/posthog-core.js | 8 +++++--- src/extensions/exception-autocapture/index.ts | 5 ++++- src/extensions/sentry-integration.ts | 5 ++++- src/posthog-core.ts | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/__tests__/posthog-core.js b/src/__tests__/posthog-core.js index 83bac25e4..222d756c4 100644 --- a/src/__tests__/posthog-core.js +++ b/src/__tests__/posthog-core.js @@ -1122,16 +1122,18 @@ 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://app.posthog.com/project/testtoken/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://app.posthog.com/project/testtoken/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://app.posthog.com/project/testtoken/replay/sessionId?t=30' ) }) }) diff --git a/src/extensions/exception-autocapture/index.ts b/src/extensions/exception-autocapture/index.ts index 6288098d1..6b021b6f1 100644 --- a/src/extensions/exception-autocapture/index.ts +++ b/src/extensions/exception-autocapture/index.ts @@ -128,7 +128,10 @@ export class ExceptionObserver { const propertiesToSend = { ...properties, ...errorProperties } const posthogHost = this.instance.requestRouter.endpointFor('ui') - errorProperties.$exception_personURL = posthogHost + '/person/' + this.instance.get_distinct_id() + + errorProperties.$exception_personURL = `${posthogHost}/project/${ + this.instance.config.token + }/person/${this.instance.get_distinct_id()}` this.sendExceptionEvent(propertiesToSend) } diff --git a/src/extensions/sentry-integration.ts b/src/extensions/sentry-integration.ts index 73d160c01..cf021f51f 100644 --- a/src/extensions/sentry-integration.ts +++ b/src/extensions/sentry-integration.ts @@ -64,7 +64,10 @@ export class SentryIntegration implements _SentryIntegration { if (event.level !== 'error' || !_posthog.__loaded) return event if (!event.tags) event.tags = {} - const personUrl = _posthog.requestRouter.endpointFor('ui', '/person/' + _posthog.get_distinct_id()) + const personUrl = _posthog.requestRouter.endpointFor( + 'ui', + `/project/${_posthog.config.token}/person/${_posthog.get_distinct_id()}` + ) event.tags['PostHog Person URL'] = personUrl if (_posthog.sessionRecordingStarted()) { event.tags['PostHog Recording URL'] = _posthog.get_session_replay_url({ withTimestamp: true }) diff --git a/src/posthog-core.ts b/src/posthog-core.ts index 357fdca1a..29ae301be 100644 --- a/src/posthog-core.ts +++ b/src/posthog-core.ts @@ -1405,7 +1405,7 @@ export class PostHog { return '' } const { sessionId, sessionStartTimestamp } = this.sessionManager.checkAndGetSessionAndWindowId(true) - let url = this.requestRouter.endpointFor('ui', '/replay/' + sessionId) + let url = this.requestRouter.endpointFor('ui', `/project/${this.config.token}/replay/${sessionId}`) if (options?.withTimestamp && sessionStartTimestamp) { const LOOK_BACK = options.timestampLookBack ?? 10 if (!sessionStartTimestamp) {