Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 34 additions & 25 deletions packages/plugins/plugin-advertising-id/src/AdvertisingIdPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export class AdvertisingIdPlugin extends Plugin {
isLimitAdTracking?: boolean = undefined;

configure(analytics: SegmentClient): void {
console.log('configure');
if (Platform.OS !== 'android') {
return;
}
Expand All @@ -41,36 +40,46 @@ export class AdvertisingIdPlugin extends Plugin {
}

async execute(event: SegmentEvent) {
// Exit early for non-Android platforms
if (Platform.OS !== 'android') {
return event;
}

// If advertisingId is not set, queue the event
if (this.advertisingId === undefined) {
this.queuedEvents.push(event);
} else {
// Send event if advertisingId is available
const currentLimitAdTrackingStatus =
await this.fetchLimitAdTrackingStatus();
if (this.isLimitAdTracking === undefined) {
this.isLimitAdTracking = currentLimitAdTrackingStatus;
} else if (this.isLimitAdTracking !== currentLimitAdTrackingStatus) {
//Fetch the fresh advertising id
await this.fetchAdvertisingInfo()
.then(() => {
console.log(
'Advertising info fetched successfully when adTrackingStatus Changed.'
);
// Additional logic after the advertising info is fetched
})
.catch((error) => {
this.handleError(error);
});
this.queuedEvents.push(event);
this.isLimitAdTracking = currentLimitAdTrackingStatus;
this.sendQueued();
return;
}
return;
}

// Check current Limit Ad Tracking status
const currentLimitAdTrackingStatus =
await this.fetchLimitAdTrackingStatus();

// Initialize tracking status if undefined
if (this.isLimitAdTracking === undefined) {
this.isLimitAdTracking = currentLimitAdTrackingStatus;
return event;
}

return;
// If tracking status has changed, refresh ad info and queue event
if (this.isLimitAdTracking !== currentLimitAdTrackingStatus) {
try {
await this.fetchAdvertisingInfo();
console.log(
'Advertising info fetched successfully when adTrackingStatus Changed.'
);
} catch (error) {
this.handleError(error);
}

this.queuedEvents.push(event);
this.isLimitAdTracking = currentLimitAdTrackingStatus;
this.sendQueued();
return;
}

// Default return
return event;
}

isTrackEvent(event: SegmentEvent): event is TrackEventType {
Expand Down
Loading