Skip to content

Commit 7128ea4

Browse files
authored
ENG-1630 - add posthog disable_session_recording (#949)
* ENG-1650: Update PostHog initialization settings in posthog.ts - Set `autocapture` to false and `disable_session_recording` to true for improved data privacy. - Adjusted user identification to use `window.roamAlphaAPI.user.uid()` for consistency. - Changed session registration method to `register_for_session` for better session management. * . * ENG-1651: Improve user identification in PostHog initialization - Updated the user identification logic to only call `posthog.identify` if a valid user UID is present, enhancing data accuracy and preventing unnecessary calls.
1 parent ab00780 commit 7128ea4

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

apps/roam/src/utils/posthog.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import getCurrentUserUid from "roamjs-components/queries/getCurrentUserUid";
21
import { getVersionWithDate } from "./getVersion";
32
import posthog from "posthog-js";
43
import type { CaptureResult } from "posthog-js";
@@ -21,8 +20,10 @@ const doInitPostHog = (): void => {
2120
"$referrer",
2221
"$referring_domain",
2322
]);
23+
/* eslint-disable @typescript-eslint/naming-convention */
2424
posthog.init("phc_SNMmBqwNfcEpNduQ41dBUjtGNEUEKAy6jTn63Fzsrax", {
25-
/* eslint-disable @typescript-eslint/naming-convention */
25+
autocapture: false,
26+
disable_session_recording: true,
2627
api_host: "https://us.i.posthog.com",
2728
person_profiles: "identified_only",
2829
capture_pageview: false,
@@ -37,16 +38,12 @@ const doInitPostHog = (): void => {
3738
}
3839
return result;
3940
},
40-
/* eslint-enable @typescript-eslint/naming-convention */
41-
autocapture: false,
4241
loaded: (posthog) => {
4342
const { version, buildDate } = getVersionWithDate();
44-
const userUid = getCurrentUserUid();
43+
const userUid = window.roamAlphaAPI.user.uid() || "";
4544
const graphName = window.roamAlphaAPI.graph.name;
46-
posthog.identify(userUid, {
47-
graphName,
48-
});
49-
posthog.register({
45+
if (userUid) posthog.identify(userUid);
46+
posthog.register_for_session({
5047
version: version || "-",
5148
buildDate: buildDate || "-",
5249
graphName,
@@ -55,6 +52,7 @@ const doInitPostHog = (): void => {
5552
initialized = true;
5653
},
5754
});
55+
/* eslint-enable @typescript-eslint/naming-convention */
5856
};
5957

6058
export const enablePostHog = (): void => {

0 commit comments

Comments
 (0)