DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Hayden Bleasel
Hayden Bleasel

Posted on • Updated on

Implementing iOS 14.5 Tracking Transparency in ExpoΒ SDK41

Starting with iOS 14.5, iPadOS 14.5, and tvOS 14.5, developers are required to ask users for their permission to track them across apps and websites owned by other companies. This is part of Apple's push for a higher standard of privacy, security and content on the App Store.

If you're buildingΒ a standard React Native app, you've got plenty of options available, namely react-native-tracking-transparency.

If you're an Expo user though, you'll notice that they've documented a new module called Expo Tracking Transparency in their docs. This module is actually a unimodule, aggregating the permission requesters found in expo-facebook, expo-ads-facebook and expo-ads-admob.

Unfortunately, it's not published to NPM yet (assuming it'll appear in SDK42) so in the meantime, you'll need to use one of the libraries above, e.g. Admob:

import { requestPermissionsAsync } from 'expo-ads-admob';

const { status } = await requestPermissionsAsync();

if (status == 'granted') {
  // Do your thing
} else {
  // No tracking for you
}
Enter fullscreen mode Exit fullscreen mode

Once the new Tracking Transparency unimodule is released, you should be able to request tracking without adding the libraries above, e.g.

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

useEffect(() => {
  (async () => {
    const { status } = await requestTrackingPermissionsAsync();
    if (status === 'granted') {
      // Do your thing
    } else {
      // No tracking for you
    }
  })();
}, []);
Enter fullscreen mode Exit fullscreen mode

You'll also want to update your app config file (app.json or app.config.ts) with a ios.infoPlist.NSUserTrackingUsageDescription property, e.g.

ios: {
  infoPlist: {
    NSUserTrackingUsageDescription: "We use Tracking to fix bugs and improve your experience."
  }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
babaphemy profile image
Babafemi Adigun

I have done all of this and Apple is still rejecting my app. Do I need to eject the app before this will work?

DEV runs on 100% open source code known as Forem.

Β 
Contribute to the codebase or host your own.
Β 
Check these out! πŸ‘‡