Skip to content

Commit

Permalink
Fix to include project in urls
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Mar 28, 2024
1 parent 174f83b commit afd77b9
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 @@ -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'
)
})
})
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 @@ -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 })
Expand Down
2 changes: 1 addition & 1 deletion src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit afd77b9

Please sign in to comment.