matomo-org / matomo-sdk-android

SDK for Android to measure your apps with Matomo. Works on Android phones, tablets, Fire TV sticks, and more!
BSD 3-Clause "New" or "Revised" License
386 stars 163 forks source link

setOptOut clears dispatecher each time the method is invoked #474

Closed lorenc-tomasz closed 4 months ago

lorenc-tomasz commented 4 months ago

Hi, each time setOptOut method is invoked the dispatcher queue is cleared.

    /**
     * Use this to disable this Tracker, e.g. if the user opted out of tracking.
     * The Tracker will persist the choice and remain disable on next instance creation.<p>
     *
     * @param optOut true to disable reporting
     */
    public void setOptOut(boolean optOut) {
        mOptOut = optOut;
        getPreferences().edit().putBoolean(PREF_KEY_TRACKER_OPTOUT, optOut).apply();
        mDispatcher.clear();
    }

When app has switch that enable / disable event tracking we can loose events history. Example scenario:

  1. App collected many events during last 1 minute.
  2. Uses goes to settings.
  3. User disables tracking. setOptOut is invoked. Dispatcher is cleared.
  4. User enables tracking. setOptOut is invoked. Dispatcher is cleared.
  5. User disables tracking. setOptOut is invoked. Dispatcher is cleared.
  6. User enables tracking. setOptOut is invoked. Dispatcher is cleared.
  7. No events to dispatch.

In that case user still allows tracking but we lost all collected events.

I think it should work this way:

  1. App collected many events during last 1 minute.
  2. Uses goes to settings.
  3. User disables tracking. setOptOut is invoked. Events collecting is disabled. Next event will not be collected.
  4. User enables tracking. setOptOut is invoked. Events collecting is enabled. Next event will be collected.
  5. User disables tracking. setOptOut is invoked. Events collecting is disabled. Next event will not be collected.
  6. User enables tracking. setOptOut is invoked. Events collecting is enabled. Next event will be collected.
  7. All collected events when user allowed to be tracked are dispatched.

I think this is the way iOS SDK works at the moment.

hannesa2 commented 4 months ago

It's a bigger question. When the user disable tracking, does this mean from now on, or all past and from now on. And what's past ? Just local, non-sent, or even the ones on backend ?

I can't answer it, I just have the power to merge pull requests.