Guides
Plan-enterprise-icon
Expo Application Services
API Reference

TrackingTransparency

A library for requesting permission to track the user or their device. Examples of data used for tracking include email address, device ID, advertising ID, etc... This permission is only necessary on iOS 14 and higher; on iOS 13 and below this permission is always granted. If the "Allow Apps to Request to Track" device-level setting is off, this permission will be denied. Be sure to add NSUserTrackingUsageDescription to your Info.plist to explain how the user will be tracked, otherwise your app will be rejected by Apple.
For more information on Apple's new App Tracking Transparency framework, please refer to their documentation.

Platform Compatibility

Android DeviceAndroid EmulatoriOS DeviceiOS SimulatorWeb
Status-failed-iconStatus-failed-iconStatus-success-iconStatus-success-iconStatus-failed-icon

Installation

Terminal
→ npx expo install expo-tracking-transparency

If you're installing this in a bare React Native app, you should also follow these additional installation instructions.

Configuration in app.json / app.config.js

You can configure expo-tracking-transparency using its built-in config plugin if you use config plugins in your project (EAS Build or npx expo run:[android|ios]). The plugin allows you to configure various properties that cannot be set at runtime and require building a new app binary to take effect.
Triangle-down-icon
Are you using the classic build system? (expo build:[android|ios])
Triangle-down-icon
Are you using this library in a bare React Native app?
Learn how to configure the native projects in the installation instructions in the expo-tracking-transparency repository.

Example app.json with config plugin

{
  "expo": {
    "plugins": [
      [
        "expo-tracking-transparency",
        {
          "userTrackingPermission": "This identifier will be used to deliver personalized ads to you."
        }
      ]
    ]
  }
}

Configurable properties

NameDefaultDescription
userTrackingPermission"Allow this app to collect app-related data that can be used for tracking you or your device."Only for:
Apple-iconiOS

Sets the iOS `NSUserTrackingUsageDescription` permission message in Info.plist.

Usage

Basic tracking transparency usage
import React, { useEffect } from 'react';
import { Text, StyleSheet, View } from 'react-native';
import { requestTrackingPermissionsAsync } from 'expo-tracking-transparency';

export default function App() {
  useEffect(() => {
    (async () => {
      const { status } = await requestTrackingPermissionsAsync();
      if (status === 'granted') {
        console.log('Yay! I have user permission to track data');
      }
    })();
  }, []);

  return (
    <View style={styles.container}>
      <Text>Tracking Transparency Module Example</Text>
    </View>
  );
}

%%placeholder-start%%const styles = StyleSheet.create({ ... }); %%placeholder-end%%const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
});

API

import {
  requestTrackingPermissionsAsync,
  getTrackingPermissionsAsync,
} from 'expo-tracking-transparency';

Hooks

useTrackingPermissions(options)

NameTypeDescription
options
(optional)
PermissionHookOptions<object>-

Check or request the user to authorize or deny access to app-related data that can be used for tracking the user or the device. Examples of data used for tracking include email address, device ID, advertising ID, etc. On iOS 14.5 and above, if the user denies this permission, any attempt to collect the IDFA will return a string of 0s.

The system remembers the user’s choice and doesn’t prompt again unless a user uninstalls and then reinstalls the app on the device.

On Android, web, and iOS 13 and below, this method always returns that the permission was granted.

Example

const [status, requestPermission] = useTrackingPermissions();
  • Undo-icon[null | PermissionResponse, RequestPermissionMethod<PermissionResponse>, GetPermissionMethod<PermissionResponse>]

Methods

getTrackingPermissionsAsync()

Checks whether or not the user has authorized the app to access app-related data that can be used for tracking the user or the device. See requestTrackingPermissionsAsync for more details.

On Android, web, and iOS 13 and below, this method always returns that the permission was granted.

Example

const { granted } = await getTrackingPermissionsAsync();

if (granted) {
  // Your app is authorized to track the user or their device
}

isAvailable()

Returns whether the TrackingTransparency API is available on the current device.

  • Undo-iconboolean

Currently this is true on iOS 14 and above only. On devices where the Tracking Transparency API is unavailable, the get and request permissions methods will always resolve to granted.

requestTrackingPermissionsAsync()

Requests the user to authorize or deny access to app-related data that can be used for tracking the user or the device. Examples of data used for tracking include email address, device ID, advertising ID, etc. On iOS 14.5 and above, if the user denies this permission, any attempt to collect the IDFA will return a string of 0s.

The system remembers the user’s choice and doesn’t prompt again unless a user uninstalls and then reinstalls the app on the device.

On Android, web, and iOS 13 and below, this method always returns that the permission was granted.

Example

const { granted } = await requestTrackingPermissionsAsync();

if (granted) {
  // Your app is authorized to track the user or their device
}

Interfaces

PermissionResponse

An object obtained by permissions get and request functions.

NameTypeDescription
canAskAgainbooleanIndicates if user can be asked again for specific permission. If not, one should be directed to the Settings app in order to enable/disable the permission.
expiresPermissionExpirationDetermines time when the permission expires.
grantedbooleanA convenience boolean that indicates if the permission is granted.
statusPermissionStatusDetermines the status of the permission.

Types

PermissionExpiration

Permission expiration time. Currently, all permissions are granted permanently.

Acceptable values are: 'never', number.

PermissionHookOptions

Acceptable values are: PermissionHookBehavior, Options.

Enums

PermissionStatus

PermissionStatus.DENIED = "denied"

User has denied the permission.

PermissionStatus.GRANTED = "granted"

User has granted the permission.

PermissionStatus.UNDETERMINED = "undetermined"

User hasn't granted or denied the permission yet.

Permissions

Android

No permissions required.

iOS

The following usage description keys are used by this library:
Info.plist KeyDescription
NSUserTrackingUsageDescriptionA message that informs the user why an app is requesting permission to use data for tracking the user or the device.
  • Message-iconAsk a question on the forums about TrackingTransparency
  • Github-iconView open bug reports for TrackingTransparency
  • Code-iconView source code for TrackingTransparency
  • Build-iconView package in npm Registry
  • Edit-iconEdit this page

Was this doc helpful?