@sparkfabrik/react-native-idfa-aaid
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

@sparkfabrik/react-native-idfa-aaid

React Native module to get IDFA (iOS) or AAID (Android)

Intro

React Native is a framework for creating native mobile apps based on React.

The Advertising Identifier (IDFA on iOS, AAID on Android) is a device-specific, unique, resettable ID for advertising that allows developers and marketers to track activity for advertising purposes.

This npm module allows any mobile application built with React Native to access the Advertising ID, following the OS specific definition and user permissions.

The module output in the RN framework is the following:

interface AdvertisingInfoResponse {
  id: string; // the Advertising ID (or null if not defined/permitted)
  isAdTrackingLimited: boolean; // the user defined permission to track
}

Supported platform

  • Android
  • iOS

Installation

npm install @sparkfabrik/react-native-idfa-aaid

or

yarn add @sparkfabrik/react-native-idfa-aaid

Then run pod install in your ios folder after installation.

Usage

iOS configuration

For native apps, in info.plist make sure to add:

<key>NSUserTrackingUsageDescription</key>
<string>...</string>

For Expo apps, in app.json make sure to add:

{
  "expo": {
    "plugins": [
      [
        "expo-tracking-transparency",
        {
          "userTrackingPermission": "..."
        }
      ]
    ]
  }
}

React Native components

Example of a basic integration in a RN component.

import ReactNativeIdfaAaid, { AdvertisingInfoResponse } from '@sparkfabrik/react-native-idfa-aaid';

const MyComponent: React.FC = () => {
  const [idfa, setIdfa] = useState<string | null>();

  useEffect(() => {
    ReactNativeIdfaAaid.getAdvertisingInfo()
      .then((res: AdvertisingInfoResponse) =>
        !res.isAdTrackingLimited ? setIdfa(res.id) : setIdfa(null),
      )
      .catch((err) => {
        console.log(err);
        return setIdfa(null);
      });
  }, []);

Contributing

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

License

MIT

Package Sidebar

Install

npm i @sparkfabrik/react-native-idfa-aaid

Weekly Downloads

9,454

Version

1.1.1

License

MIT

Unpacked Size

545 kB

Total Files

132

Last publish

Collaborators

  • paolomainardi
  • monska85
  • edodusi