@@ -59,8 +59,6 @@ function initOneSignal(): void {
5959 if ( storedExternalUserId ) {
6060 void OneSignal . login ( storedExternalUserId ) ;
6161 }
62-
63- console . log ( `OneSignal initialized with app ID: ${ RESOLVED_APP_ID } ` ) ;
6462}
6563initOneSignal ( ) ;
6664
@@ -91,6 +89,7 @@ export type UseOneSignalReturn = {
9189 consentRequired : boolean ;
9290 privacyConsentGiven : boolean ;
9391 externalUserId : string | undefined ;
92+ oneSignalId : string | undefined ;
9493 pushSubscriptionId : string | undefined ;
9594 isPushEnabled : boolean ;
9695 hasNotificationPermission : boolean ;
@@ -151,6 +150,7 @@ export function useOneSignal(): UseOneSignalReturn {
151150 preferences . getConsentGiven ( ) ,
152151 ) ;
153152 const [ externalUserId , setExternalUserId ] = useState < string | undefined > ( undefined ) ;
153+ const [ oneSignalId , setOneSignalId ] = useState < string | undefined > ( undefined ) ;
154154 const [ pushSubscriptionId , setPushSubscriptionId ] = useState < string | undefined > ( undefined ) ;
155155 const [ isPushEnabled , setIsPushEnabled ] = useState ( false ) ;
156156 const [ hasNotificationPermission , setHasNotificationPermission ] = useState ( false ) ;
@@ -208,22 +208,6 @@ export function useOneSignal(): UseOneSignalReturn {
208208
209209 const handleNotificationClick = ( e : NotificationClickEvent ) => {
210210 console . log ( `Notification click: ${ e . notification . title ?? '' } ` ) ;
211- // Persist to localStorage so cold-start clicks are still inspectable
212- // after the Safari Web Inspector reattaches to the WKWebView.
213- try {
214- const existing = JSON . parse ( localStorage . getItem ( 'lastNotificationClicks' ) ?? '[]' ) ;
215- existing . push ( {
216- notificationId : e . notification . notificationId ,
217- title : e . notification . title ?? null ,
218- body : e . notification . body ?? null ,
219- actionId : e . result . actionId ?? null ,
220- url : e . result . url ?? null ,
221- receivedAt : new Date ( ) . toISOString ( ) ,
222- } ) ;
223- localStorage . setItem ( 'lastNotificationClicks' , JSON . stringify ( existing . slice ( - 20 ) ) ) ;
224- } catch ( err ) {
225- console . warn ( 'Failed to persist notification click to localStorage' , err ) ;
226- }
227211 } ;
228212
229213 const handleForegroundWillDisplay = ( e : NotificationWillDisplayEvent ) => {
@@ -257,6 +241,8 @@ export function useOneSignal(): UseOneSignalReturn {
257241 `User changed: onesignalId=${ nextOnesignalId ?? 'null' } , externalId=${ event . current . externalId ?? 'null' } ` ,
258242 ) ;
259243
244+ setOneSignalId ( nextOnesignalId ?? undefined ) ;
245+
260246 if ( nextOnesignalId === null ) return ;
261247 void fetchUserDataFromApi ( ) ;
262248 } ;
@@ -283,6 +269,7 @@ export function useOneSignal(): UseOneSignalReturn {
283269 if ( cancelled ) return ;
284270
285271 setExternalUserId ( externalId ?? preferences . getExternalUserId ( ) ?? undefined ) ;
272+ setOneSignalId ( initialOnesignalId ?? undefined ) ;
286273 setPushSubscriptionId ( pushId ?? undefined ) ;
287274 setIsPushEnabled ( pushOptedIn ) ;
288275 setHasNotificationPermission ( hasPerm ) ;
@@ -550,6 +537,7 @@ export function useOneSignal(): UseOneSignalReturn {
550537 consentRequired,
551538 privacyConsentGiven,
552539 externalUserId,
540+ oneSignalId,
553541 pushSubscriptionId,
554542 isPushEnabled,
555543 hasNotificationPermission,
0 commit comments