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

# Appbrew SDK

Source: https://docs.linkrunner.io/sdk/appbrew

Add Linkrunner attribution to an Appbrew Shopify app with the @linkrunner/appbrew tracker

**Before you start**

- For: App developers
- Time: About 30 minutes
- You need: An Appbrew app built on the @gauntlet packages, for iOS 15+ and Android minSdk 24
- You need: Your project token, added for your store in the Appbrew dashboard
- You need: A new app build and store release to ship the change

[Appbrew](https://appbrew.tech) builds Shopify mobile apps from config. `@linkrunner/appbrew` plugs Linkrunner into that system as an analytics tracker, so installs, events, revenue, identity, deep links, push opens and uninstalls are attributed without per-event code.

The package is an adapter over the [React Native SDK](https://docs.linkrunner.io/sdk/react-native). `rn-linkrunner` does the work; `@linkrunner/appbrew` translates Appbrew's events and lifecycle into SDK calls.

| Package                                                                    | Role                                                               |
| -------------------------------------------------------------------------- | ------------------------------------------------------------------ |
| [`@linkrunner/appbrew`](https://www.npmjs.com/package/@linkrunner/appbrew) | Appbrew tracker. `LinkrunnerTrackerV2 extends AnalyticsTrackerV2`. |
| [`rn-linkrunner`](https://www.npmjs.com/package/rn-linkrunner)             | Linkrunner React Native SDK. Native module.                        |

## Requirements

- An Appbrew app built on the `@gauntlet/*` packages
- `@linkrunner/appbrew` 0.3.0 or higher and `rn-linkrunner` 3.4.1 or higher
- iOS 15.0 or higher, Android minSdk 24
- A Linkrunner project token from [Project Settings](https://dashboard.linkrunner.io/dashboard/settings/project-details)

## 1. Install

```bash
pnpm add @linkrunner/appbrew rn-linkrunner
cd ios && pod install
```

> **Warning:**
>
> The package declares `requiresNativeBuild: true`. Adding or updating it needs a new binary build and a store release.

## 2. Register the tracker

In `src/app/App.tsx`, on the same provider as Appbrew's own trackers:

```typescript
import { AnalyticsProviderV2 } from '@gauntlet/analytics'
import { LinkrunnerTrackerV2 } from '@linkrunner/appbrew'

AnalyticsProviderV2.getInstance().addTracker(new LinkrunnerTrackerV2())
```

Apps on gauntlet 0.30 or higher use `AnalyticsProviderV2` as their `analytics` module. If your app still uses `AnalyticsProvider` there, register the tracker on `AnalyticsProvider` instead. The tracker only receives events from the provider your app sends them through.

Do not put the token in code. It arrives at runtime from the Appbrew dashboard.

> **Tip:**
>
> Sample apps register trackers inside `if (!__DEV__)`. Move this line outside that guard to test in a debug build, or pass `{ token, debug: true }` to the constructor for local runs only.

## 3. Configure in the Appbrew dashboard

The Appbrew team enters the settings per store. They reach the app as `config.integrations.linkrunner`, and the tracker reads them on every launch. Only `token` is required.

| Setting                                                              | Default  | Purpose                                                                                                 |
| -------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------- |
| `token`                                                              | required | Linkrunner project token. Without it the tracker stays disabled.                                        |
| `secretKey`, `keyId`                                                 | unset    | [SDK signing](https://dashboard.linkrunner.io/settings?s=sdk-signing).                                  |
| `debug`                                                              | `false`  | Verbose SDK logs.                                                                                       |
| `disableIdfa`                                                        | `false`  | Skip IDFA on iOS even when ATT is granted.                                                              |
| `enablePIIHashing`                                                   | `false`  | Hash email and phone on device before sending.                                                          |
| `trackScreenViews`                                                   | `false`  | Forward `screen_view` and `page_view`. Off because they are the highest-volume events.                  |
| `deeplinkRouting`                                                    | `true`   | Route the resolved deferred deep link into Appbrew's router.                                            |
| `uninstallTracking`                                                  | `true`   | Register the push token for [uninstall tracking](https://docs.linkrunner.io/sdk/react-native#uninstall-tracking).                 |
| `pushOpenAttribution`                                                | `true`   | Report push notification taps as re-engagements. See [Push notifications](https://docs.linkrunner.io/sdk/appbrew#push-notifications).         |
| `enableRefunds`                                                      | `false`  | Forward `refund` as `removePayment`. Verify order id mapping for your store first.                      |
| `consentIsEEA`, `consentAdUserData`, `consentAdPersonalization`      | unset    | Google Ads consent, each `granted`, `denied` or `unknown`. Sent before `init`. See [Consent](https://docs.linkrunner.io/sdk/appbrew#consent). |
| `enableTCFConsentCollection`                                         | `false`  | Let the SDK read TCF consent from the device CMP on Android.                                            |
| `clevertapIntegration`                                               | `true`   | Send the CleverTap ID to Linkrunner when `clevertap-react-native` is installed.                         |
| `analyticsIdentifiers`                                               | `true`   | Attach Firebase Analytics ids to `signup` and `setUserData`.                                            |
| `eventsMapper`, `paramsMapper`, `eventsWhitelist`, `paramsWhitelist` | unset    | Rename or restrict events and params (JSON).                                                            |

## 4. Native setup

**Android**

Exclude the SDK's preferences from auto-backup in `AndroidManifest.xml`, or a reinstall reads as an existing install:

```xml
<application
  android:dataExtractionRules="@xml/linkrunner_backup_rules"
  android:fullBackupContent="@xml/linkrunner_backup_descriptor">
```

Both resource files ship inside `rn-linkrunner`. Permissions and the Play Install Referrer dependency are merged automatically.

**iOS**

`pod install` only. Appbrew already presents the ATT prompt before trackers start, so no ATT handling is needed. Confirm `NSUserTrackingUsageDescription` is in `Info.plist`.

For Google Ads on iOS, add `pod 'GoogleAdsOnDeviceConversion'` as described in [Google Integrated Conversion Measurement](https://docs.linkrunner.io/features/google-icm).

Deep links need your Linkrunner domain in the iOS Associated Domains entitlement and an Android intent filter with `autoVerify`. Follow [Deep Linking Setup](https://docs.linkrunner.io/features/deep-linking-setup).

## What the tracker does on its own

| Appbrew                             | Linkrunner                                                                                |
| ----------------------------------- | ----------------------------------------------------------------------------------------- |
| App open                            | `init`, then `setCustomerUserId` with the device id so guests are attributed              |
| `purchase`                          | `capturePayment` with `transaction_id` as the payment id                                  |
| `refund`                            | `removePayment`, only when `enableRefunds` is on                                          |
| `signup`, `login`, customer details | `signup` once per install and customer, `setUserData` after                               |
| `logout`                            | Identity reset to the device id                                                           |
| Every other event                   | `trackEvent` with the Appbrew name unchanged, the Appbrew event's data as its [event parameters](https://docs.linkrunner.io/features/event-parameters), and Meta catalog fields added from `items[]` |
| Link opened with the app installed  | `handleDeeplink`. Appbrew routes it                                                       |
| Push notification tapped            | `handleDeeplink` with the push's `data.link`. Appbrew routes it                           |
| First open after install            | `getAttributionData`, and the deferred link is routed once per install                    |
| Push token                          | `setPushToken` for uninstall tracking                                                     |
| CleverTap installed                 | `setAdditionalData` with the CleverTap ID                                                 |
| Firebase Analytics installed        | `ga_app_instance_id` and `ga_session_id` on user data                                     |

Each event's Appbrew data arrives as [event parameters](https://docs.linkrunner.io/features/event-parameters), so you can filter and break down these events by it in the dashboard without writing tracking code.

> **Warning:**
>
> Map your events to standard commerce events in **Dashboard → Meta Ads → Event Mapping** (`add_to_cart` → `AddToCart`, `view_item` → `ViewContent`, payment type `DEFAULT` → `Purchase`). Without the mapping, events are stored but never sync to Meta.

## Using the attribution API

Everything above is automatic. Use these calls when your app needs the campaign context itself. Each is exported from `@linkrunner/appbrew` and waits for the tracker to initialise.

### Getting attribution data

Read the campaign that drove the install and the deferred deep link. Use it for [referral codes](https://docs.linkrunner.io/features/referral-codes) or campaign-specific onboarding.

```typescript
import { getAttributionData } from '@linkrunner/appbrew'

const attribution = await getAttributionData()
// { deeplink?: string, campaignData?: { id, name, type, adNetwork, ... } }
```

Returns `undefined` when no token is configured or the install has no attribution. One native call per launch, shared with deferred routing.

### Consent

Google Ads attribution needs consent before `init`. Without a consent management platform, set the three consent settings in the Appbrew dashboard. With one, call `setConsent` from its callback and again whenever the choice changes:

```typescript
import { setConsent } from '@linkrunner/appbrew'

setConsent({
  isEEA: 'granted',
  hasConsentForDataUsage: 'granted',
  hasConsentForAdsPersonalization: 'denied',
})
```

Leave a signal out rather than sending `unknown` as a denial. See [Google Integrated Conversion Measurement](https://docs.linkrunner.io/features/google-icm).

### Push notifications

Put a Linkrunner campaign link in the push and the tap is recorded as a re-engagement on that campaign. Nothing to add in your app.

Appbrew's push module routes a tap from the notification's `data.link` without going through React Native's `Linking`, so the tracker listens for push taps itself. It covers taps while the app is closed, in the background and open. A link that also comes back through `Linking` is reported once.

- Use the full campaign link as the push link, for example `https://links.yourstore.com/collections/joggers?c=AbC123`.
- A push that points at a screen instead of a url has no link to attribute.
- If your app calls `handleDeeplink` from its own push handlers (needed before 0.3.0), remove that code.
- Set `pushOpenAttribution` to `false` to turn it off.

> **Note:**
>
> On Android, a tap is not reported when the system killed the app's process but kept it in recents. React Native Firebase drops that tap before the app loads, so Appbrew does not open the push link either.

### Handling deep links yourself

Links that reach the app through some other channel, such as an in-app banner, can be reported by hand. The result says whether Linkrunner recognised the link:

```typescript
import { handleDeeplink } from '@linkrunner/appbrew'

const result = await handleDeeplink(url)
// { deeplink?: string, isLinkrunner: boolean, processing?: boolean }
```

### Extra user fields

`id` defaults to the current customer, or the device id for guests:

```typescript
import { setAdditionalData, setUserData } from '@linkrunner/appbrew'

await setUserData({ mixpanel_distinct_id: distinctId })
await setAdditionalData({ clevertapId })
```

The same five calls exist as methods on the `LinkrunnerTrackerV2` instance.

## Function Placement Guide

Register `LinkrunnerTrackerV2` once. The tracker handles the required React Native SDK calls below through Appbrew's lifecycle; do not duplicate them in your app. Incoming links and push notification taps are reported automatically. Call the exported `handleDeeplink` helper only for links that reach the app some other way.

| Function                                                                        | Requirement | Where to Place                                                                    | When to Call                                                |
| ------------------------------------------------------------------------------- | ----------- | --------------------------------------------------------------------------------- | ----------------------------------------------------------- |
| [`linkrunner.init`](https://docs.linkrunner.io/sdk/appbrew#2-register-the-tracker)                        | Required    | Appbrew tracker lifecycle (automatic)                                             | When the app opens with a configured token                  |
| [`linkrunner.signup`](https://docs.linkrunner.io/sdk/appbrew#what-the-tracker-does-on-its-own)            | Required    | Appbrew identity lifecycle (automatic)                                            | Once per install and customer                               |
| [`linkrunner.setCustomerUserId`](https://docs.linkrunner.io/sdk/appbrew#what-the-tracker-does-on-its-own) | Required    | Appbrew identity lifecycle (automatic)                                            | At app open and when the customer identity changes          |
| [`handleDeeplink`](https://docs.linkrunner.io/sdk/appbrew#handling-deep-links-yourself)                   | Required    | Automatic for incoming links and push taps; your own code only for other channels | When the app opens through a deep link or a push            |
| [`getAttributionData`](https://docs.linkrunner.io/sdk/appbrew#getting-attribution-data)                   | Optional    | Campaign-specific onboarding or referral flow                                     | When your app needs install attribution                     |
| [`setUserData`](https://docs.linkrunner.io/sdk/appbrew#extra-user-fields)                                 | Optional    | User data or analytics integration flow                                           | When you add fields to the current user                     |
| [`setAdditionalData`](https://docs.linkrunner.io/sdk/appbrew#extra-user-fields)                           | Optional    | Third-party integration setup                                                     | When the CleverTap ID is available                          |
| [`setConsent`](https://docs.linkrunner.io/sdk/appbrew#consent)                                            | Optional    | Consent settings or your CMP callback                                             | Before initialization and when consent changes              |
| [`linkrunner.trackEvent`](https://docs.linkrunner.io/sdk/appbrew#what-the-tracker-does-on-its-own)        | Optional    | Appbrew event lifecycle (automatic)                                               | When Appbrew emits an event                                 |
| [`linkrunner.capturePayment`](https://docs.linkrunner.io/sdk/appbrew#what-the-tracker-does-on-its-own)    | Optional    | Appbrew purchase lifecycle (automatic)                                            | When Appbrew emits `purchase`                               |
| [`linkrunner.removePayment`](https://docs.linkrunner.io/sdk/appbrew#what-the-tracker-does-on-its-own)     | Optional    | Appbrew refund lifecycle (automatic)                                              | When Appbrew emits `refund` and `enableRefunds` is on       |
| [`linkrunner.setPushToken`](https://docs.linkrunner.io/sdk/appbrew#what-the-tracker-does-on-its-own)      | Optional    | Appbrew push token lifecycle (automatic)                                          | When a push token is available and uninstall tracking is on |

## Testing

1. Build with `debug: true` and look for `Linkrunner initialised successfully` in the console.
2. Open [Events Settings](https://dashboard.linkrunner.io/dashboard/settings/events). The install and events appear as you use the app.
3. Place an order and confirm one payment appears. Relaunch and confirm it is not duplicated.
4. Install through a campaign link on a fresh device and confirm `getAttributionData()` returns the `deeplink`.
5. Send a push with a campaign link as `data.link`, tap it with the app closed, and confirm a re-engagement on that campaign.

See [Integration Testing](https://docs.linkrunner.io/testing/integration-testing) for the full checklist.

## Troubleshooting

| Symptom                                                     | Cause                                                                                                  |
| ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| `no token in config.integrations.linkrunner` in the console | The token is not set for this store in the Appbrew dashboard                                           |
| No events at all                                            | The tracker is registered inside `if (!__DEV__)`, or the whitelist excludes them                       |
| Events in Linkrunner but not in Meta                        | Event mapping missing under **Meta Ads → Event Mapping**                                               |
| Reinstalls counted as existing installs                     | Android backup rules missing from `AndroidManifest.xml`                                                |
| Deep link opens the app but does not navigate               | Domain verification incomplete. See [Deep Linking Setup](https://docs.linkrunner.io/features/deep-linking-setup)                 |
| Duplicate payments                                          | `capturePayment` also called from a Shopify webhook with a different payment id                        |
| `getAttributionData()` returns `undefined`                  | No token, or the app was installed directly from the store                                             |
| Push taps show no re-engagement                             | The push link is a screen, not a campaign url, or the app is on `@linkrunner/appbrew` older than 0.3.0 |

**Need help?** Contact <support@linkrunner.io>
