11import 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" ;
26import type {
37 EventPropertyMap ,
48 UserIdentifyProperties ,
59} from "../../types/analytics" ;
10+ import { logger } from "./logger" ;
11+
12+ const log = logger . scope ( "analytics" ) ;
613
714let 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+
3290export function identifyUser (
3391 userId : string ,
3492 properties ?: UserIdentifyProperties ,
0 commit comments