> ## Documentation Index
> Fetch the complete documentation index at: https://docs.partnero.com/llms.txt
> Use this file to discover all available pages before exploring further.

# React Native SDK

> Link React Native app users to the partner who referred them, from a typed code, a partner app link or a Google Play install.

Use the Partnero React Native library to tell Partnero which partner referred an app user. After that, any purchase recorded for the user, through [RevenueCat](https://docs.partnero.com/integrations/revenuecat.md) or your backend, earns that partner a commission. The [Mobile apps](https://docs.partnero.com/guides/tracking/mobile-app.md) guide explains the whole flow.

* React Native 0.82+ (New Architecture), iOS 15.1+, Android 7.0 (API 24)+
* A thin wrapper around the [Swift](https://docs.partnero.com/sdks/swift.md) and [Android](https://docs.partnero.com/sdks/android.md) SDKs, so it behaves the same way on both platforms
* Uses only your **Program ID**, never your API key

Source: [github.com/partnero/partnero-react-native](https://github.com/partnero/partnero-react-native)

## Before you start

In Partnero, open **Program settings** and turn on **Enable mobile app claims** in the **Tracking for mobile apps** section. Until then, every claim fails with `code_not_found`.

Copy your **Program ID** from the program's **Integration** page. It's the same ID as in your PartneroJS snippet.

## Install

```bash theme={"system"}
npm install @partnero/react-native
cd ios && pod install
```

With Expo, use a [development build](https://docs.expo.dev/develop/development-builds/introduction/). The library has native code, so it doesn't run in Expo Go.

## Configure

Call `configure` once at launch, before any claim:

```ts theme={"system"}
import { Partnero } from '@partnero/react-native';

Partnero.configure({ programId: 'YOUR_PROGRAM_ID' });
```

The first call records when the app was first opened on this device, which the program's claim window counts from.

Referral links use `?aff=` by default. If yours use another parameter, such as `?ref=DANIEL20`, pass `referralParameter: 'ref'`.

## Claim a code the user enters

Claim the code when the user enters one. Pass the ID your purchases are reported under, such as the RevenueCat app user ID:

```ts theme={"system"}
import Purchases from 'react-native-purchases';
import { Partnero, PartneroError } from '@partnero/react-native';

try {
  const result = await Partnero.claim({
    code: 'DANIEL20',
    appUserId: await Purchases.getAppUserID(),
  });
  // result.status is 'claimed' or 'already_claimed'
} catch (error) {
  if (error instanceof PartneroError && error.code === 'code_not_found') {
    // show "That code isn't valid"
  } else {
    // network error or another refusal; see Claim results and failures
  }
}
```

Each user can be linked to one partner only, so the first successful claim is final. With RevenueCat, claim after `Purchases.logIn(...)`, since anonymous IDs are rejected.

If a code is used as both a partner's link key and a promotion code, say which one the user entered:

```ts theme={"system"}
await Partnero.claim({ code: 'DANIEL20', appUserId: user.id, codeType: 'promotion_code' });
```

Save the code on the RevenueCat customer as well. Then a purchase can still be credited to the partner if the claim request was lost:

```ts theme={"system"}
Purchases.setAttributes(Partnero.revenueCatAttributes('DANIEL20'));
```

## Claim from an opened link

When a [partner app link](https://docs.partnero.com/guides/tracking/mobile-app.md#partner-app-links) or a referral link opens your app, pass the URL on. `Linking` covers both the link that started the app and links that arrive while it's open:

```ts theme={"system"}
import { Linking } from 'react-native';

const claimLink = (url?: string | null) => {
  if (url) {
    Partnero.claimUrl({ url, appUserId: user.id }).catch(() => {});
  }
};

Linking.getInitialURL().then(claimLink);
Linking.addEventListener('url', ({ url }) => claimLink(url));
```

The code is read from `partnero_code`, or from your referral parameter, such as `https://example.com/?aff=DANIEL20`. The click ID is read from `partnero_click`. It resolves to `null` without calling Partnero for links with neither.

If the user isn't signed in yet, store the values and claim after sign-in:

```ts theme={"system"}
const code = await Partnero.codeFromUrl(url);
const clickId = await Partnero.clickIdFromUrl(url);

// after sign-in
if (code) {
  await Partnero.claim({ code, appUserId: user.id, clickId });
} else if (clickId) {
  await Partnero.claimClick({ clickId, appUserId: user.id });
}
```

With a deep linking provider such as AppsFlyer, Branch or Adjust, read the click from its callback and call `Partnero.claimClick({ clickId, appUserId })`.

## Claim a Google Play install

When the program has no deep link and a **Google Play** link is set, app links send Android users to Google Play with the code and click ID in the install referrer. Claim it once the user is signed in:

```ts theme={"system"}
await Partnero.claimFromInstallReferrer({ appUserId: user.id });
```

It resolves to `null` when the install didn't come from a partner link, and always on iOS, so you can call it on both platforms. Each install's referrer is claimed once. If Google Play can't be reached, or the claim fails because of a rate limit, a server error or the network, the next call tries again. Other refusals, such as an unknown code, are final for that install, so turn on mobile app claims before you release.

## Claim results and failures

The claim functions resolve to an object with a `status`:

| `status` | What it means |
| - | - |
| `claimed` | Partnero linked the user to the partner and created the customer |
| `already_claimed` | The user was linked to a partner before, and that link stays as it was |

Refusals reject with a `PartneroError`, whose `code` is one of:

| `code` | When |
| - | - |
| `not_configured` | `configure` wasn't called |
| `invalid_input` | A blank or malformed value. `field` says which one: `code`, `clickId`, `appUserId` or `programId` |
| `code_not_found` | No active code or click matches, or mobile app claims are off |
| `code_conflict` | The code matches more than one partner, or the claim window has closed |
| `rate_limited` | More than 30 claims a minute from one network. Try again in a minute |
| `network` | The request couldn't reach Partnero |
| `server` | Any other response, with the HTTP `status` |

The library never retries on its own.

## Privacy

The library sends Partnero the code, the click ID when there is one, the app user ID, the platform and the first launch date. It stores the first launch date and, on Android, whether the install referrer was claimed. It doesn't read device identifiers. The iOS privacy manifest declares the user ID. List the user ID as collected for **App Functionality** in your App Store privacy details and Google Play **Data safety** form if you don't already.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.