amplitude / Amplitude-Android

Native Android SDK for Amplitude
MIT License
164 stars 90 forks source link

AmplitudeClient.setOptOut Doesn't Work #381

Open gusuly0rum opened 1 year ago

gusuly0rum commented 1 year ago

Expected Behavior

Calling amplitudeClient.setOptOut(true) should make amplitudeClient.isOptedOut return true.

Current Behavior

Calling amplitudeClient.isOptedOut always returns false despite calling amplitudeClient.setOptOut(true).

Images

Amplitude client is initialized as such

@Provides
@Singleton
fun provideAmplitudeClient(): AmplitudeClient {
    return Amplitude.getInstance()
        .setLogLevel(Log.VERBOSE)
        .setFlushEventsOnClose(false)
        .setOptOut(true)
}
image image image

Environment

yuhao900914 commented 1 year ago

Hi @gusuly0rum, Thanks for choosing Amplitude. The setOptOut still works fine. The issue is that the isOptedOut return value is incorrect. We will fix this issue soon.

yuhao900914 commented 1 year ago

@gusuly0rum After investigation, this bug is caused by the setOptOut is executed in Runnable at here. All runnable will be executed in order, this makes sure the logEvent happens after setOptOut will get the correct optOut value. But since the isOptOut get the optOut value immediately, it may happen before setOptOut. Again, the setOptOut still works fine. The issue is that the isOptedOut return value might be incorrect.

Since this SDK is in Maintenance mode. We highly recommend you upgrade your SDK to our latest android SDK. It's more reliable and has better performance.

gusuly0rum commented 1 year ago

@yuhao900914 Thanks for letting me know. Yes we want to upgrade to the new SDK soon but there are some features not supported.

justin-fiedler commented 1 year ago

Thank you @gusuly0rum. What features do you need that are missing in the new SDK?

gusuly0rum commented 1 year ago

Hello seems like it is missing two things:

  1. Setting isOffline (true/false) on the amplitude object
  2. Dynamically changing the value of setOptOut (true/false) after initializing the amplitude object