Depending on the audience for your app (e.g. children) or the countries where you sell your app (e.g. the EU), you may need to offer the ability for users to opt-out of analytics data collection inside your app. You can turn off forwarding to ALL destinations including Segment itself:
(Source – Segment docs)
import*asSegmentfrom'expo-analytics-segment';Segment.setEnabledAsync(false);// Or if they opt-back-in, you can re-enable data collection:Segment.setEnabledAsync(true);
Note: disabling the Segment SDK ensures that all data collection method invocations (eg. track, identify, etc) are ignored.
This method is only supported in standalone and detached apps. In Expo Go the promise will reject.
The setting value will be persisted across restarts, so once you call setEnabledAsync(false), Segment won't track the users even when the app restarts. To check whether tracking is enabled, use Segment.getEnabledAsync() which returns a promise which should resolve to a boolean.