segmentio / analytics-react-native

The hassle-free way to add analytics to your React-Native app.
https://segment.com/docs/sources/mobile/react-native/
MIT License
367 stars 191 forks source link

fix: remove void promises from appsflyer plugin #1025

Open lennartschoch opened 1 week ago

lennartschoch commented 1 week ago

Hi there!

Opening a PR here to solve an issue we've been having when trying to integrate with the Segment Appsflyer plugin. We're running an Expo app using React Native 0.74.5 with Hermes.

When adding the plugin to our Segment instance (and going through the rest of the integration steps as described in the documentation), we'd see the attribution data on Appsflyer, together with all of our Segment tracking events, indicating the integration went well. What was missing, though, were the Install Attributed and Organic Install events on Segment. Interestingly, this was only the case on production builds, development clients were working just fine.

After diving into this issue, I figured out that the onInstallConversionData callback is called as expected with the right data, but the analytics.track calls for emitting those missing events never end up getting called.

I ended up patching the library on our side, adding .then handler to the track() calls, which suddenly made the Install events appear on Segment.

My hypothesis is that Hermes does some sort of performance optimization on production builds that keeps it from calling the promises all together, thinking they are not in use because of the lack of a promise handler (like then or catch). I used the then handler for an info log, but technically the content of it shouldn't matter here.

I'd love to get this merged so that we can remove the patch from our repo! Let me know what you think :)

seg-atlantis-prod[bot] commented 1 week ago

Atlantis commands can't be run on fork pull requests. To enable, set --allow-fork-prs or, to disable this message, set --silence-fork-pr-errors

seg-atlantis-prod[bot] commented 1 week ago
Error parsing command: EOF found when expecting closing quote