From e57dea508cb2d62ca315c6627a0096a999e89a21 Mon Sep 17 00:00:00 2001 From: thesunita <31236585+thesunita@users.noreply.github.com> Date: Wed, 23 Oct 2024 14:24:28 +0530 Subject: [PATCH] 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 <> --- .../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 = []; + } }