Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change userTraits after the user logout and login with another account #104

Open
taham8875 opened this issue Oct 8, 2024 · 2 comments

Comments

@taham8875
Copy link

taham8875 commented Oct 8, 2024

The goal is to change the user traits when the user logout from his account (for example user1) and login into another account (for example user2) when this happend the same traits of the previous user is used, the only way to reset it is to close and reopen the app

How i identify the user

When the app boots or after a successful login I execute this code

    userTraits = UserTraits(
      name: user.name,
      phone: user.phone,
    );

    segment.identify(
      userId: user.id.toString(),
      userTraits: userTraits,
    );

this code works fine but once, when something changes related to the user (logout and login with different account), re-excuting this not affecting the traits, the only way is to close and reopen the app to be able to set the traits to the new data, how to change the user traits when needed?

What I have tried to achieve this

I have tried all of these in my logout method but failed

  1. use segment.reset();

  2. re-identify the user with null user traits values,

    segment.identify(
      userId: user.id.toString(),
      userTraits: null,
    );
  1. re-identify the user with user traits with null values,
    userTraits = UserTraits(
      name: null,
      phone: null,
    );

    segment.identify(
      userId: user.id.toString(),
      userTraits: userTraits,
    );

as mentioned before, recalling this code with the new user data not affecting his traits

    userTraits = UserTraits(
      name: user.name,
      phone: user.phone,
    );

    segment.identify(
      userId: user.id.toString(),
      userTraits: userTraits,
    );
@edsonjab
Copy link
Contributor

edsonjab commented Oct 9, 2024

Hi @taham8875 thank you for your report. I did this exercise:

image

  1. I press User 1 button and set a new userTraits.
  2. I press User 2 button and show the same userTraits that button 'User 1'.
  3. I press Reset button and clear userTraits.
  4. I press User 2 button and it display the userTraits with 'null' value.

Maybe is a simple example but you can have an idea about how you need organize the flow execution of your code.

@taham8875
Copy link
Author

@edsonjab

I tried all of this, unfortunately, still not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants