analytics-react-native icon indicating copy to clipboard operation
analytics-react-native copied to clipboard

Ability to programmatically disable

Open imjared opened this issue 1 year ago • 2 comments

In #757, the user wanted to disable Segment in order to respect user preferences. In my use case, we get information about the user at run time that determines if we should or shouldn't track them.

Because the client gets initialized at app load, before user data is fetched, we aren't able to disable immediately. I'd love to be able to do something like:

const segment = useAnalytics();
if (user.type === "non_trackable") {
  segment.settings.set({ debug: true/false });
}

A similar behavior seems to exist in Analytics.js (link) so this doesn't seem out of the question. I know it's been flagged as a wontfix but the feature parity would be nice.

imjared avatar Jul 30 '24 16:07 imjared

BUMP. Currently having our logs flooded by Flush triggered but queue restoration and settings loading not complete. Flush will be retried.

Would be great to have a simple "enabled: true"

pTinosq avatar Aug 16 '24 10:08 pTinosq

Flush....

same -> what is this about?

stevenmathers avatar Feb 20 '25 03:02 stevenmathers

@imjared : Starting from v2.21.0, Segment can be disabled by adding segmentClient.enabled.set(true/false).

sunitaprajapati89 avatar May 01 '25 03:05 sunitaprajapati89

@sunitaprajapati89 Thanks for the update. Just to confirm, setting this enabled value to true will disable it?

imjared avatar May 01 '25 10:05 imjared

@imjared : enabled as the name says if its true means it is enabled and will track events and false will disable it.

sunitaprajapati89 avatar May 01 '25 12:05 sunitaprajapati89