# Audience Management Integrate audience management features into your app. This guide covers how to identify contacts, access channel IDs, and set tags, attributes, and subscription lists on channels and contacts. For information about using these features for segmentation and targeting, see the [Audience User Guide]({{< ref "/guides/audience/segmentation/segmentation.md" >}}). # Channels > Access and manage channel IDs, listen for channel creation, and configure the channel capture tool. Each device/app install will generate a unique identifier known as the Channel ID. Once a Channel ID is created, it will persist in the application until the app is reinstalled, or has its internal data is cleared. If `AirshipMessageCenter` is installed, the SDK will attempt to restore the Channel ID across app reinstalls. For information about finding Channel IDs, using the Channel Capture tool, and other methods to access Channel IDs, see [Finding Channel IDs](https://www.airship.com/docs/guides/getting-started/developers/identifiers/). ## Accessing the Airship Channel ID Apps can access the Channel ID directly through the SDK. #### Swift ```swift let channelID = Airship.channel.identifier ``` #### Objective-C ```objc NSString *channelID = UAirship.channel.identifier; ``` The Channel ID is asynchronously created, so it may not be available right away on the first run. Changes to Channel data will automatically be batched and applied when the Channel is created, so there is no need to wait for the Channel to be available before modifying any data. Applications that need to access the Channel ID can use a listener to be notified when it is available. #### Swift Using `identifierUpdates` (AsyncStream): ```swift Task { for await channelID in Airship.channel.identifierUpdates { print("Channel ID: \(channelID)") } } ``` Using `NotificationCenter`: ```swift NotificationCenter.default.addObserver( self, selector: #selector(refreshView), name: AirshipNotifications.ChannelCreated.name, object: nil ) ``` #### Objective-C Using `NotificationCenter`: ```objc [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshView) name:UAirshipNotificationChannelCreated.name object:nil]; ``` ## Channel Capture tool The Channel Capture tool is a feature built into the SDK that helps users find their Channel ID. For detailed information about how it works and how to use it, see [Finding Channel IDs](https://www.airship.com/docs/guides/getting-started/developers/identifiers/). The Channel Capture tool can be disabled through the Airship Config options passed to `takeOff` during SDK initialization. For information about setting up the Airship SDK and configuring `AirshipConfig`, see [iOS SDK Setup](https://www.airship.com/docs/developer/sdk-integration/apple/installation/getting-started/). #### Swift ```swift config.isChannelCaptureEnabled = false ``` #### Objective-C ```objc config.isChannelCaptureEnabled = NO; ``` ## Delaying channel creation Airship creates the channel if at least one feature is enabled in the Privacy Manager. To delay channel creation, use the Privacy Manager to disable all features during takeOff. For more information about Privacy Manager, see [Privacy Manager](https://www.airship.com/docs/developer/sdk-integration/apple/data-collection/privacy-manager/). # Contacts > Identify contacts, reset contacts, and get named user IDs. A Contact is any user in your project. Contacts are identified as either an Anonymous Contact or a Named User. Airship can set targeting data on these identifiers, which are also used to map devices and channels to a specific user. For detailed information about contacts and named users, see [Named users](https://www.airship.com/docs/guides/audience/named-users/). ## Managing the Contact's identifier (Named User ID) Identify can be called multiple times with the same Named User ID. The SDK will automatically deduplicate `identify` calls made with the same Named User ID. If the ID is changed from a previous value, the Contact will automatically be dissociated from the previous Named User ID. #### Swift ```swift Airship.contact.identify("some named user ID") ``` #### Objective-C ```objective-c [UAirship.contact identify:@"some named user ID"]; ``` If the user logs out of the device, you may want to reset the contact. This will clear any anonymous data and dissociate the contact from the Named User ID, if set. This should only be called when the user manually logs out of the app, otherwise you will not be able to target the Channel by its Contact data. #### Swift ```swift Airship.contact.reset() ``` #### Objective-C ```objc [UAirship.contact reset]; ``` You can get the Named User ID only if you set it through the SDK. #### Swift ```swift await Airship.contact.namedUserID ``` #### Objective-C ```objc [UAirship.contact getNamedUserIDWithCompletionHandler:^(NSString *namedUserID) { }]; ``` ### Email channel association When an email address is registered through the SDK, it will be registered for both transactional and commercial emails by default. To change this behavior, you can override the options to request [[Double Opt-In](https://www.airship.com/docs/reference/glossary/#double_opt_in)](https://www.airship.com/docs/developer/api-integrations/email/getting-started/#double-opt-in) for commercial messages. #### Swift ```swift let options = EmailRegistrationOptions.commercialOptions( transactionalOptedIn: transactionalDate, commercialOptedIn: commercialDate, properties: properties ) Airship.contact.registerEmail("your@example.com", options: options) ``` #### Objective-C ```objc UAEmailRegistrationOptions* options = [UAEmailRegistrationOptions commercialOptionsWithTransactionalOptedIn:transactionalDate commercialOptedIn:commercialDate properties:properties]; [UAirship.contact registerEmail:@"your@example.com" options:options]; ``` ### SMS channel association When an [MSISDN](https://www.airship.com/docs/reference/glossary/#msisdn) is registered through the SDK, Airship sends a message to that number, prompting them to opt in. For more information, see the SMS platform documentation: [Non-Mobile Double Opt-In](https://www.airship.com/docs/developer/api-integrations/sms/opt-in-out-handling/#non-mobile-double-opt-in). #### Swift ```swift let options = SMSRegistrationOptions.optIn(senderID: "senderId") Airship.contact.registerSMS("yourMsisdn", options: options) ``` #### Objective-C ```objc UASMSRegistrationOptions* options = [UASMSRegistrationOptions optInSenderID:@"senderId"]; [UAirship.contact registerSMS:"yourMsisdn" options:options]; ``` ### Open Channel association Open Channels support notifications to any medium that can accept a JSON payload, through either the Airship API or web dashboard. For more information about Open Channels, see the [Open Channels documentation](https://www.airship.com/docs/developer/api-integrations/open/getting-started/). #### Swift ```swift let options = OpenRegistrationOptions.optIn(platformName: "platformName", identifiers: identifiers) Airship.contact.registerOpen("address", options: options) ``` #### Objective-C ```objc UAOpenRegistrationOptions* options = [UAOpenRegistrationOptions optInSenderID:@"platformName"]; [UAirship.contact registerOpen:"address" options:options]; ``` # Tags > Set device tags, contact tags, and tag groups for audience segmentation. For information about tags, including how to use them for segmentation and targeting, see the [Tags user guide](https://www.airship.com/docs/guides/audience/tags/). ## Channel Tags Channel tags are tags managed on the Channel by the SDK. Device tags (tags without a group) can be modified or fetched from the Channel. #### Swift ```swift Airship.channel.editTags { editor in editor.set(["one", "two", "three"]) editor.add("a_tag") editor.remove("three") } // Accessing channel tags let tags = Airship.channel.tags ``` #### Objective-C ```objc [UAirship.channel editTags:^(UATagEditor *editor) { [editor setTags:@[@"one", @"two", @"three"]]; [editor addTag:@"a_tag"]; [editor removeTag:@"three"]; }]; // Accessing channel tags NSArray* tags = [[UAirship channel] tags]; ``` ## Channel Tag Groups Tag groups are tags scoped within a group. Tag groups can be modified from the SDK but cannot be fetched. Device tags (tags without a group) can be fetched. If you need to be able to fetch tag groups, consider using subscription lists. #### Swift ```swift Airship.channel.editTagGroups { editor in editor.add(["silver-member", "gold-member"], group:"loyalty") editor.remove(["bronze-member", "club-member"], group:"loyalty") editor.set(["bingo"], group:"games") } ``` #### Objective-C ```objc [UAirship.channel editTagGroups:^(UATagGroupsEditor *editor) { [editor addTags:@[@"silver-member", @"gold-member"] group:@"loyalty"]; [editor removeTags:@[@"bronze-member", @"club-member"] group:@"loyalty"]; [editor setTags:@[@"bingo"] group:@"games"]; }]; ``` ## Contact Tag Groups Contact tag groups are tags scoped within a group at the Contact level. Tag groups can be modified from the SDK but cannot be fetched. If you need to be able to fetch tag groups, consider using subscription lists. #### Swift ```swift Airship.contact.editTagGroups { editor in editor.add(["silver-member", "gold-member"], group:"loyalty") editor.remove(["bronze-member", "club-member"], group:"loyalty") editor.set(["bingo"], group:"games") } ``` #### Objective-C ```objc [UAirship.contact editTagGroups:^(UATagGroupsEditor *editor) { [editor addTags:@[@"silver-member", @"gold-member"] group:@"loyalty"]; [editor removeTags:@[@"bronze-member", @"club-member"] group:@"loyalty"]; [editor setTags:@[@"bingo"] group:@"games"]; }]; ``` ## Verifying Tags To verify that tags have been set correctly, look up the channel or contact in the [Contact Management](https://www.airship.com/docs/guides/audience/contact-management/) view. You can search by Channel ID or Named User ID to view the tags and tag groups associated with a channel or contact. # Attributes > Set channel and contact attributes as key-value pairs for personalization. For information about Attributes, including overview, use cases, and how to target Attributes, see [About Attributes](https://www.airship.com/docs/guides/audience/attributes/about/). ## Channel Attributes Channel attributes are attributes managed on the Channel by the SDK. #### Swift ```swift Airship.channel.editAttributes { editor in editor.set(string: "Bobby's Phone", attribute: "device_name") editor.set(number: 4.99, attribute: "average_rating") editor.remove("vip_status") } ``` #### Objective-C ```objc [UAirship.channel editAttributes:^(UAAttributesEditor * editor) { [editor setString:@"Bobby's Phone" attribute:@"device_name"]; [editor setNumber:@(4.99) attribute:@"average_rating"]; [editor removeAttribute:@"vip_status"]; }]; ``` ## Contact Attributes Contact attributes are attributes managed on the Contact by the SDK. #### Swift ```swift Airship.contact.editAttributes { editor in editor.set(string: "Bobby", attribute: "first_name") } ``` #### Objective-C ```objc [UAirship.contact editAttributes:^(UAAttributesEditor * editor) { [editor setString:@"Bobby" attribute:@"first_name"]; }]; ``` ## JSON Attributes JSON Attributes are data objects containing one or more string, number, date, or boolean key-value pairs. You can set and remove JSON Attributes on a Channel or a Contact. #### Swift ```swift Airship.contact.editAttributes { editor in try! editor.set( json: [ "key": .string("value"), "another_key": .string("another_value") ], attribute: "attribute_name", instanceID: "instance_id", expiration: Date.now ) } ``` ## Verifying Attributes To verify that attributes have been set correctly, look up the channel or contact in the [Contact Management](https://www.airship.com/docs/guides/audience/contact-management/) view. You can search by Channel ID or Named User ID to view the attributes associated with a channel or contact. # Subscription Lists > Manage channel and contact subscription lists for topic-based messaging. For information about Subscription Lists, including overview, use cases, and how to create subscription lists, see [Subscription Lists](https://www.airship.com/docs/guides/audience/segmentation/audience-lists/subscription/). ## Channel Subscription Lists Channel subscriptions apply only to the single channel. #### Swift ```swift // Modifying channel subscription lists Airship.channel.editSubscriptionLists { editor in editor.subscribe("food") editor.unsubscribe("sports") } // Fetching channel subscription lists let channelSubscriptions = try await Airship.channel.fetchSubscriptionLists() ``` #### Objective-C ```objc // Modifying channel subscription lists UASubscriptionListEditor *channelEditor = [UAirship.channel editSubscriptionLists]; [channelEditor subscribe:@"food"]; [channelEditor unsubscribe:@"sports"]; [channelEditor apply]; // Fetching channel subscription lists [[UAChannel shared] fetchSubscriptionListsWithCompletionHandler:^(NSArray * _Nullable channelSubscriptionLists, NSError * _Nullable error) { // Use the channelSubscriptionLists }]; ``` ## Contact Subscription Lists Contact subscriptions are set at the user-level and require a Channel scope specifying the types that the subscription list applies to. #### Swift ```swift // Modifying contact subscription lists Airship.contact.editSubscriptionLists { editor in editor.subscribe("food", scope: .app) editor.unsubscribe("sports", scope: .sms) } // Fetching contact subscription lists let contactSubscriptions = try await Airship.contact.fetchSubscriptionLists() ``` #### Objective-C ```objc // Modifying contact subscription lists UAScopedSubscriptionListEditor *contactEditor = [[UAContact shared] editSubscriptionLists]; [contactEditor subscribe:"food" scope:"app"]; [contactEditor unsubscribe:"sports" scope:"sms"]; [contactEditor apply]; // Fetching contact subscription lists [UAirship.contact fetchSubscriptionListsWithCompletionHandler:^(NSDictionary * _Nullable, NSError * _Nullable) { // Use the subscriptionLists }]; ``` ## Verifying Subscription Lists To verify that subscription lists have been set correctly, look up the channel or contact in the [Contact Management](https://www.airship.com/docs/guides/audience/contact-management/) view. You can search by Channel ID or Named User ID to view the subscription lists associated with a channel or contact.