Published on

(Unity) Get whether the user has allowed ATT (App Tracking Transparency)

  • Evelyn
    Full-time IndieDev.
    I'm Japanese, so please forgive me if my English is strange.

Please share this article if you like!

Hello! If you've visited this blog post, you've probably already taken action on ATT.

In this article, we will try to get the user's ATT permission information and then control whether or not to show the Unity Ads privacy dialog.

If you haven't already done so, please refer to the following article to get started.

If you are planning to use Unity Ads, please watch this video.

Table of Contents

Native iOS code to get an IDFA

First, let's write the native iOS code. Place the following object C file under the Plugins > iOS folder.

Plugins > iOS >

#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import <AdSupport/AdSupport.h>

extern "C" const char * _getIDFA() {
    if (@available(iOS 14,*)) {
        ASIdentifierManager *identifierManager = [ASIdentifierManager sharedManager];
            if ([identifierManager isAdvertisingTrackingEnabled]) {
                NSLog(@"[idfa] isAdvertisingTrackingEnabled enabled");
            } else {
                NSLog(@"[idfa] isAdvertisingTrackingEnabled disabled");
            NSString *idfa = identifierManager.advertisingIdentifier.UUIDString;
            NSLog(@"[idfa] %@", idfa);
        return strdup([idfa UTF8String]);

    } else{
        return NULL;

Placement locations are as follows. Please be careful not to make mistakes.

Call native code from C# to determine if ATT is allowed

Next, create a cSharp file in your preferred location that calls the native code you just saw.

The IDFA you get will determine if 00000000-0000-0000-0000-000000000000" is allowed for ATT.


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;

public class GetIDFA : MonoBehaviour
    private bool AttAllowedFlg = false;

    private static extern string _getIDFA();

    private void Start()
      string idfa = _getIDFA();
      AttAllowedFlg = !idfa.Equals("00000000-0000-0000-0000-000000000000");
    public bool GetDidAllowedATT()
      return AttAllowedFlg;


In addition, if you want to take advantage of ATT's acquisition status in Unity Ads.

As a bonus section, if you're using Unity Ads, you may get rejected by the GDPR and CCPA permission dialogs even though you don't have ATT permission.

In this case, you can use this IDFA code to control the Advertisement metadata before the initialization process of Unity Ads.

string idfa = _getIDFA();

//GDPR Compliance
MetaData gdprMetaData = new MetaData("gdpr");
gdprMetaData.Set("consent", idfa.Equals("00000000-0000-0000-0000-000000000000") ? "false" : "true");


//CCPA compliance
MetaData privacyMetaData = new MetaData("privacy");
privacyMetaData.Set("consent", idfa.Equals("00000000-0000-0000-0000-000000000000") ? "false" : "true");


The following links will take you to Unity Ads' privacy data documentation.

(UnityAds) Data privacy and consent

I hope I can be of help to you in your game development. The above was written by Evelyn. I'll see you in another article.

Please share this article if you like!