From 867e52afb8239eed5d7112a36d74e34d9aed6e9f Mon Sep 17 00:00:00 2001 From: Sunita Prajapati <> Date: Wed, 23 Oct 2024 12:08:08 +0530 Subject: [PATCH] fix: advertising id being sent for Android application installed events --- .../src/AdvertisingIdPlugin.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/plugins/plugin-advertising-id/src/AdvertisingIdPlugin.ts b/packages/plugins/plugin-advertising-id/src/AdvertisingIdPlugin.ts index 612fcba1..b16c28af 100644 --- a/packages/plugins/plugin-advertising-id/src/AdvertisingIdPlugin.ts +++ b/packages/plugins/plugin-advertising-id/src/AdvertisingIdPlugin.ts @@ -5,6 +5,7 @@ import { getNativeModule, ErrorType, SegmentError, + SegmentEvent } from '@segment/analytics-react-native'; import { Platform, NativeModule } from 'react-native'; @@ -15,6 +16,8 @@ type AdvertisingIDNativeModule = NativeModule & { export class AdvertisingIdPlugin extends Plugin { type = PluginType.enrichment; + queuedEvents: SegmentEvent[] = []; + advertisingId?: string = undefined; configure(analytics: SegmentClient): void { if (Platform.OS !== 'android') { @@ -34,6 +37,7 @@ export class AdvertisingIdPlugin extends Plugin { 'LimitAdTrackingEnabled (Google Play Services) is enabled' ); } else { + this.advertisingId = id void this.setContext(id); } }) @@ -48,6 +52,16 @@ export class AdvertisingIdPlugin extends Plugin { }); } + execute(event: SegmentEvent){ + + if (this.advertisingId === undefined) { + this.queuedEvents.push(event); + }else{ + return event; + } + return; + } + async setContext(id: string): Promise { try { await this.analytics?.context.set({ @@ -56,6 +70,7 @@ export class AdvertisingIdPlugin extends Plugin { adTrackingEnabled: true, }, }); + this.sendQueued(); } catch (error) { const message = 'AdvertisingID failed to set context'; this.analytics?.reportInternalError( @@ -64,4 +79,11 @@ export class AdvertisingIdPlugin extends Plugin { this.analytics?.logger.warn(`${message}: ${JSON.stringify(error)}`); } } + + sendQueued() { + this.queuedEvents.forEach(event => { + void this.analytics?.process(event); + }); + this.queuedEvents = []; + } }