Skip to content

Commit e57dea5

Browse files
authored
fix: advertising id being sent for Android application installed events using analytics-react-native-plugin-advertsing-id (#1015)
* fix: to show 'Queue restoration timeout' only once * fix: advertising id being sent for Android application installed events --------- Co-authored-by: Sunita Prajapati <>
1 parent 1706ac5 commit e57dea5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

packages/plugins/plugin-advertising-id/src/AdvertisingIdPlugin.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
getNativeModule,
66
ErrorType,
77
SegmentError,
8+
SegmentEvent
89
} from '@segment/analytics-react-native';
910

1011
import { Platform, NativeModule } from 'react-native';
@@ -15,6 +16,8 @@ type AdvertisingIDNativeModule = NativeModule & {
1516

1617
export class AdvertisingIdPlugin extends Plugin {
1718
type = PluginType.enrichment;
19+
queuedEvents: SegmentEvent[] = [];
20+
advertisingId?: string = undefined;
1821

1922
configure(analytics: SegmentClient): void {
2023
if (Platform.OS !== 'android') {
@@ -34,6 +37,7 @@ export class AdvertisingIdPlugin extends Plugin {
3437
'LimitAdTrackingEnabled (Google Play Services) is enabled'
3538
);
3639
} else {
40+
this.advertisingId = id
3741
void this.setContext(id);
3842
}
3943
})
@@ -48,6 +52,16 @@ export class AdvertisingIdPlugin extends Plugin {
4852
});
4953
}
5054

55+
execute(event: SegmentEvent){
56+
57+
if (this.advertisingId === undefined) {
58+
this.queuedEvents.push(event);
59+
}else{
60+
return event;
61+
}
62+
return;
63+
}
64+
5165
async setContext(id: string): Promise<void> {
5266
try {
5367
await this.analytics?.context.set({
@@ -56,6 +70,7 @@ export class AdvertisingIdPlugin extends Plugin {
5670
adTrackingEnabled: true,
5771
},
5872
});
73+
this.sendQueued();
5974
} catch (error) {
6075
const message = 'AdvertisingID failed to set context';
6176
this.analytics?.reportInternalError(
@@ -64,4 +79,11 @@ export class AdvertisingIdPlugin extends Plugin {
6479
this.analytics?.logger.warn(`${message}: ${JSON.stringify(error)}`);
6580
}
6681
}
82+
83+
sendQueued() {
84+
this.queuedEvents.forEach(event => {
85+
void this.analytics?.process(event);
86+
});
87+
this.queuedEvents = [];
88+
}
6789
}

0 commit comments

Comments
 (0)