Steps to reproduce
- Create a Segment client and add a custom
WaitingPlugin that simulates async init (sets an id after 10s, then calls resume()):
import { createClient } from '@segment/analytics-react-native';
import { AppsFlyerIntegrationPlugin } from './AppsFlyerPlugin';
export const segmentClient = createClient({
writeKey: '...',
trackAppLifecycleEvents: true,
debug: true,
});
segmentClient.add({ plugin: new AppsFlyerIntegrationPlugin() });
import {
PluginType,
SegmentClient,
type SegmentEvent,
WaitingPlugin,
} from '@segment/analytics-react-native';
export class AppsFlyerIntegrationPlugin extends WaitingPlugin {
type = PluginType.enrichment;
private appsFlyerId = 'EMPTY';
configure = (analytics: SegmentClient) => {
super.configure(analytics);
// simulate long delay
delay(10_000).then(() => {
console.log('[AppsFlyer] set id', 'CORRECT_APPSFLYER_ID');
this.appsFlyerId = 'CORRECT_APPSFLYER_ID';
void this.resume();
});
};
execute = (event: SegmentEvent): SegmentEvent => {
const name = 'event' in event ? event.event : event.type;
console.log('[AppsFlyer] execute', this.appsFlyerId, event.type, name);
return {
...event,
integrations: {
...event.integrations,
AppsFlyer: {
appsFlyerId: this.appsFlyerId,
},
},
};
};
}
function delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
- Launch the app (lifecycle events like
Application Opened / identify fire automatically).
- After the plugin resumes, trigger any later event (e.g. a button click).
Expected behavior
Events should be buffered until resume() is called. After the id is set and resume() runs, buffered and subsequent events should execute with the correct id:
[AppsFlyer] set id CORRECT_APPSFLYER_ID
[AppsFlyer] execute CORRECT_APPSFLYER_ID track Application Opened
[AppsFlyer] execute CORRECT_APPSFLYER_ID identify identify
[AppsFlyer] execute CORRECT_APPSFLYER_ID track Button Clicked
Actual behavior
Events are processed immediately, before resume():
[AppsFlyer] execute EMPTY track Application Opened
[AppsFlyer] execute EMPTY identify identify
[AppsFlyer] set id CORRECT_APPSFLYER_ID
[AppsFlyer] execute CORRECT_APPSFLYER_ID track Button Clicked
Checked on both: 2.24.0 and 2.23.0
- "@segment/analytics-react-native": "2.24.0",
- "@segment/sovran-react-native": "1.1.4",
- Integrations versions (if used):
@segment/analytics-react-native-plugin-firebase 0.4.3 (not required for the repro)
- React Native version:
0.81.5
- iOS or Android or both? iOS
Steps to reproduce
WaitingPluginthat simulates async init (sets an id after 10s, then callsresume()):Application Opened/identifyfire automatically).Expected behavior
Events should be buffered until
resume()is called. After the id is set andresume()runs, buffered and subsequent events should execute with the correct id:Actual behavior
Events are processed immediately, before
resume():Checked on both: 2.24.0 and 2.23.0
@segment/analytics-react-native-plugin-firebase0.4.3(not required for the repro)0.81.5