Custom iOS Device Attributes Using AWS Amplify CLI and Amazon Pinpoint

Dennis Hills
ITNEXT
Published in
5 min readSep 11, 2018

--

This is part 2 of a 3-part series on adding user analytics to your iOS Swift app using AWS Amplify and Amazon Pinpoint. In part 1, we talked about collecting basic user analytics (demographics and app activity) in your iOS app. In this article, we’ll augment this process by adding custom user device analytics in the form of device-specific attributes. We will then use these additional attributes to segment our app users into shared device model characteristics so we can later engage these users with relevant content.

Collect Custom Device Specific Attributes

First, let’s focus on the default demographics automatically collected by Amazon Pinpoint when using the AWS SDK for iOS. The standard default demographics attributes collected by Pinpoint look like this:

Standard Demographic Attributes Collected by Amazon Pinpoint

Here’s what standard demographics were collected for my iPhone x:

Actual Standard Demographic Attributes Collected by Pinpoint for my iPhone X

Notice how the demographics for my iPhone X is missing the standard ModelVersion attribute? The ModelVersion demographic attribute for iOS should represent the specific iOS model type (e.g. iPhone 8, iPhone X, or iPad Mini 3). For any mobile developer, the model version attribute is important to know as your app can perform completely different from one model version to the next. This is critical for addressing Android fragmentation, but for iPhones, developers need to know these details when adding or deprecating app features for a specific model. For troubleshooting, you need to know specifically, what phone types are experiencing issues so that you debug on the exact devices and can also reach out only to those affected users on those devices, hopefully before they experience an issue.

Since Amazon Pinpoint does not currently track ModelVersion as a standard demographic attribute for iOS devices, let’s add this attribute to our app. We can use this attribute to later segment our users based on a specific iOS iPhone model.

Add this DeviceUitlity.swift extension to your Xcode project

This DeviceUtility.swift class is a utility class that defines the UIDevice extension that deciphers Apple’s model number schema into readable iOS device types. (e.g. “iPhone7,1” refers to “iPhone 6s”)

Now, if you recall, from the first article, we added an AWSAnalyticsService.swift class that is used for sending analytics events to Amazon Pinpoint. We’ll take that same class and modify it to call the UIDevice extension and update the user’s device default model version attribute before sending an update to Pinpoint.

Add this function to the AWSAnalyticsService.swift class just under sendEvent method:

In the AppDelegate.swift class of your iOS project, call the recordCustomProfileDemographics function to update the ModelVersion attribute of the device with a model version returned by the UIDevice extension.

Here are the results in the Models graph of the Demographics analytics page in the Amazon Pinpoint console after running the app with our applied changes:

Amazon Pinpoint Models graph showing updated iOS model versions

Before adding the custom model version, the Model graph would have shown one colored circle with 100% of these users on a single Apple “iPhone”. This is OK for high-level analytics, but not useful if we need to contact those customers based on a specific version of iPhone or when we need a better understanding what features those user devices are able to take of advantage of.

Now that we are collecting the iOS model type, let’s create a new Amazon Pinpoint Segment with a subset of users based on their iPhone model versions. The same process can be done to segment iPad models as the UIDevice extension handles all iOS device types (at least until Apple announces new device on Sept 12).

Segmenting Users Based on iPhone Model Version Attributes

In this example, our segment represents a subset of our audience based on like iPhone models. For example, to reach users who are running your app on an iPhone X, you can define a segment for app users matching ModelVersion “iPhone X”.

Create a segment via Amazon Pinpoint Console

  1. From your project directory in Terminal, launch the Amazon Pinpoint Console using AWS Amplify CLI: $ amplify analytics console
  2. In the navigation menu, choose Segments.
  3. Choose New segment.
  4. For Segment name, type a name for your segment to make it easy to recognize later.
  5. For How would you like to define your segment, keep Build segment selected.

6. For What messaging channel do you want to use? Choose the channel you will most likely use to engage the segmented users. We’ll talk about building out channels and campaigns in the next article. For this tutorial, I’ll use SMS.

7. For Filter by standard attributes, define which users are using Model > iPhone X. The (2) “iPhone” devices you see here represent apps that have not been updated with our UIDevice code so we only know these users are on an iPhone.

8. (Optional) For Filter by custom attributes and Filter by user attributes, define which users belong to the segment based on custom attributes that you add to your Amazon Pinpoint endpoint resources.

9. When you are finished selecting criteria, choose Create segment.

Keep this segment handy for when we create a new campaign based on these segmented users.

Final Thoughts

In this article, we updated an existing iOS app by adding an extension to map iOS model versions to human readable values and then used those values to update the standard demographics attributes collected by Amazon Pinpoint. We then created an Amazon Pinpoint Segment that filters out those users of a specific iOS model.

In the next article, we’ll build a Pinpoint Campaign based on this segment and send out a notification to those segmented users.

Resources

AWS Amplify CLI

--

--

Mobile Developer. I do mobile stuff. Opinions are always my own.