Skip to content

Commit

Permalink
Fix to include project in urls (#1098)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored Apr 8, 2024
1 parent 70dbfa5 commit 55a7b95
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/__tests__/posthog-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1143,16 +1143,18 @@ describe('posthog core', () => {
})

it('returns the replay URL', () => {
expect(given.lib.get_session_replay_url()).toEqual('https://us.posthog.com/replay/sessionId')
expect(given.lib.get_session_replay_url()).toEqual(
'https://us.posthog.com/project/testtoken/replay/sessionId'
)
})

it('returns the replay URL including timestamp', () => {
expect(given.lib.get_session_replay_url({ withTimestamp: true })).toEqual(
'https://us.posthog.com/replay/sessionId?t=20' // default lookback is 10 seconds
'https://us.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://us.posthog.com/replay/sessionId?t=30'
'https://us.posthog.com/project/testtoken/replay/sessionId?t=30'
)
})
})
Expand Down
5 changes: 4 additions & 1 deletion src/extensions/exception-autocapture/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 4 additions & 1 deletion src/extensions/sentry-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ export class SentryIntegration implements _SentryIntegration {
if (!shouldProcessLevel || !_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 })
Expand Down
2 changes: 1 addition & 1 deletion src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,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) {
Expand Down

0 comments on commit 55a7b95

Please sign in to comment.