Code Monkey home page Code Monkey logo

react-native-tracking-transparency's Introduction

react-native-tracking-transparency

🕵️ A React Native Library for interacting with the tracking API from iOS 14.





Installation

  1. Install package

    npm install react-native-tracking-transparency
    cd ios
    pod install
  2. Add NSUserTrackingUsageDescription to your Info.plist

Usage

See the example app for a full code example.

getTrackingStatus

Gets the current Tracking API status. As of iOS 14, Apple requires apps to only enable tracking (e.g.: advertiser ID collection) when the user has granted tracking permissions.

Requires iOS 14. On Android and iOS versions below 14, this will always return 'unavailable'.

import { getTrackingStatus } from 'react-native-tracking-transparency';

const trackingStatus = await getTrackingStatus();
if (trackingStatus === 'authorized' || trackingStatus === 'unavailable') {
  // enable tracking features
}

The tracking status can return one of the following values:

  • 'unavailable': The tracking API is not available on the current device. That's the case on Android devices and iPhones below iOS 14.
  • 'denied': The user has explicitly denied permission to track. You'd want to respect that and disable any tracking features in your app.
  • 'authorized': The user has granted permission to track. You can now enable tracking features in your app.
  • 'restricted': The tracking permission alert cannot be shown, because the device is restricted. See ATTrackingManager.AuthorizationStatus.restricted for more information.
  • 'not-determined': The user has not been asked to grant tracking permissions yet. Call requestTrackingPermission().

requestTrackingPermission

Requests permission to track the user. Requires an NSUserTrackingUsageDescription key in your Info.plist. (See iOS 14 Tracking API)

Requires iOS 14. On Android and iOS versions below 14, this will always return 'unavailable'.

import { requestTrackingPermission } from 'react-native-tracking-transparency';

const trackingStatus = await requestTrackingPermission();
if (trackingStatus === 'authorized' || trackingStatus === 'unavailable') {
  // enable tracking features
}

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

react-native-tracking-transparency's People

Contributors

danilobuerger avatar edwinkcw avatar imgbotapp avatar mrousavy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-native-tracking-transparency's Issues

Does this work for React Native Expo?

Im using react native expo and im getting this issue:

[Unhandled promise rejection: TypeError: null is not an object (evaluating 'TrackingTransparency.requestTrackingPermission')]

Any idea on how to fix it?

Undefined symbol: _RCTRegisterModule when trying to build app

I am encountering the following error when attempting to build my React Native app after adding the react-native-tracking-transparency package --

Screen Shot 2022-03-21 at 9 08 08 PM

Screen Shot 2022-03-21 at 9 09 09 PM

I've been trying to solve this for awhile now and am sure it is probably something simple, but I can't find the solution and searching online hasn't yielded many answers. How do I make my app build correctly while using this package?

Steps followed:

  1. yarn add react-native-tracking-transparency
  2. yarn install
  3. cd ios
  4. pod install

React version: 17.0.2
React Native version: 0.67.4
Xcode version: 13.2.1

bundling failed: Error: While trying to resolve module `react-native-tracking-transparency`

