identify method

Future<void> identify(
  1. String distinctId, {
  2. String? email,
  3. String? name,
  4. String? phone,
  5. Map<String, Object?>? traits,
})

Identify the current end-user. All subsequent telemetry is attributed to it.

Implementation

Future<void> identify(
  String distinctId, {
  String? email,
  String? name,
  String? phone,
  Map<String, Object?>? traits,
}) async {
  _id.distinctId = distinctId;
  if (traits != null) _id.traits.addAll(traits);
  if (email != null) _id.email = email;
  if (name != null) _id.name = name;
  if (phone != null) _id.phone = phone;
  // Remember the user on device so future launches restore this identity
  // instead of starting anonymous (see NexusIdentity + Nexus._loadIdentity).
  await IdentityStore.save(
    distinctId: distinctId,
    email: _id.email,
    name: _id.name,
    phone: _id.phone,
    traits: _id.traits,
  );
  await _http.post('/partner/sessions/identify', {
    'distinctId': distinctId,
    'email': ?email,
    'name': ?name,
    'phone': ?phone,
    'traits': ?traits,
  });
  await track();
}