App Tracking Transparency in Unity (IDFA Popup)

​ With Apple’s incoming changes to the requirements for use of IDFA and needing to request users permission via App Tracking Transparency popup which is incoming at some point in early 2021. Apps need to start to prepare to the incoming changes.

​ So how do you add a IDFA App Tracking Transparency popup from a Unity app?

At the moment there is no build in Unity method that will trigger the notification, There is however a preview package!

​ As a note App Tracking Transparency is only required on IOS 14 devices, Altough this won’t causing issues on any lower OS version it won’t trigger the popup. If you don’t have access to a IOS 14 device you can test this with the XCode Emulators. ​

1. Download Unity IOS Support Package

​ Download the com.unity.ads.ios.support library from Github. This is current in preview and won’t be found directly from the package manager.

Github Download

Unzip this into a folder outside your Asset Folder.

Unzip Project ​ Note it is best to make sure these files are checking into source control we will be using a relative path from Unity package manager. ​

2. Add to Package Manager

​ Now in you’re unity project go Windows->Package Manger.

​​Unity Package Manager

Then press the plus button and add from disk and navigate to the package.json file within the com.unity.ads.ios.support that we just unzipped.

​​Unzip Project

Unity will then import the package, Because we have imported the file from within the base Unity Project file the file has been direct to a relative path, if you however place this file outside this folder you will need to edit the Packages/manifest.json file to make it relative.

​​Unzip Project ​ ​

3. Triggering App Tracking Transparency Request

​ As most SDK recommend We will need to trigger this before we initialize any SDK’s that we wish to pass the IDFA into. We also can only trigger this one pre install with users being able to edit there preference within the IOS Settings menu. ​ ​ Here we are using a really simple system where we trigger the notification when a user press a button.

Breaking down

​ We first state we are using the IosSupport Library. We also inclosing this with a UNITY_IOS pre-compile which means we will only compile this code if we are running on IOS

#if UNITY_IOS

using Unity.Advertisement.IosSupport;

#endif

Next the actual triggering, again inclosing this with the UNITY_IOS pre-compile. We first check call ATTrackingStatusBinding.GetAuthorizationTrackingStatus() which will tell if the user has already set there preference, then ATTrackingStatusBinding.RequestAuthorizationTracking() Which will trigger the popup.

#if UNITY_IOS

    if(ATTrackingStatusBinding.GetAuthorizationTrackingStatus() == 
    ATTrackingStatusBinding.AuthorizationTrackingStatus.NOT_DETERMINED)
    {

        ATTrackingStatusBinding.RequestAuthorizationTracking();

    }

#endif

4. Post build steps

​ Like any other permission request Apple requires a description on why you are requesting these permission. For this we need to add the NSUserTrackingUsageDescription key to our PList. Instead of having to do this each time we create a build we are going to create a post build step that automatically adds it to the XCode Project

​ You can see more about Unity post build steps here

​ Here we just read in the PlistFile from the Xcode project we just created, then add in a new string values ​ plistRoot.SetString(“NSUserTrackingUsageDescription”, TrackingDescription); ​ Which sets the our popup text. ​ ​

4. Testing it out

​ Build the App to Xcode as normal and open it up in Xcode. If you open up the Info.Plist you will see the description we just added in from the post build step

​​​​Xcode Plist

Now we can just build and play on our device. Then just press the button and you should see the IDFA Popup!

​​​​​Xcode Plist

​​​​Xcode Plist

​ You will notice that if you press the button again it won’t re-trigger this is by the apple requirements so we will need to uninstall and pre-install to test it again. ​

​ This is the basic implementation ahead of the requirement of App Tracking Transparency for IOS, for a production version it may be best to pre-warn users about the popup, explaining why you are wanting to use the IDFA. This will likely improve the number of user who opt-in ​

If any problems feel free to drop me a line on Twitter @Gamereat.