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
393 stars 164 forks source link

USER_ID can not be empty #203

Closed oscargrgm closed 6 years ago

oscargrgm commented 6 years ago

I'm using the version 2.0.0 of the Piwik SDK and trying to set the USER_ID of my Tracker as an empty String but it sets up automatically a random one.

This is my declaration:

public synchronized Tracker getInstance() {
    if (tracker == null) {
        TrackerConfig trackerConfig = new TrackerConfig("https://mywebpage.com", SITE_ID, "android-tracker");
        tracker = Piwik.getInstance(this).newTracker(trackerConfig);
    }
    tracker.setUserId("");
    tracker.getDefaultTrackMe().set(QueryParams.USER_ID, "");
    return tracker;
}

I've also tried to set it as empty inside the if condition but is not working either. Is there any way to do it?

d4rken commented 6 years ago

Why are you trying to do that?

The documentation states:

User ID is any non-empty unique string identifying the user (such as an email address or an username).

You can either remove it, or set it to something, "nothing" is not supported: https://github.com/matomo-org/piwik-sdk-android/blob/v2.0.0/piwik-sdk/src/main/java/org/piwik/sdk/TrackMe.java#L43

oscargrgm commented 6 years ago

The reason is we have defined a non-logged users system which have an empty USER_ID. I guess we should define another system and set a standard USER_ID for those non-logged users.

You can close the issue then. Thank you very much!

d4rken commented 6 years ago

Providing an empty user-id for all non-logged-in users, even it is accepted by the server, would aggregate all visits with empty "user id" as visits from the same user. So then in tracking you get many different logged-in users, but one huge "not-logged-in". I think this would make the statistics quite unusuable.

Being logged in or not should not change the user-id as it's still the same individual that might just have logged-in while using your app. It's more of a status, an attribute per user. I think I would do this via custom dimensions.

If you search for this, I'm sure this has come up before somewhere as this is not specific to apps and seems like something a lot of piwik/matomo users have thought about.