You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems like at this point, where plugins are being added in the forEeach, and since at least AdvertisingIdPlugin is async, the manual flush from this.store.pendingEvents including the event Application Installed is being executed before finishing adding all plugins.
this.checkInstalledVersion() is being called here, where Application Installed event is created internally. However, since this.isReady.value is not yet set to true, the event is added to a store of pending events here.
Then await this.onReady() is being called, during which the plugins are being added. Inside a forEach, this.addPlugin(plugin) is executed for each plugin. In the case of the plugin AdvertisingIdPlugin it should be done async since the plugin itself is async. And not synchronously as it's done in the forEeachhere.
Finally, the list of pending events is being processed and a manual flush is performed to trigger them here.
So there may be a case where AdvertisingIdPlugin has not been added yet, including its context with an advertisingId and pending events like Application Installed were flushed, resulting in these first events being sent without its corresponding advertisingId.
// this prevents this block running for every update
this.pluginsToAdd=[];
}finally{
this.isAddingPlugins=false;
}
by:
try {
// start by adding the plugins
for (const plugin of this.pluginsToAdd) {
await this.addPlugin(plugin);
}
// now that they're all added, clear the cache
// this prevents this block running for every update
this.pluginsToAdd = [];
} finally {
this.isAddingPlugins = false;
}
Thanks for the analysis @maurispalletti ! Yes, it seems that configure in the plugin is of async nature given that clearly it needs to communicate with the native layer. That part can be seen here:
Updated issue:
There is an issue in the
analytics-react-native-plugin-advertising-id
(https://github.com/segmentio/analytics-react-native/tree/master/packages/plugins/plugin-advertising-id) where its functioning defers from the Android native implementation.When the the event
Application Installed
is triggered, it is missing theadvertisingId
value.Why is this happening?
It seems like at this point, where plugins are being added in the
forEeach
, and since at leastAdvertisingIdPlugin
is async, the manual flush fromthis.store.pendingEvents
including the eventApplication Installed
is being executed before finishing adding all plugins.analytics-react-native/packages/core/src/analytics.ts
Lines 478 to 508 in c1a0957
So, the current process follows this sequence:
this.checkInstalledVersion()
is being called here, whereApplication Installed
event is created internally. However, sincethis.isReady.value
is not yet set totrue
, the event is added to a store of pending events here.await this.onReady()
is being called, during which the plugins are being added. Inside a forEach,this.addPlugin(plugin)
is executed for each plugin. In the case of the pluginAdvertisingIdPlugin
it should be done async since the plugin itself is async. And not synchronously as it's done in theforEeach
here.So there may be a case where
AdvertisingIdPlugin
has not been added yet, including its context with anadvertisingId
and pending events likeApplication Installed
were flushed, resulting in these first events being sent without its correspondingadvertisingId
.Proposed fix
Replace:
analytics-react-native/packages/core/src/analytics.ts
Lines 482 to 493 in c1a0957
by:
Details
analytics-react-native
version: 2.17.0analytics-react-native-plugin-advertising-id
: 1.3.1Steps to reproduce
Application Installed
events on Segment.Expected behavior
Application Installed
events from Android should haveadvertisingId
.Actual behavior
Application Installed
events from Android actually haveadvertisingId
.The text was updated successfully, but these errors were encountered: