Identify people

You need to identify a person using a mobile device before you can send them messages or track events for things they do in your app. You need the Tracking package to identify people.

 Our mobile SDKs are in alpha and subject to change

While we’re very excited about our mobile SDKs, they’re still works in progress! If you want to try them out, contact product@customer.io

This page is part of an introductory series to help you get started with the essential features of our SDK. The highlighted step(s) below are covered on this page. Before you continue, make sure you've implemented previous features—i.e. you can't identify people before you initialize the SDK!

graph LR getting-started(Install SDK) -->B(Initialize SDK) B --> identify(identify people) identify -.-> track-events(Send events) identify -.-> push(Receive push) identify -.-> rich-push(Receive Rich Push) track-events --> testing-error-handling(handle errors) push --> testing-error-handling rich-push --> testing-error-handling click getting-started href "/docs/sdk/ios/getting-started" click B href "/docs/sdk/ios/getting-started/#initialize-the-sdk" click identify href "/docs/sdk/ios/identify" click track-events href "/docs/sdk/ios/track-events/" click push href "/docs/sdk/ios/push" click rich-push href "/docs/sdk/ios/rich-push" click testing-error-handling href "/docs/sdk/ios/testing-error-handling" style identify fill:#B5FFEF,stroke:#007069

Identify a person

When you identify a customer, you:

  1. Add or update the person in your workspace. This is basically the same as an identify call to our server-side API.
  2. Save the person’s information on the device. Future calls to the SDK reference the identified person. For example, after you identify a person, any events that you track are automatically associated with that person.

You can only identify one customer at a time. The SDK “remembers” the most recently-identified customer. If you identify person A, and then call the identify function for person B, the SDK “forgets” person A and assumes that person B is the current app user. You can also stop identifying a person, which you might do when someone logs off or stops using your app for a significant period of time.

Learn more about the Tracking class.

An identify request takes the following parameters:

import CioTracking
CustomerIO.shared.identify(identifier: "989388339", body: ["first_name": firstName]) { [weak self] result in
    // We recommend that you use `[weak self]` in the callback, but your app's use cases may be unique. 
    guard let self = self else { return }
    
    switch result {
    case .success: 
      // Customer successfully identified in your Workspace!
      break 
    case .failure(let customerIOError):
      // Error occurred. You should parse `customerIOError` to learn more about the error.
      break 
    }
}

// `body` accepts a dictionary or an `Encodable` object 
// 1. dictionary:
let body = ["first_name": "Dana", "last_name": "Green"]
CustomerIO.shared.identify(identifier: "989388339", body: body)
// 2. `Encodable` object:
struct IdentifyRequestBody: Encodable {
  let firstName: String
  let lastName: String
}
CustomerIO.shared.identify(identifier: "989388339", body: IdentifyRequestBody(firstName: "Dana", lastName: "Green"))
See Error handling for help parsing the CustomerIOError.

Update a person’s attributes

You store information about a person in Customer.io as attributesA key-value pair that you associate with a person—like their name, the date they were created in your workspace, etc. Use attributes to target people and personalize messages.. When you call the identify() function, you can update a person’s attributes on the server-side.

If a person is already identified, and then updates their preferences, provides additional information about themselves, or performs other attribute-changing actions, you can call identify() again to update their attributes on the server-side.

Stop identifying a person

When a person logs out, or does something else to tell you that they no longer want to be tracked, you should stop identifying them.

Use clearIdentify() to stop identifying the previously identified person (if there was one).

// Calls to the Customer.io SDK will be ignored until you identify a new person. 
CustomerIO.shared.clearIdentify()

Identify a different person

If you want to identify a new person—like when someone switches profiles on a streaming app, etc—you can simply call identify() for the new person. The new person then becomes the currently-identified person, with whom all new information—messages, events, etc—is associated.

Copied to clipboard!