mixpanel/mixpanel-swift

Problem with reset()

Closed this issue · 5 comments

Hello!

I’m using mixpanel to track the users in my Swift app, but i must handle more than one user in the same device and i’m having some issues with the reset method.

The first thing i do when a user gets registered is an to create an alias using a uniqueId generated by my API as the alias and the uniqueID generated by mixpanel as the distinctID.
After this process, the user logs in the app and i perform an identify using only the uniqueID generated by my API (the same as in the register) and I can track all the events correctly.

The peoblem is that this user logs out, i do a reset and when a new user logs in i do an identify using the uniqueid generated by my api (that is diferent of the uniqueid generated for the first user) and then mixpanel joins both users into the same one merging the properties.

Is this a bug with the reset method or should i call some other method?

I was reading this article https://mixpanel.com/blog/2015/09/21/community-tip-maintaining-user-identity/ and it seems that i shouldn’t do anything else.

Thanks and best regards!

wgins commented

Hi @llKoull!

After calling reset() you should immediately generate a new UUID (or other unique identifier) and pass that value into the identify() method. What sounds like might be going on is that you're aliasing the identifier of the "second" user to the distinct_id of the previous user and tying two identities together.

If generating a new UUID immediately after calling reset() doesn't do the trick, would you mind writing into support@mixpanel.com? A member of our Support Engineering team can take a look at how you're handling user identity and get to the bottom of the discrepancy.

Thanks!

kuzdu commented

FYI: Android hasn't this problem. The Android Mixpanel always creates a distinct id automatically after reset.

I generate a UUID like this and it works.

func logout() {
        Mixpanel.mainInstance().reset()
        Mixpanel.mainInstance().identify(distinctId: UUID().uuidString)
    }

This says the Mixpanel documentation

 /**
     Clears all stored properties including the distinct Id.
     Useful if your app's user logs out.
     */
    open func reset() {

So I'm a little bit confused. Mixpanel cleans everything and use the same distinct Id again?
Why it's the client's job to generate a UUID?

However, the workaround works.

I think this should be written on the document, it could affect our data if users try to login and logout with other accounts

You could add a flag called 'MIXPANEL_RANDOM_DISTINCT_ID' in the compilation flags for Mixpanel framework. This ensures that every time you call the reset() function, a unique distinct_id is created. Checkout https://developer.mixpanel.com/docs/swift#section-call-reset-on-logout

Mixpanel should definitely put this in the user implementation guide as it's quite important for correct identity tracking.

Using 2.6.8, I've tried setting the preprocessor flag w/ no luck. Calling reset() never changes the stored distinctId

Edit: I mistakenly set the flag in the Preprocessor Macros and not in Active Complication Conditions. Works fine now!