-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstrumentation-client.ts
More file actions
50 lines (45 loc) · 1.5 KB
/
instrumentation-client.ts
File metadata and controls
50 lines (45 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import posthog from "posthog-js";
import { POSTHOG_KEY, getPageType, shouldTrackPath } from "@/lib/posthog-config";
if (POSTHOG_KEY) {
posthog.init(POSTHOG_KEY, {
api_host: "/ingest",
ui_host: "/ingest",
person_profiles: "identified_only",
capture_exceptions: true,
disable_session_recording: true,
autocapture: false,
capture_pageleave: false,
capture_pageview: "history_change",
debug: process.env.NODE_ENV === "development",
defaults: "2026-01-30",
persistence: "sessionStorage",
before_send: (event) => {
if (typeof window !== "undefined" && !shouldTrackPath(window.location.pathname)) {
return null;
}
if (!event) {
return event;
}
delete event.properties["$ip"];
delete event.properties["$browser_language"];
delete event.properties["$timezone"];
delete event.properties["$raw_user_agent"];
delete event.properties["$screen_height"];
delete event.properties["$screen_width"];
delete event.properties["$viewport_height"];
delete event.properties["$viewport_width"];
if (typeof window !== "undefined" && event.event === "$pageview") {
event.properties = {
...event.properties,
page_type: getPageType(window.location.pathname),
};
}
return event;
},
loaded: (instance) => {
if (typeof window !== "undefined" && !shouldTrackPath(window.location.pathname)) {
instance.opt_out_capturing();
}
},
});
}