Skip to content

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

@taham8875

Description

@taham8875

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,
    );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions