Identify people
UpdatedThere's a new version available!
These pages cover version 2 of our SDK, but a newer version is available. In general, we suggest that you update to the latest version to take advantage of new features and fixes.
- Are you new to our SDKs? Check out the latest docs.
- Otherwise, learn about updating to the latest version
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.
This page is part of a setup flow for the SDK. Before you continue, make sure you've implemented previous features—i.e. you can't identify people before you initialize the SDK!
Device Token) register-token -.-> push(Receive push) register-token -.-> rich-push(Receive Rich Push) track-events --> test-support(Write tests) push --> test-support rich-push --> test-support identify -.-> in-app(Receive in-app) in-app --> test-support click getting-started href "/docs/sdk/ios/getting-started/#install" 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 register-token href "/docs/sdk/ios/push" click push href "/docs/sdk/ios/push" click rich-push href "/docs/sdk/ios/rich-push" click in-app href "/docs/sdk/ios/in-app" click test-support href "/docs/sdk/ios/test-support" style identify fill:#B5FFEF,stroke:#007069
Identify a person
Identifying a person:
- Adds or updates the person in your workspace. This is basically the same as an
identify
call to our server-side API. - Saves 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.
- If you already registered a device token, identifying a person automatically associates the token with the identified person. You can register for a device token before or after you identify a person. See our Push Documentation for help registering device tokens.
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.
An identify request takes the following parameters:
- identifier (required): The unique value representing a person—an ID, email address, or the cio_idAn identifier for a person that is automatically generated by Customer.io and cannot be changed. This identifier provides a complete, unbroken record of a person across changes to their other identifiers (id, email, etc). (when updating people), depending on your workspace settings.
- body (Optional): Contains attributes that you want to add to, or update on, a person. https://customer.io/docs/api/track/#operation/identify
import CioTracking
CustomerIO.shared.identify(identifier: "989388339", body: ["first_name": firstName])
// `body` accepts [String: Any] or an `Encodable` object
// 1. [String: Any]:
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"))
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 or an object—like a person’s name, the date they were created in your workspace, or a company’s billing date etc. Use attributes to target people and personalize messages. Attributes are analogous to traits in Data Pipelines.. 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 update their attributes with profileAttributes
.
CustomerIO.shared.profileAttributes = ["favorite_food": "pizza"]
You only need to pass the attributes that you want to create or modify to profileAttributes
. For example, if you identify a new person with the attribute ["first_name": "Dana"]
, and then you call CustomerIO.shared.profileAttributes = ["favorite_food": "pizza"]
after that, the person’s first_name
attribute will still be Dana
.
Device attributes
When you register a device token to a person, we automatically collect device attributesA key-value pair that you associate with a person or an object—like a person’s name, the date they were created in your workspace, or a company’s billing date etc. Use attributes to target people and personalize messages. Attributes are analogous to traits in Data Pipelines.. You can use these attributes in segmentsA group of people who match a series of conditions. People enter and exit the segment automatically when they match or stop matching conditions. and other campaign workflow conditions to target the device owner, just like you would use a person’s other attributes. You cannot, however, use device attributes to personalize messages with liquidA syntax that supports variables, letting you personalize messages for your audience. For example, if you want to reference a person’s first name, you might use the variable {{customer.first_name}}
. yet.
For each device, we automatically collect the device platform
attribute. Within your workspace, we also automatically set a last_used
timestamp indicating when the device owner was last identified, and the last_status
of a push notification you sent to the device. By default, we also automatically capture a series of attributes
, like the device’s operating system, model, push_enabled
preference. You can add custom attributes to the attributes
object.
- id stringRequired The device token.
-
- _last_status stringThe delivery status of the last message sent to the device—sent, bounced, or suppressed. An empty string indicates that that the device hasn’t received a push yet.
Accepted values:
,
bounced
,sent
,suppressed
- app_version stringThe version of your app that a customer uses. You might target app versions to let people know when they need to update, or expose them to new features when they do.
- cio_sdk_version stringThe version of the Customer.io SDK in the app.
- device_locale stringThe four-letter IETF language code for the device. For example,
en-MX
(indicating an app in Spanish formatted for a user in Mexico) ores-ES
(indicating an app in Spanish formatted for a user in Spain). - device_model stringThe model of the device a person uses.
- device_os stringThe operating system, including the version, on the device.
- push_enabled stringIf
"true"
, the device is opted-in and can receive push notifications.Accepted values:
true
,false
- Custom Device Attributes* stringCustom properties that you want to associate with the device.
- last_used integer (unix timestamp)The
timestamp
when you last identified this device. If you don’t pass a timestamp when you add or update a device, we use the time of the request itself. Our SDKs identify a device when a person launches their app. - platform stringRequired The device/messaging platform.
Accepted values:
ios
,android
Custom device attributes
When we collect device attributes, you can also set custom device attributes with the deviceAttributes
method. You might do this to save app preferences, timezone, or other custom values specific to the device.
CustomerIO.shared.deviceAttributes = ["company" : "cio", "checklist" : "complete"]
However, before you set custom device attributes, consider whether the attribute is specific to the device
or if it applies to the person broadly. Device tokens are ephemeral—they can change based on user behavior, like when a person uninstalls and reinstalls your app. If you want an attribute to persist beyond the life of the device, you should apply it to the person rather than the device.
Disable automatic device attribute collection
By default, the SDK automatically collects the device attributes defined above. You can change your config to prevent the SDK from automatically collecting these attributes.
CustomerIO.initialize(...) { config in
config.autoTrackDeviceAttributes = false
}
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).
// Future 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.