@@ -28,6 +28,7 @@ export function initializePostHog() {
2828 api_host : apiHost ,
2929 ui_host : uiHost ,
3030 disable_session_recording : false ,
31+ capture_exceptions : true ,
3132 loaded : ( ) => {
3233 log . info ( "PostHog loaded" ) ;
3334 // Start session recording immediately after load
@@ -88,13 +89,19 @@ export function identifyUser(
8889 userId : string ,
8990 properties ?: UserIdentifyProperties ,
9091) {
91- if ( ! isInitialized ) return ;
92+ if ( ! isInitialized ) {
93+ log . warn ( "PostHog not initialized, cannot identify user" ) ;
94+ return ;
95+ }
9296
9397 posthog . identify ( userId , properties ) ;
9498}
9599
96100export function resetUser ( ) {
97- if ( ! isInitialized ) return ;
101+ if ( ! isInitialized ) {
102+ log . warn ( "PostHog not initialized, cannot reset user" ) ;
103+ return ;
104+ }
98105
99106 posthog . reset ( ) ;
100107}
@@ -107,6 +114,45 @@ export function track<K extends keyof EventPropertyMap>(
107114 ? [ properties ?: EventPropertyMap [ K ] ]
108115 : [ properties : EventPropertyMap [ K ] ]
109116) {
110- if ( ! isInitialized ) return ;
117+ if ( ! isInitialized ) {
118+ log . warn ( "PostHog not initialized, cannot track event" ) ;
119+ return ;
120+ }
121+
111122 posthog . capture ( eventName , args [ 0 ] ) ;
112123}
124+
125+ /**
126+ * Capture an exception for error tracking using PostHog's built-in exception tracking.
127+ */
128+ export function captureException (
129+ error : Error ,
130+ additionalProperties ?: Record < string , unknown > ,
131+ ) {
132+ if ( ! isInitialized ) {
133+ log . warn ( "PostHog not initialized, cannot capture exception" ) ;
134+ return ;
135+ }
136+
137+ posthog . captureException ( error , additionalProperties ) ;
138+ }
139+
140+ /**
141+ * Get the PostHog instance for direct access
142+ */
143+ export function getPostHog ( ) {
144+ return isInitialized ? posthog : null ;
145+ }
146+
147+ // ============================================================================
148+ // Surveys
149+ // ============================================================================
150+
151+ export function displaySurvey ( surveyId : string ) {
152+ if ( ! isInitialized ) {
153+ log . warn ( "PostHog not initialized, cannot display survey" ) ;
154+ return ;
155+ }
156+
157+ posthog . displaySurvey ( surveyId ) ;
158+ }
0 commit comments