AppTrackingTransparency
In this blog, we are going to learn about AppTrackingTransparency. AppTrackingTransparency is a framework introduced with iOS 14.5 and it is mandatory to implement it in your application if your application collects end-user data and shares it with third parties for tracking purposes. It replaced the previous Limit Ad Tracking. This framework limits the user’s unique id (IDFA) from sharing for ad tracking. Let’s first talk about all mentioned terms in detail for better understanding. The AppTrackingTransparency is applied to every app and device.
IDFA
According to Apple,
The Advertising Identifier (IDFA) is a unique ID for each iOS device and is the only way to offer targeted ads. Users can choose to limit ad targeting on their iOS device. Apple Devices like Iphone, Ipad gets assigned a unique IDFA.
Apple introduced IDFA in 2012 as a replacement for UDID. IDFA is generally used by MMPs (Mobile Measurement Platform) for various purposes such as Ad Targeting, Ad fraud detection, etc. Below is an example of how IDFA looks like:
1 |
F65B26BA-846–98DD-TE6P-83369125YFDC |
To view your device IDFA you can download My Device ID by AppsFlyer from App Store and launch the application. We are using a third-party application for viewing our own UDID is because apple doesn’t provide a way to view it in your device setting.
MMP (Market Measurement Platform)
MMP is a platform that tracks, visualizes, and organizes mobile app data to provide marketing information to their partners. It provides SDK to their advertiser to integrate into a mobile app. With this SDK, advertisers can track multiple things. Some of them are:
- Source of each download from the app store,
- App Crashes,
- In-app Events,
- Measure media,
- Keywords,
- Clicks
- etc
LAT
LAT stands for Limit Ad Tracking. As the name suggests it allows you to opt-out from advertisement tracking. When LTA is enabled it changed the user IDFA into zeros
(00000000-0000-0000-0000-000000000000). This means they won’t see specific ads targeted at them because, as far as networks see, the device has no identity. It was introduced in 2012. The LAT is set globally in settings.
Now let’s dive into code and check how to enable ATT in your code
To enable ATT in your application you need to follow the below-mentioned 2 steps.
Firstly, add two new lines to your Info.plist
1 2 |
<key>NSUserTrackingUsageDescription</key> <string>Reason, why you want to track the user detail </string> |
Secondly, we need to request for user’s permission. As this new feature is only available with iOS14, we also need to wrap the code into a version check. Let’s first look at how it looks in AppDelegate
. Run this block from didFinishLaunchingWithOptions:
1 2 3 4 5 6 7 8 9 |
if #available(iOS 14, *) { ATTrackingManager.requestTrackingAuthorization { status in //you got permission to track } } else { //you got permission to track, iOS 14 is not yet installed } |
Finally, when you run your application you will get a prompt to allow permission.
advertisingIdentifier
You can also fetch device IDFA using this property of AdSupport
framework. The advertisingIdentifier
is an alphanumeric string that’s unique to each device, and which you only use for advertising. However, on devices running iOS 14.5 and later and iPadOS 14.5 and later, your app must request tracking authorization before it can get the advertising identifier. For more information on getting the advertising identifier, see AdSupport.
The advertising identifier returns either a unique UUID, or all zeros. It returns a unique UUID in the following cases:
- Firstly, if Settings > Privacy > Tracking > Allow Apps to Request to Track is On, you’ve requested tracking authorization from the user by calling the App Tracking Transparency APIs, and received authorization, indicated by ATTrackingManager.AuthorizationStatus.authorized.
- Secondly, if the user changes Settings > Privacy > Tracking > Allow Apps to Request to Track to Off after authorizing your app, and leaves the permissions On for your app.
The advertising identifier returns all zeros (00000000-0000-0000-0000-000000000000) in the following cases:
- In Simulator, regardless of any settings.
- When we call this API on a device running macOS.
- On devices running iOS 14.5 and later and iPadOS 14.5 and later,
- if we haven’t requested authorization using the App Tracking Transparency framework.
- If we requested authorization using the App Tracking Transparency framework and the user declines, which results in an authorization status of
ATTrackingManager.AuthorizationStatus.denied
. - Or when a profile or configuration restricts access to the advertising identifier.
1 2 3 4 5 6 7 8 9 10 11 12 |
func fetchIDFA() -> String? { if #available(iOS 14, *) { if ATTrackingManager.trackingAuthorizationStatus != .authorized { return nil } } else { if ASIdentifierManager.shared().isAdvertisingTrackingEnabled == false { return nil } } return ASIdentifierManager.shared().advertisingIdentifier.uuidString } |
In conclusion, using the above code you can fetch device IDFA.
Thank you for reading this article. If you want to read more articles regarding iOS Development click here.