fix: iOS losing integrations on Setup #295
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
Sometimes, mainly on iOS, I'm losing the integration with some libs, like AppsFlyer or Firebase.
We set up as described on device-mode doc but sometimes the received payload on Segment was missing some of the defined integrations.
example of a correct payload passing
using: [AppsFlyer, Firebase]
:As described on the issue #61 those event informations were being lost and I could find the root cause of the problem.
Wrong Behavior
Debugging I found some intermittent behaviour in this part of the code
This code is using the RNAnalyticsIntegrations to add on integration factories to
SEGAnalyticsConfiguration
.This is a
static NSMutableSet
and it is updated when this integrations are setup.analytics-react-native/packages/core/ios/RNAnalytics/RNAnalytics.m
Line 18 in 40683c7
Setup Method Examples
AppsFlyer
Facebook
However, sometimes the method RNAnalytics.setup is called before RNAnalyticsIntegrations being updated.
I put out some logs while debugging the code and could find that this happens:
Logs added:
RNAnalytics.m, ln 24
RNAnalytics.m, ln 105
Hypothesis
My hypothesis was that the following part of the RN code is not waiting correctly for all integrations to be called.
analytics-react-native/packages/core/src/configuration.ts
Lines 36 to 40 in e522f6e
I confirmed it putting a sleep on Firebase setup and could check that the code wasn't waiting for all promises to be resolved to continue the execution, so causing the bug.
Fix
Looking on React Native doc I found something about ReactModules and Promises, I made this change on iOS and start to working well. I tested with
5 seconds
on Firebase setup and still working.https://reactnative.dev/docs/0.62/native-modules-ios#promises
Android
I made the change just for iOS because It's our main problem and I'm more comfortable to test.
But it is easy to do the same thing on Android side. Just follow this doc: https://reactnative.dev/docs/native-modules-android#promises