react-native-tracking-transparency

repository·master·Indexed 42 days ago

https://github.com/mrousavy/react-native-tracking-transparency

A React Native library for interacting with the iOS App Tracking Transparency (ATT) API on iOS 14+. It provides functions to request user permission via requestTrackingPermission() and check the current authorization state using getTrackingStatus().

Tokens
818
Snippets
4
Records
4
Agent score
4%

What's inside react-native-tracking-transparency

  1. Install react-native-tracking-transparency

    master

    To install the library, run the following commands to install the npm package and update your iOS pods:

    npm install react-native-tracking-transparency
    cd ios
    pod install

    Important: You must add the NSUserTrackingUsageDescription key to your Info.plist file for the library to function correctly on iOS.

  2. Get the current tracking status with getTrackingStatus

    master

    Use getTrackingStatus() to retrieve the current state of the iOS Tracking API.

    Platform Behavior:

    • iOS 14+: Returns the actual permission status.
    • Android & iOS < 14: Always returns 'unavailable'.

    Possible return values:

    • 'unavailable': The tracking API is not available on this device (Android or iOS < 14).
    • 'denied': The user explicitly denied permission. You should disable tracking features.
    • 'authorized': The user granted permission. You can enable tracking features.
    • 'restricted': The permission alert cannot be shown due to device restrictions.
    • 'not-determined': The user has not been prompted yet. Call requestTrackingPermission() to show the prompt.
    import { getTrackingStatus } from 'react-native-tracking-transparency';
    
    const trackingStatus = await getTrackingStatus();
    if (trackingStatus === 'authorized' || trackingStatus === 'unavailable') {
      // enable tracking features
    }
  3. Request tracking permission with requestTrackingPermission

    master

    Use requestTrackingPermission() to trigger the system permission alert to the user.

    Requirements:

    • Requires iOS 14 or higher.
    • You must include the NSUserTrackingUsageDescription key in your Info.plist.
    • On Android and iOS versions below 14, this will always return 'unavailable'.

    Return Values: Returns a promise that resolves to the tracking status (e.g., 'authorized', 'denied', etc.).

    import { requestTrackingPermission } from 'react-native-tracking-transparency';
    
    const trackingStatus = await requestTrackingPermission();
    if (trackingStatus === 'authorized' || trackingStatus === 'unavailable') {
      // enable tracking features
    }
  4. TrackingStatus type values

    master

    The TrackingStatus type represents the authorization state of the user. The values correspond to Apple's ATTrackingManager.AuthorizationStatus:

    • 'authorized': The user has granted permission to track.
    • 'denied': The user has explicitly denied permission.
    • 'restricted': Tracking is restricted (e.g., due to parental controls or device settings).
    • 'not-determined': The user has not yet been asked for permission.
    • 'unavailable': The tracking API is not available on this platform or device.
    type TrackingStatus =
      | 'unavailable'
      | 'denied'
      | 'authorized'
      | 'restricted'
      | 'not-determined';