npm package: @leochaddad/capacitor-referrer
Description: Get Google Play Install Referrer details in Capacitor apps
Author: Leo Chaddad
Latest version: 0.0.2

# @leochaddad/capacitor-referrer

Get Google Play Install Referrer details in Capacitor apps using the latest [Google Play Install Referrer API](https://developer.android.com/google/play/installreferrer).

This plugin allows you to retrieve attribution information about how users installed your app from Google Play Store, including referrer URLs, timestamps, and instant app launch status.

## Features

- ✅ Uses the latest Install Referrer Library 2.2
- ✅ Compatible with Capacitor 7
- ✅ Full TypeScript support
- ✅ Comprehensive referrer details including server-side timestamps
- ✅ Install version tracking
- ✅ Google Play Instant detection

## Platform Support

- ✅ **Android**: Full support
- ❌ **iOS**: Not supported (Install Referrer is Android/Google Play only)
- ❌ **Web**: Not supported

## Install

```bash
npm install @leochaddad/capacitor-referrer
npx cap sync
```

## Usage

```typescript
import { CapacitorReferrer } from '@leochaddad/capacitor-referrer';

async function getInstallReferrer() {
  try {
    const referrerDetails = await CapacitorReferrer.getReferrerDetails();
    console.log('Referrer URL:', referrerDetails.referrerUrl);
    console.log('Click timestamp:', referrerDetails.referrerClickTimestampSeconds);
    console.log('Install timestamp:', referrerDetails.appInstallTimestampSeconds);
    console.log('Install version:', referrerDetails.installVersion);
    console.log('Is instant app:', referrerDetails.googlePlayInstantParam);
  } catch (error) {
    console.error('Error getting referrer:', error);
  }
}
```

## Use Cases

- **Attribution Tracking**: Identify which marketing campaigns drive app installs
- **Analytics**: Track user acquisition sources
- **A/B Testing**: Measure effectiveness of different promotional strategies
- **Fraud Detection**: Verify legitimate install sources

## API

<docgen-index>

* [`getReferrerDetails()`](#getreferrerdetails)
* [Interfaces](#interfaces)

</docgen-index>

<docgen-api>
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->

### getReferrerDetails()

```typescript
getReferrerDetails() => Promise<ReferrerDetails>
```

Retrieves the install referrer details from Google Play.
Note: This method only works on Android. On iOS/Web, it will reject with an error.

**Returns:** <code>Promise&lt;<a href="#referrerdetails">ReferrerDetails</a>&gt;</code>

--------------------


### Interfaces


#### ReferrerDetails

| Prop                                      | Type                 | Description                                                                             |
| ----------------------------------------- | -------------------- | --------------------------------------------------------------------------------------- |
| **`referrerUrl`**                         | <code>string</code>  | The referrer URL of the installed package.                                              |
| **`referrerClickTimestampSeconds`**       | <code>number</code>  | The timestamp in seconds when referrer click happened.                                  |
| **`appInstallTimestampSeconds`**          | <code>number</code>  | The timestamp in seconds when installation began.                                       |
| **`referrerClickTimestampServerSeconds`** | <code>number</code>  | The timestamp in seconds when the user first opened the app after installation.         |
| **`appInstallTimestampServerSeconds`**    | <code>number</code>  | The timestamp in seconds when the app installation began from the server's perspective. |
| **`installVersion`**                      | <code>string</code>  | The app's version at the time when the app was first installed.                         |
| **`googlePlayInstantParam`**              | <code>boolean</code> | Whether the instant experience was launched.                                            |

</docgen-api>