bundling failed: Error: While trying to resolve module react-native-tracking-transparency from file /Users/lucky/Projects/apps/reactNativeSalesapp/utility/appTrackingTransparency.js, the package /Users/lucky/Projects/apps/apps/reactNativeSalesapp/node_modules/react-native-tracking-transparency/package.json was successfully found. However, this package itself specifies a main module field that could not be resolved (/Users/lucky/Projects/apps/reactNativeSalesapp/node_modules/react-native-tracking-transparency/src/index. Indeed, none of these files exist:

  • reactNativeSalesapp/node_modules/react-native-tracking-transparency/src/index(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
  • /Users/lucky/Projects/apps/reactNativeSalesapp/node_modules/react-native-tracking-transparency/src/index/index(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
    at ResolutionRequest.resolveDependency (/Users/lucky/Projects/apps/reactNativeSalesapp/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:65:15)
    at DependencyGraph.resolveDependency (/Users/lucky/Projects/apps/reactNativeSalesapp/node_modules/metro/src/node-haste/DependencyGraph.js:283:16)
    at Object.resolve (/Users/lucky/Projects/apps/reactNativeSalesapp/node_modules/metro/src/lib/transformHelpers.js:264:42)
    at /Users/lucky/Projects/apps/reactNativeSalesapp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:399:31
    at Array.map ()
    at resolveDependencies (/Users/lucky/Projects/apps/reactNativeSalesapp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:396:18)
    at /Users/lucky/Projects/apps/eactNativeSalesapp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:269:33
    at Generator.next ()
    at asyncGeneratorStep (/Users/lucky/Projects/apps/reactNativeSalesapp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:87:24)
    at _next (/Users/lucky/Projects/apps/reactNativeSalesapp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:107:9)
    BUNDLE [ios, dev] ./index.js ░░░░░░░░░░░░░░░░ 0.0% (0/1), failed.

Not working on real device

It perfectly works on simulator with debug variant but not on real device with production variant.

any suggestion ?

tracking status always returns 'denied' [iOS 14.4]

I'm running iOS 14.4 on an iPhone 12 Pro Max and for some reason when I try to request the tracking transparency permission using this library I always get 'denied' back and there is no dialog alert that appears that requests the permission.

I've toggled on and off the Tracking permission in the iOS settings multiple times and uninstalled and re-installed my app several times with no luck. My app doesn't even appear in the list of apps that require tracking. I'm pretty stuck right now, but it seems like a lot of other people are having the same issue maybe?

Custom IDFA message not showing

Hi There,

I've installed this lib and well displaying the request Tracking, but the custom IDFA isn't showing up

This is my code:

import {
  getTrackingStatus,
  requestTrackingPermission,
  TrackingStatus,
} from 'react-native-tracking-transparency';


getTrackingStatus()
      .then((status) => {

        if (status !== 'denied' && status !== 'authorized') {
          this.requestPermissions();
        }
        else {
          this.setState({
            trackingState: status
          });
        }
        
      })
      .catch((e) => Alert.alert('Error', e?.toString?.() ?? e));

Any help please !
Regards

'TrackingTransparency.mm' cannot be found

When i build the app and i'm getting this issue:

Build input file cannot be found: '/Users/ejiang/Project/TKPro/TKPro-mobile/packages/tkp-mobile/node_modules/react-native-tracking-transparency/ios/TrackingTransparency.mm' (in target 'TrackingTransparency' from project 'TrackingTransparency')

If i fix the '.mm' to '.m' in the file(/ios/TrackingTransparency.xcodeproj/project.pbxproj),it will build success.But in production,i can't fix this file.

Is there any other idea to fix it?

Error - TypeError: null is not an object (evaluating 'TrackingTransparency.getTrackingStatus')

After installing the package and adding NSUserTrackingUsageDescription to my Info.plist I get an error "[TypeError: null is not an object (evaluating 'TrackingTransparency.getTrackingStatus')]" when calling getTrackingStatus(). Same happens with requestTrackingPermission().

I am experiancing this issue only when testing on a real device. On emulator it works fine.
My guess is that it appears because on the emulator the "Allow Apps to Request to Track" option in "Setting -> Privacy -> Tracking", is configurable, while on my physical device it stays "greyed out".

There are a couple discussions/threads about this greyed out buttons but nothing seams to make them interactable.
One workaround is to wrap the function call in a try catch block and if an error occurs, treat it as "not-determined".

Is this the expected behaviour or am I missing something?

Device: iPhone 8 (iOS 14.5)

Not possible to request Tracking Transparency in iOS 15

Hello,

I've tested in iOS 15 as it was officially released in 2021/09/20

However when calling method from iOS 15 requestTrackingPermission() I receive not-determined.

The same code executed in iOS 14 is working properly.

Do you have any idea why it's not requesting?

Thanks

import React, { useEffect } from 'react';
import { View } from 'react-native'
import {  requestTrackingPermission } from 'react-native-tracking-transparency';

const requestPermission = async () => {
    const trackingStatus = await requestTrackingPermission();
    alert(`trackingStatus ${trackingStatus}`);
}

const App = () => {
   useEffect(() => {
      requestPermission();
   }, []); 
   return <View />;
};

export default App;

requestTrackingPermission returns 'denied'

requestTrackingPermission returns 'denied' status without check for answer from modal.

requestTrackingPermission()
.then(trackingStatus => {
console.log('requestTrackingPermission', trackingStatus); // here shows "requestTrackingPermission denied"
});

reactnative 0.73.7

Apple TV support

hi! does this package support apple tv, for react-native-tvos?
thank you!

Link react_native_tracking_transparency (arm64) 0.2 seconds * Undefined symbol: _RCTRegisterModule

I am trying to run my react-native project in Xcode(ios) and I am faced with this error (run in real iPhone) :

Link react_native_tracking_transparency (arm64) 0.2 seconds * Undefined symbol: _RCTRegisterModule**
My project can run on Android, but on iOS, it could not run. I should mention that neither can run in the simulator nor on a real iPhone, and the strange thing is that I can archive it and I can do it via test flight. When I install the test flight application it works well, but I can not run the project.

I uninstall **react_native_tracking_transparency *** to see if the error is related to this package but as soon as I uninstall that, the same error(Undefined symbol: _RCTRegisterModule) *happens but with another package (react_native_spinkit), and I continue to uninstall also SpinKit package and again the error happens with another package. Also, it could not run in the previous Xcode version (13), when I updated my Xcode (14.1) for the first time after updating Xcode the app could run in Xcode, but then again the error happened and could not run the app.

my system config: Mac mini,chip apple M1,macOS:Ventura 13

Xcode: 14.1

react-native-cli: 2.0.1 react-native: 0.68.1

I tried different solutions but none of them works for me. Thanks in advance for any help from you.

firebase crashlytics report: FBSDKSKAdNetworkReporter (After version of ATT)

After version of react-native-tracking-transparency (ATT) applied
Firebase Crashlytics reports crashes, such as attached images.
(FBSDKSKAdNetworkReporter.m line 92 / Fatal Exception: NSInvalidArgumentException)

firebase_crash

I am currently using react-native-fbsdk-next. (FB SDK >= 9)
What should I do to fix the problem?
Thank you.

App breaking on (iOS < 14) dyld: Library not loaded

After installing the package the app works fine on iOS 14 but any version before that the app does not run.
I get this error.

dyld: Library not loaded: /System/Library/Frameworks/AppTrackingTransparency.framework/AppTrackingTransparency
  Referenced from: /Users/kash/Library/Developer/CoreSimulator/Devices/FE2B596E-88F2-43A5-8801-0EC1665C69E2/data/Containers/Bundle/Application/A96FC8FA-34BA-4322-86EE-860382C37B2A/jdwelreact.app/jdwelreact
  Reason: image not found

I found this solution on stack overflow. It's working for me now on all iOS versions, is this the right fixed? If so I think it should be added to the documentation, as I sadly released an update to the app store, and now all users on iOS < 14 the app is crashing for them. This is very important to mention.
Thank you

xcode 12.4 build error: Undefined symbol: _OBJC_CLASS_$_ATTrackingManager [iOS 14.4]

Hey am sorry to bother again but your advice is very valuable.

I'm running iOS 14.4 on an iPhone 12 Pro Max[14.4],but it always has an error :
Undefined symbols for architecture x86_64:
"OBJC_CLASS$_ATTrackingManager", referenced from:
objc-class-ref in libTrackingTransparency.a(TrackingTransparency.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
“Undefined symbol: OBJC_CLASS$_ATTrackingManager”

I try to change the build setting and build path to fix it,but it didn't work。

How can i do to fix it?

Thank you

requestTrackingPermission crash the app [OS 14.5.1]

Hi, thank you for your library. I've set up action inside my root component, to call prompt modal

It's very simple but anyway app crashed when requestTrackingPermission() triggered

`const onCheckUserTrackingPermission = useCallback(async () => {
try {
const trackingStatus = await getTrackingStatus();

  if (trackingStatus === 'not-determined') {
    return await requestTrackingPermission();
  }

  if (trackingStatus === 'authorized' || trackingStatus === 'unavailable') {
    return;
  }
} catch (error) {}

}, []);

useEffect(() => { onCheckUserTrackingPermission(); }, [onCheckUserTrackingPermission]);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.