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
354 stars 181 forks source link

Disabling the Facebook App Events SDK for a specific build #930

Closed gbyesiltas closed 2 months ago

gbyesiltas commented 3 months ago

Summary

We have set-up the facebook app events plugin as per the docs. For now we want to only enable it in our staging app and not in the actual production app, and not in the app instances we build for End-to-end testing. However, simply not adding the facebook app events plugin doesn't seem to work (at least for Android).

From what I understand, the FB SDK is automatically initialized for Android. I have tried adding the meta-data that is supposed to turn that off to AndroidManifest but that didn't help either.

There is a closed issue about this here though the specific examples there are related to Expo which doesn't apply to us and honestly the issue was closed without a real conclusion :D

Is there a way to do this?

Screenshot 2024-03-19 at 17 58 11 Screenshot 2024-03-19 at 11 49 07 Screenshot_1710845354

oscb commented 3 months ago

Looks like this validation is happening in the FBSDK itself so it's not something we can control from our plugin. Do you want to fully remove it from the build or just not send any event to FB?

If it's the first one it might be an option in the native FB SDK to control this behavior: https://developers.facebook.com/docs/app-events/overview

If it's fine with just disabling Segment from sending events to FB this one is easier, you can keep the plugin there and add a plugin that filters FB if your app is in debug mode:

class FilterFBPlugin extends Plugin {
  type = Plugin.before

  execute(event: SegmentEvent) {
    if (!Config.FACEBOOK_APP_ID || !Config.FACEBOOK_CLIENT_TOKEN) {
       event.integrations['Facebook App Events'] = false;
    }
    return event;
  }
}

(If FB is automatically sending logs from your app outside of Segment this won't prevent those)

gbyesiltas commented 3 months ago

@oscb Hey thanks for the response :)

I have tried adding the meta properties from the FB documentation that I thought could be related to this to disable the auto-initialization, thinking that would fix the issue. But that didn't help unfortunately.

Otherwise, with the second approach, we will need to provide some APP_IDs and CLIENT_TOKENs even for our builds where we don't necessarily want logging and I was concerned about possible side-effects of that (maybe we provide just some mock ones? but again, I assume that may have other side-effects like errors trying to connect to the Facebook SDK).

I feel like at this point I've tried everything that I could think of to disable the initialisation from happening so I may just go with filtering out the events. Thank you for the suggestion!

gbyesiltas commented 2 months ago

Didn't quite end-up disabling the SDK at all, but I was able to resolve my issue by passing some mock APP_IDs etc. and filtering out the events as suggested here so closing the issue to not crowd-up the issues