Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Commit a91d01f

Browse files
committed
fix: session replay works and links users
1 parent 1dda85f commit a91d01f

3 files changed

Lines changed: 76 additions & 6 deletions

File tree

apps/array/src/renderer/features/auth/stores/authStore.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,11 @@ export const useAuthStore = create<AuthState>()(
124124

125125
get().scheduleTokenRefresh();
126126

127-
// Track user login
128-
identifyUser(user.uuid, {
127+
// Track user login - use distinct_id to match web sessions (same as PostHog web app)
128+
const distinctId = user.distinct_id || user.email;
129+
identifyUser(distinctId, {
130+
email: user.email,
131+
uuid: user.uuid,
129132
project_id: projectId.toString(),
130133
region,
131134
});
@@ -135,8 +138,10 @@ export const useAuthStore = create<AuthState>()(
135138
});
136139

137140
trpcVanilla.analytics.setUserId.mutate({
138-
userId: user.uuid,
141+
userId: distinctId,
139142
properties: {
143+
email: user.email,
144+
uuid: user.uuid,
140145
project_id: projectId.toString(),
141146
region,
142147
},
@@ -309,14 +314,20 @@ export const useAuthStore = create<AuthState>()(
309314

310315
get().scheduleTokenRefresh();
311316

312-
identifyUser(user.uuid, {
317+
// Use distinct_id to match web sessions (same as PostHog web app)
318+
const distinctId = user.distinct_id || user.email;
319+
identifyUser(distinctId, {
320+
email: user.email,
321+
uuid: user.uuid,
313322
project_id: projectId.toString(),
314323
region: tokens.cloudRegion,
315324
});
316325

317326
trpcVanilla.analytics.setUserId.mutate({
318-
userId: user.uuid,
327+
userId: distinctId,
319328
properties: {
329+
email: user.email,
330+
uuid: user.uuid,
320331
project_id: projectId.toString(),
321332
region: tokens.cloudRegion,
322333
},

apps/array/src/renderer/lib/analytics.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import posthog from "posthog-js/dist/module.full.no-external";
2+
// Import the recorder to set up __PosthogExtensions__.initSessionRecording
3+
// The module.full.no-external bundle includes rrweb but not the initSessionRecording function
4+
// This import adds the missing piece needed for session replay in Electron
5+
import "posthog-js/dist/lazy-recorder";
26
import type {
37
EventPropertyMap,
48
UserIdentifyProperties,
59
} from "../../types/analytics";
10+
import { logger } from "./logger";
11+
12+
const log = logger.scope("analytics");
613

714
let isInitialized = false;
815

@@ -24,11 +31,62 @@ export function initializePostHog() {
2431
capture_pageleave: false,
2532
disable_session_recording: false,
2633
debug: true, // Enable debug mode for now (TODO: turn this off before launch)
34+
loaded: () => {
35+
log.info("PostHog loaded");
36+
// Log session recording status after remote config loads
37+
setTimeout(() => {
38+
logSessionRecordingStatus();
39+
}, 3000);
40+
},
2741
});
2842

2943
isInitialized = true;
3044
}
3145

46+
/**
47+
* Log the current session recording status for debugging
48+
*/
49+
export function logSessionRecordingStatus() {
50+
if (!isInitialized) {
51+
log.warn("PostHog not initialized");
52+
return;
53+
}
54+
55+
const sessionRecording = posthog.sessionRecording;
56+
const remoteConfig = posthog.get_property("$session_recording_remote_config");
57+
58+
log.info("Session Recording Debug:", {
59+
started: sessionRecording?.started,
60+
status: sessionRecording?.status,
61+
remoteConfigEnabled: remoteConfig?.enabled,
62+
remoteConfig,
63+
windowLocationHref: window.location?.href,
64+
configDisableSessionRecording: posthog.config?.disable_session_recording,
65+
});
66+
}
67+
68+
/**
69+
* Manually start session recording.
70+
* Use this to force start recording regardless of triggers.
71+
*/
72+
export function startSessionRecording() {
73+
if (!isInitialized) {
74+
log.warn("PostHog not initialized, cannot start session recording");
75+
return;
76+
}
77+
78+
log.info("Attempting to start session recording...");
79+
80+
// Use PostHog's startSessionRecording API which overrides triggers
81+
posthog.startSessionRecording();
82+
83+
// Log status after attempting to start
84+
setTimeout(() => {
85+
log.info("Session recording status after manual start:");
86+
logSessionRecordingStatus();
87+
}, 1000);
88+
}
89+
3290
export function identifyUser(
3391
userId: string,
3492
properties?: UserIdentifyProperties,

apps/array/src/types/analytics.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ export interface RepositorySelectProperties {
5353
}
5454

5555
export interface UserIdentifyProperties {
56-
user_id?: string;
56+
email?: string;
57+
uuid?: string;
5758
project_id?: string;
5859
region?: string;
5960
}

0 commit comments

Comments
 (0)