A Unity Dev’s Guide to App Tracking Transparency, IDFA and iOS 14


By Troy Atkinson
15/06/21 · 15 min read

If you’re a mobile developer you know the importance of ads; the more tailored an ad is to the user’s preferences, the more likely they are to interact with it - and thus the more money your app can earn.

This process is possible because every user's phone has a unique ID which lets advertisers analyse user behaviour across websites and apps, allowing them to provide more tailored ads to users.

This ID on iOS is called The Identifier for Advertisers, or IDFA, and Apple has given users increased control over who can access it via the new App Tracking Transparency (ATT) framework. That means developers now need to first ask permission from the user to access it. This change continues Apple's trend of improving transparency and empowering users.

This change has kicked off a new era for mobile advertising, one where the majority of users on the second biggest mobile OS will no longer be sharing their Advertising ID, meaning developers will need to adapt by either being persuasive enough to get users to share it, or turn to other types of data to serve ads such as contextual advertising (one of AudioMob’s areas of focus).

So, how does this affect you as a Unity Developer? Let’s take a look.

How the Advertising ID Has Changed

The Identifier for Advertisers is a UUID (Universally Unique Identifier) assigned to each iOS device. Accessing it from within Unity is straightforward enough but as a game developer you don’t really have a direct need for it. What’s important is allowing the ad SDKs you’re using in your project to get them.

From iOS 14, if the user has not yet been asked permission by the developer to use the track the user or if the user has denied permission, their advertisingIdentifier will come back as a handful of zeros, rather than the usual UUID.

It’s important to note that users can turn off ‘Allow Apps to Request to Track’ in their phone’s privacy settings. While this will stop you from asking the user for permission to access their IDFA, it doesn’t mean that the user can’t give you permission manually. In the same settings window, user’s can toggle which apps are allowed to track them, thus which apps have access to the Identifier for Advertisers.

 

What About the Device Unique Identifier?

My initial worry was that my analytics system (that uses device UIDs to track users) would no longer work for users that don’t grant tracking permission; I mean, it’s an ID unique to each device, and analytics is a form of tracking... right?

However it turns out while Device.advertisingIdentifier will return a bunch of zeros if the user hasn’t opted in, Unity’s SystemInfo.deviceUniqueIdentifier property still returns an ID unique to every device with or without tracking permission from the user.

At first glance this seems like a mistake, surely the Device UID is similar to an Advertising ID when it comes to being able to track users? Actually no, it turns out that the Device UID is not only unique to each user, but unique to each publisher as well.

On iOS, deviceUniqueIdentifier gives you UIDevice.identifierForVendor which is hashed using an actual device ID and Vendor ID (or partial BundleID). So you’re absolutely fine to use it as much as you like, as apps from different publishers will receive different IDs for the same user, and there’s no way to reverse engineer it. Apple’s focus is on developers not being able to track users across websites and apps owned by other companies without permission, so when it comes to using the device UID for analytics, you’re good to go.

 

What’s a SKAdNetwork?

SKAdNetworks (SK stands for StoreKit but apparently it’s pronounced ‘skad’) are Apple’s way of being able to find out how successful an ad is by anonymously tracking a user’s actions after they press an ad. This allows advertisers to link app installs to ad impressions without disclosing any user data.Below is a handy visualisation of the process from the Apple Developer Documentation but as a Unity developer the important thing to know is that, yes, you do want to add SKAd IDs to your project. Instructions on how to do so can be found down in the next paragraph. Once they’re added into your Unity project,  you can just sit back and let your favourite ad networks do the rest.

 

How Do I Ask Users for Permission to Track Them?

Now the important thing to ask is ‘how do I ask users permission to track them?’. You want to call iOS’s native function requestTrackingAuthorization, which from within Unity is easier said than done. There’s no built in-support to handle this (yet) so for now, you’ve got two choices:

Option 1: Unity’s Advertising Support Package

Unity has created a package that gives you some static functions including asking for tracking permission and checking it’s status. If you’re on Unity 2018.1+ you can find it in the Package Manager as ‘iOS 14 Advertising Support’. In the case of older versions you’ll need to download from GitHub

Once imported, you want to be using the Unity.Advertisement.IosSupport namespace and make the request.

public void RequestTrackingPermission()
{
    #if UNITY_IOS
    if (ATTrackingStatusBinding.GetAuthorizationTrackingStatus() == ATTrackingStatusBinding.AuthorizationTrackingStatus.NOT_DETERMINED)
    {
        ATTrackingStatusBinding.RequestAuthorizationTracking();
    }
    #endif
}

Easy right? Well we’re not quite done. We now have to add a NSUserTrackingUsageDescription string into our info.plist file either by adding it in Xcode once the project is built, or by writing a fancy post-build script. This Usage Description string is what will be shown to the user when you ask them for tracking permission, and usually consists of something like: ‘we will use the data to show you personalised ads’.

Alternatively you can make an Xcode build a post-build script in Unity that automatically adds the Usage Description string  for you everytime you build. The specifics of how to do this, best practices, API details and examples can be found in Unity’s technical integration guide.

The last thing you need to know is how to add SKAdNetwork IDs to your app; Unity Ads will do this step for you if you’re using it, but if not you will need to create a file in your Assets folder called SKAdNetworks (with no extension), open it in a text editor and paste in a URL to your list of SKAdNetworks (in JSON format). Unity provides and updates this list which you can paste into your file if you don’t have your own list. If you’re interested in which SkAdNetworks Unity uses, here’s a nicer looking list of networks.

Unity’s build process will pick up on the SKAdNetworks asset you created, download the JSON list and add the IDs to your info.plist file when you make an Xcode build. If you hate yourself you can also manually add SKAdNetwork IDs into your info.plist file via Xcode, but there’s zero point and it takes ages.

Option 2: Third Party Asset Store Plugin

If you prefer the fast and easy approach, you can buy this plugin on the Unity Asset Store. It puts all of the TrackingUsageDescription and SKAdNetwork stuff into a nice UI window and handles the post-build stuff for you. It also allows you to subscribe to an event that will fire once the tracking permission result is sent back to the game, which is always nice.

If you’re happy with another third party plugin in the mix, it’s a good way to get it up and running quickly.

private void RequestTrackingPermission()
{
    #if UNITY_IOS
    AppTrackingTransparency.OnAuthorizationRequestDone += OnAuthorizationRequestDone;
    AppTrackingTransparency.RequestTrackingAuthorization();
    #endif
}

private void OnAuthorizationRequestDone(AppTrackingTransparency.AuthorizationStatus status)
{
    if (status == AppTrackingTransparency.AuthorizationStatus.AUTHORIZED)
    {
        Debug.Log(AppTrackingTransparency.IdentifierForAdvertising());
    }
}

Here it’s worth noting that Apple only lets you ask for tracking permission once per install. You can check to see if the user has already declined the request (AuthorizationTrackingStatus), but the user’s phone will remember itself and won’t display the request a second time even if you tried.

What It Looks Like for the User

When you request tracking permission, the user will get a prompt asking if they want to be tracked, which includes your NSUserTrackingUsageDescription text in a smaller font below.

 

Final Thoughts

Apple is making user privacy a focal point on iOS, and my guess is they will continue to make changes that put user privacy first. As game developers it’s important we keep on-top of these changes and look for solutions to minimise the impact this will have on revenue.

Hopefully Unity will have built-in ATT functionality out of the box at some point, similar to how the LocationService works. But then again it might not be needed, as developers are pivoting to new and innovative ways of advertising in games that are IDFA-safe.

 


Troy Atkinson
Software Engineer
Follow me on