@@ -24,7 +24,6 @@ export class AdvertisingIdPlugin extends Plugin {
2424 isLimitAdTracking ?: boolean = undefined ;
2525
2626 configure ( analytics : SegmentClient ) : void {
27- console . log ( 'configure' ) ;
2827 if ( Platform . OS !== 'android' ) {
2928 return ;
3029 }
@@ -41,36 +40,46 @@ export class AdvertisingIdPlugin extends Plugin {
4140 }
4241
4342 async execute ( event : SegmentEvent ) {
43+ // Exit early for non-Android platforms
44+ if ( Platform . OS !== 'android' ) {
45+ return event ;
46+ }
47+
4448 // If advertisingId is not set, queue the event
4549 if ( this . advertisingId === undefined ) {
4650 this . queuedEvents . push ( event ) ;
47- } else {
48- // Send event if advertisingId is available
49- const currentLimitAdTrackingStatus =
50- await this . fetchLimitAdTrackingStatus ( ) ;
51- if ( this . isLimitAdTracking === undefined ) {
52- this . isLimitAdTracking = currentLimitAdTrackingStatus ;
53- } else if ( this . isLimitAdTracking !== currentLimitAdTrackingStatus ) {
54- //Fetch the fresh advertising id
55- await this . fetchAdvertisingInfo ( )
56- . then ( ( ) => {
57- console . log (
58- 'Advertising info fetched successfully when adTrackingStatus Changed.'
59- ) ;
60- // Additional logic after the advertising info is fetched
61- } )
62- . catch ( ( error ) => {
63- this . handleError ( error ) ;
64- } ) ;
65- this . queuedEvents . push ( event ) ;
66- this . isLimitAdTracking = currentLimitAdTrackingStatus ;
67- this . sendQueued ( ) ;
68- return ;
69- }
51+ return ;
52+ }
53+
54+ // Check current Limit Ad Tracking status
55+ const currentLimitAdTrackingStatus =
56+ await this . fetchLimitAdTrackingStatus ( ) ;
57+
58+ // Initialize tracking status if undefined
59+ if ( this . isLimitAdTracking === undefined ) {
60+ this . isLimitAdTracking = currentLimitAdTrackingStatus ;
7061 return event ;
7162 }
7263
73- return ;
64+ // If tracking status has changed, refresh ad info and queue event
65+ if ( this . isLimitAdTracking !== currentLimitAdTrackingStatus ) {
66+ try {
67+ await this . fetchAdvertisingInfo ( ) ;
68+ console . log (
69+ 'Advertising info fetched successfully when adTrackingStatus Changed.'
70+ ) ;
71+ } catch ( error ) {
72+ this . handleError ( error ) ;
73+ }
74+
75+ this . queuedEvents . push ( event ) ;
76+ this . isLimitAdTracking = currentLimitAdTrackingStatus ;
77+ this . sendQueued ( ) ;
78+ return ;
79+ }
80+
81+ // Default return
82+ return event ;
7483 }
7584
7685 isTrackEvent ( event : SegmentEvent ) : event is TrackEventType {
0 commit comments