Skip to content

Commit f435428

Browse files
Drop PostHog autocapture events
1 parent 48eae3b commit f435428

3 files changed

Lines changed: 37 additions & 10 deletions

File tree

instrumentation-client.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import posthog from 'posthog-js'
2+
import { browserPostHogConfig } from 'src/lib/posthog-browser-config'
23

34
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY as string, {
45
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST as string,
5-
defaults: '2025-05-24',
6-
autocapture: false,
7-
capture_pageview: true,
8-
capture_pageleave: false,
9-
capture_performance: false,
6+
...browserPostHogConfig,
107
})

src/lib/posthog-browser-config.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { COPY_AUTOCAPTURE_EVENT, type CaptureResult, type PostHogConfig } from 'posthog-js'
2+
3+
const dropAutocaptureEvents = (event: CaptureResult | null) => {
4+
if (!event) {
5+
return event
6+
}
7+
8+
if (
9+
event.event === '$autocapture' ||
10+
event.event === COPY_AUTOCAPTURE_EVENT
11+
) {
12+
return null
13+
}
14+
15+
return event
16+
}
17+
18+
export const browserPostHogConfig: Pick<
19+
PostHogConfig,
20+
| 'autocapture'
21+
| 'before_send'
22+
| 'capture_pageleave'
23+
| 'capture_pageview'
24+
| 'capture_performance'
25+
| 'defaults'
26+
> = {
27+
defaults: '2025-05-24',
28+
autocapture: false,
29+
capture_pageview: true,
30+
capture_pageleave: false,
31+
capture_performance: false,
32+
before_send: dropAutocaptureEvents,
33+
}

src/pages/_app.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
Header,
3333
FeedbackButton,
3434
} from 'src/components'
35+
import { browserPostHogConfig } from 'src/lib/posthog-browser-config'
3536

3637
const openSansClassName = 'font-sans'
3738

@@ -56,11 +57,7 @@ function MaiaPlatform({ Component, pageProps }: AppProps) {
5657
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY as string, {
5758
api_host: '/ingest',
5859
ui_host: 'https://us.posthog.com',
59-
defaults: '2025-05-24',
60-
autocapture: false,
61-
capture_pageview: true,
62-
capture_pageleave: false,
63-
capture_performance: false,
60+
...browserPostHogConfig,
6461
capture_exceptions: true,
6562
debug: false,
6663
})

0 commit comments

Comments
 (0)