:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(replay): exclude JSON-LD URLs from navigation tracking (#97344)
Robbie17e4e5c8d0ac
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/README.md b/nodejs/src/ingestion/pipelines/sessionreplay/README.mdindex 0b6e3f6398a9..3c2beadac7ee 100644--- a/nodejs/src/ingestion/pipelines/sessionreplay/README.md+++ b/nodejs/src/ingestion/pipelines/sessionreplay/README.md@@ -13,6 +13,15 @@ The `SessionRecordingIngester` consumes session recording events from Kafka and:- **Extracts console logs** for separate storage and search- **Handles failures** via dead letter queue and overflow topics+## Navigation URLs++Navigation URL extraction ignores `$json_ld` custom events, so their URLs do not add page visits or clear pending dead-click detection.+Other events retain the existing extraction behavior: read `data.href`, then fall back to `data.payload.href`.+This includes the `$pageview` and `$url_changed` custom events used for SPA navigation.++The ML mirror extracts URL metadata separately through the native anonymizer.+A URL on a mirrored JSON-LD event identifies its page; it does not represent a navigation.+## Local Development### Prerequisitesdiff --git a/nodejs/src/ingestion/pipelines/sessionreplay/rrweb-types.ts b/nodejs/src/ingestion/pipelines/sessionreplay/rrweb-types.tsindex 1da601ea760a..bb6a292aa522 100644--- a/nodejs/src/ingestion/pipelines/sessionreplay/rrweb-types.ts+++ b/nodejs/src/ingestion/pipelines/sessionreplay/rrweb-types.ts@@ -118,7 +118,12 @@ export function isMouseActivity(inputEvent: SnapshotEvent): boolean {}export function hrefFrom(inputEvent: SnapshotEvent): string | undefined {- const event = inputEvent as { type?: number; data?: { href?: string; payload?: { href?: string } } } | undefined+ const event = inputEvent as+ | { type?: number; data?: { tag?: string; href?: string; payload?: { href?: string } } }+ | undefined+ if (event?.type === RRWebEventType.Custom && event.data?.tag === '$json_ld') {+ return undefined+ }const metaHref = event?.data?.href?.trim?.()const customHref = event?.data?.payload?.href?.trim?.()return metaHref || customHref || undefineddiff --git a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-feature-recorder.test.ts b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-feature-recorder.test.tsindex 56899b027b2a..818ea4e09dfb 100644--- a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-feature-recorder.test.ts+++ b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-feature-recorder.test.ts@@ -795,17 +795,66 @@ describe('SessionFeatureRecorder', () => {expect(result.quickBackCount).toBe(0)})- it('should set urlChangedSinceLastClick to allow dead click detection to be cleared', () => {- // Click, then navigation, then another click => first click should NOT be dead+ it.each([+ {+ name: 'Meta',+ type: RRWebEventType.Meta,+ data: { href: ' https://example.com/page2 ' },+ navigation: true,+ },+ {+ name: 'SPA pageview',+ type: RRWebEventType.Custom,+ data: { tag: '$pageview', payload: { href: ' https://example.com/page2 ' } },+ navigation: true,+ },+ {+ name: 'SPA URL change',+ type: RRWebEventType.Custom,+ data: { tag: '$url_changed', payload: { href: 'https://example.com/page2' } },+ navigation: true,+ },+ {+ name: 'JSON-LD URL',+ type: RRWebEventType.Custom,+ data: { tag: '$json_ld', href: 'https://example.com/page2', payload: {} },+ navigation: false,+ },+ {+ name: 'JSON-LD payload URL',+ type: RRWebEventType.Custom,+ data: { tag: '$json_ld', payload: { href: 'https://example.com/page2' } },+ navigation: false,+ },+ {+ name: 'other custom URL',+ type: RRWebEventType.Custom,+ data: { tag: 'other', payload: { href: 'https://example.com/page2' } },+ navigation: true,+ },+ {+ name: 'non-custom event URL',+ type: RRWebEventType.IncrementalSnapshot,+ data: { href: 'https://example.com/page2' },+ navigation: true,+ },+ ])('tracks navigation URLs while excluding JSON-LD: $name', ({ type, data, navigation }) => {const events = [+ makeNavigationEvent(500, 'https://example.com/'),makeClickEvent(1000),- makeNavigationEvent(2000, 'https://example.com/page2'),+ { type, timestamp: 2000, data } as unknown as SnapshotEvent,makeClickEvent(5000),]recorder.recordMessage(createMessage(events))const result = recorder.end()!- expect(result.deadClickCount).toBe(0)+ expect(result.pageVisitCount).toBe(navigation ? 2 : 1)+ expect(result.deadClickCount).toBe(navigation ? 0 : 1)+ expect(result.visitedUrls).toEqual(+ navigation+ ? [md5Hex('https://example.com/'), md5Hex('https://example.com/page2')]+ : [md5Hex('https://example.com/')]+ )})})