# 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 **CioDataPipelines** package to identify people.

## Identify a person[](#identify)

Identifying a person:

1.  Adds or updates the person in your workspace. This is basically the same as an [`identify` call to our server-side API](/api/#operation/identify).
2.  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.
3.  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](/integrations/sdk/ios/push/push-setup/) 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](#clearIdentify), 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:

*   **userId** (required): The unique value representing a person—an ID or email address that represents a person in Customer.io (and your downstream destinations).
*   **traits** (Optional): Contains [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.](/journeys/attributes/) that you want to set for a person. [https://customer.io/api/track/#operation/identify](https://customer.io/api/track/#operation/identify)

```swift
import CioDataPipelines

CustomerIO.shared.identify(userId: "989388339", traits: ["first_name": firstName]) 

// `traits` accepts [String: Any] or an `Encodable` object 

// 1. [String: Any]:
let traits = ["first_name": "Dana", "last_name": "Green"]
CustomerIO.shared.identify(userId: "989388339", traits: traits)


// 2. `Encodable` object:
struct IdentifyRequestTraits: Encodable {
  let firstName: String
  let lastName: String 
}
CustomerIO.shared.identify(userId: "989388339", traits: IdentifyRequestTraits(firstName: "Dana", lastName: "Green"))
```

### Update a person’s attributes[](#identify-again)

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.](/journeys/attributes/). 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`.

```swift
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[](#device-attributes)

By default (if you don’t set `.autoTrackDeviceAttributes(false)` in your config), the SDK automatically collects a series of [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.](/journeys/attributes/) for each device. 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.](/journeys/data-driven-segments/) 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}}`.](/using-liquid) yet.

Along with these attributes, we automatically set a `last_used` timestamp for each device indicating when the device owner was last identified, and the `last_status` of a push notification you sent to the device. You can also set your own custom device attributes. You’ll see a person’s devices and each device’s attributes when you go to **Journeys > People > Select a person**, and click **Devices**.

[![device attributes on a person's profile](https://docs.customer.io/images/device-attributes.png)](#db82cfb11dbec1c42a9f938183dcedbd-lightbox)

 Your integration shows device attributes in the `context` object

When you inspect calls from the SDK (in your integration’s data inAn integration that feeds data *into* Customer.io. tab), you’ll see device information in the `context` object. We flatten the device attributes that you send into your workspace, so that they’re easier to use in [segmentsA segment is a group of people in your workspace. Use segments to trigger campaigns, track membership over time, or fine-tune your audience. There are two types of segments: data-driven and manual. Data-driven segments automatically update when people start or stop matching criteria. Manual segments are static.](/journeys/segments/). For example, `context.network.cellular` becomes `network_cellular`.

*   id string
    
    Required The device token.
    

#### Custom device attributes[](#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, time zone, or other custom values specific to the device.

```swift
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](#identify-again) rather than the device.

#### Disable automatic device attribute collection[](#disable-attributes)

By default, the SDK automatically collects the device attributes [defined above](#device-attributes). You can change your config to prevent the SDK from automatically collecting these attributes.

```swift
import CioDataPipelines

let config = SDKConfigBuilder(cdpApiKey: "YOUR_CDP_API_KEY")
            .migrationSiteId("YOUR_SITE_ID")
            .autoTrackDeviceAttributes(false)

CustomerIO.initialize(withConfig: config.build()) 
```

## Stop identifying a person[](#clearIdentify)

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).

```swift
// Future calls to the Customer.io SDK are anonymous 
CustomerIO.shared.clearIdentify()
```

### Identify a different person[](#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.