33// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
44
55import { AppState , type AppStateStatus } from 'react-native' ;
6- import { PassportReader } from 'react-native-passport-reader ' ;
6+ import { NativeModules } from 'react-native' ;
77import { ENABLE_DEBUG_LOGS , MIXPANEL_NFC_PROJECT_TOKEN } from '@env' ;
88import NetInfo from '@react-native-community/netinfo' ;
99import type { JsonMap , JsonValue } from '@segment/analytics-react-native' ;
@@ -161,32 +161,28 @@ export const cleanupAnalytics = () => {
161161const setupFlushPolicies = ( ) => {
162162 AppState . addEventListener ( 'change' , ( state : AppStateStatus ) => {
163163 if ( state === 'background' || state === 'active' ) {
164- flushMixpanelEvents ( ) . catch ( console . warn ) ;
164+ flushMixpanelEvents ( ) ;
165165 }
166166 } ) ;
167167
168168 NetInfo . addEventListener ( state => {
169169 isConnected = state . isConnected ?? true ;
170170 if ( isConnected ) {
171- flushMixpanelEvents ( ) . catch ( console . warn ) ;
171+ flushMixpanelEvents ( ) ;
172172 }
173173 } ) ;
174174} ;
175175
176- const flushMixpanelEvents = async ( ) => {
176+ const flushMixpanelEvents = ( ) => {
177177 if ( ! MIXPANEL_NFC_PROJECT_TOKEN ) return ;
178178 try {
179179 if ( __DEV__ ) console . log ( '[Mixpanel] flush' ) ;
180180 // Send any queued events before flushing
181181 while ( eventQueue . length > 0 ) {
182182 const evt = eventQueue . shift ( ) ! ;
183- if ( PassportReader . trackEvent ) {
184- await Promise . resolve (
185- PassportReader . trackEvent ( evt . name , evt . properties ) ,
186- ) ;
187- }
183+ NativeModules . PassportReader ?. trackEvent ?.( evt . name , evt . properties ) ;
188184 }
189- if ( PassportReader . flush ) await Promise . resolve ( PassportReader . flush ( ) ) ;
185+ NativeModules . PassportReader ? .flush ?. ( ) ;
190186 eventCount = 0 ;
191187 } catch ( err ) {
192188 if ( __DEV__ ) console . warn ( 'Mixpanel flush failed' , err ) ;
@@ -198,20 +194,20 @@ const flushMixpanelEvents = async () => {
198194} ;
199195
200196// --- Mixpanel NFC Analytics ---
201- export const configureNfcAnalytics = async ( ) => {
197+ export const configureNfcAnalytics = ( ) => {
202198 if ( ! MIXPANEL_NFC_PROJECT_TOKEN || mixpanelConfigured ) return ;
203199 const enableDebugLogs = JSON . parse ( String ( ENABLE_DEBUG_LOGS ) ) ;
204- if ( PassportReader . configure ) {
205- await Promise . resolve (
206- PassportReader . configure ( MIXPANEL_NFC_PROJECT_TOKEN , enableDebugLogs , {
207- flushInterval : 20 ,
208- flushCount : 5 ,
209- flushOnBackground : true ,
210- flushOnForeground : true ,
211- flushOnNetworkChange : true ,
212- } ) ,
213- ) ;
214- }
200+ NativeModules . PassportReader . configure (
201+ MIXPANEL_NFC_PROJECT_TOKEN ,
202+ enableDebugLogs ,
203+ {
204+ flushInterval : 20 ,
205+ flushCount : 5 ,
206+ flushOnBackground : true ,
207+ flushOnForeground : true ,
208+ flushOnNetworkChange : true ,
209+ } ,
210+ ) ;
215211 setupFlushPolicies ( ) ;
216212 mixpanelConfigured = true ;
217213} ;
@@ -226,30 +222,28 @@ export const flushAllAnalytics = () => {
226222 flushAnalytics ( ) ;
227223
228224 // Flush Mixpanel events
229- flushMixpanelEvents ( ) . catch ( console . warn ) ;
225+ flushMixpanelEvents ( ) ;
230226} ;
231227
232- export const trackNfcEvent = async (
228+ export const trackNfcEvent = (
233229 name : string ,
234230 properties ?: Record < string , unknown > ,
235231) => {
236232 if ( ! MIXPANEL_NFC_PROJECT_TOKEN ) return ;
237- if ( ! mixpanelConfigured ) await configureNfcAnalytics ( ) ;
233+ if ( ! mixpanelConfigured ) configureNfcAnalytics ( ) ;
238234
239235 if ( ! isConnected ) {
240236 eventQueue . push ( { name, properties } ) ;
241237 return ;
242238 }
243239
244240 try {
245- if ( PassportReader . trackEvent ) {
246- await Promise . resolve ( PassportReader . trackEvent ( name , properties ) ) ;
247- }
241+ NativeModules . PassportReader ?. trackEvent ?.( name , properties ) ;
248242 eventCount ++ ;
249243 if ( eventCount >= 5 ) {
250- flushMixpanelEvents ( ) . catch ( console . warn ) ;
244+ flushMixpanelEvents ( ) ;
251245 }
252- } catch {
246+ } catch ( err ) {
253247 eventQueue . push ( { name, properties } ) ;
254248 }
255249} ;
0 commit comments