Skip to content

Commit 8e529d1

Browse files
Update README.md
1 parent 2eba1de commit 8e529d1

1 file changed

Lines changed: 23 additions & 41 deletions

File tree

README.md

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ yarn add react-native-install-referrer
1616

1717
### Android
1818

19-
No manual linking needed (auto-linked). The library adds `com.android.installreferrer:installreferrer:2.2` to your Android build automatically via `build.gradle`.
19+
No manual linking needed (auto-linked). The library adds `com.android.installreferrer:installreferrer:2.2` to your Android build automatically.
2020

2121
Make sure Google Play Store is installed on the test device — the API is backed by a Play Store service.
2222

2323
### iOS
2424

25-
No additional setup needed. All methods return `null` on iOS. Check for `null` before using results.
25+
No additional setup needed. All methods return `null` on iOS. Always null-check before using results.
2626

2727
---
2828

@@ -48,7 +48,7 @@ const details = await getReferrerDetails();
4848
// instantExperience: false,
4949
// }
5050

51-
// Parse UTM parameters
51+
// Parse UTM parameters from the referrer string
5252
const utm = parseReferrer(referrer ?? '');
5353
// { utm_source: 'google', utm_medium: 'cpc', utm_campaign: 'launch' }
5454
```
@@ -59,42 +59,40 @@ const utm = parseReferrer(referrer ?? '');
5959

6060
### `getInstallReferrer(): Promise<string | null>`
6161

62-
Returns the raw install referrer string as provided by Google Play.
62+
Returns the raw install referrer string from Google Play.
6363

64-
- **Android** — Resolves with the referrer string (empty string `""` if no referrer was set).
64+
- **Android** — Resolves with the referrer string. Returns `""` if no referrer was set.
6565
- **iOS** — Resolves with `null`.
66-
- **Throws** — Rejects with a standardized error code (see [Error Codes](#error-codes)) on failure.
66+
- **Throws** — Rejects with a standardized error code on failure (see [Error Codes](#error-codes)).
6767

68-
Results are **cached** after the first successful call — subsequent calls return immediately without a native round-trip.
68+
Result is **cached** after the first successful call — subsequent calls return immediately without a native round-trip.
6969

7070
---
7171

7272
### `getReferrerDetails(): Promise<ReferrerDetails | null>`
7373

74-
Returns the full referrer details object.
74+
Returns full referrer details including timestamps and instant-experience flag.
7575

7676
```ts
7777
type ReferrerDetails = {
7878
referrer: string;
79-
/** Unix timestamp in milliseconds */
80-
clickTimestamp: number;
81-
/** Unix timestamp in milliseconds */
82-
installTimestamp: number;
79+
clickTimestamp: number; // Unix timestamp in milliseconds
80+
installTimestamp: number; // Unix timestamp in milliseconds
8381
instantExperience: boolean;
8482
};
8583
```
8684

87-
- **Android** — Resolves with the full details.
85+
- **Android** — Resolves with the full details object.
8886
- **iOS** — Resolves with `null`.
8987
- **Throws** — Rejects with a standardized error code on failure.
9088

91-
Results are **cached** after the first successful call.
89+
Result is **cached** after the first successful call.
9290

9391
---
9492

9593
### `parseReferrer(referrer: string): Record<string, string>`
9694

97-
Parses a URL-encoded referrer string into a plain key/value object. Handles percent-encoding and `+`-as-space correctly.
95+
Parses a URL-encoded referrer string into a plain key/value object. Handles percent-encoding and `+`-as-space.
9896

9997
```ts
10098
parseReferrer('utm_source=google&utm_medium=cpc&utm_campaign=Q4+launch');
@@ -103,28 +101,22 @@ parseReferrer('utm_source=google&utm_medium=cpc&utm_campaign=Q4+launch');
103101

104102
---
105103

106-
### `clearCache(): void`
107-
108-
Clears the in-memory cache so the next call to `getInstallReferrer` or `getReferrerDetails` fetches fresh data from native. Useful in tests.
109-
110-
---
111-
112104
## Error Codes
113105

114-
When a native call fails, the Promise is rejected with an `Error` whose `code` property is one of:
106+
When a native call fails the Promise is rejected. The error `code` will be one of:
115107

116108
| Code | Cause |
117109
|---|---|
118-
| `SERVICE_UNAVAILABLE` | Play Store is not installed, or the referrer service is unavailable / disconnected |
110+
| `SERVICE_UNAVAILABLE` | Play Store is not installed, or the referrer service disconnected |
119111
| `FEATURE_NOT_SUPPORTED` | The installed Play Store version does not support the Install Referrer API |
120112
| `UNKNOWN_ERROR` | An unexpected response code was returned |
121113

122114
```ts
123115
try {
124116
const referrer = await getInstallReferrer();
125-
} catch (e) {
126-
if ((e as any).code === 'SERVICE_UNAVAILABLE') {
127-
// Handle gracefully — e.g. sideloaded APK, non-Play device
117+
} catch (e: any) {
118+
if (e.code === 'SERVICE_UNAVAILABLE') {
119+
// Sideloaded APK or non-Play device — handle gracefully
128120
}
129121
}
130122
```
@@ -133,26 +125,16 @@ try {
133125

134126
## Android Notes
135127

136-
- The referrer string is set by Google Play at install time and is only available for **90 days** after installation.
137-
- Sideloaded APKs (not installed via Play Store) will receive an empty referrer string.
138-
- The API requires the device to have Google Play Services installed.
139-
- Timestamps returned by the native API are in **seconds**; this library converts them to **milliseconds** for JavaScript consistency.
128+
- The referrer string is available for **90 days** after installation.
129+
- Sideloaded APKs (not installed via Play Store) will return an empty referrer string.
130+
- Requires Google Play Store to be installed on the device.
131+
- The native API returns timestamps in **seconds**this library converts them to **milliseconds** so `new Date(clickTimestamp)` works directly.
140132

141133
---
142134

143135
## iOS Limitation
144136

145-
Google Play Install Referrer is an Android-only API. There is no equivalent mechanism on iOS. All methods in this library resolve with `null` on iOS. To attribute iOS installs, use the [SKAdNetwork API](https://developer.apple.com/documentation/storekit/skadnetwork) or a third-party attribution SDK.
146-
147-
---
148-
149-
## Example App
150-
151-
See [example/src/App.tsx](example/src/App.tsx) for a complete working example that:
152-
153-
- Fetches the referrer string and full details on mount
154-
- Displays click/install timestamps as ISO date strings
155-
- Renders parsed UTM parameters in a list
137+
Google Play Install Referrer is an Android-only API. All methods in this library resolve with `null` on iOS. For iOS install attribution, refer to [SKAdNetwork](https://developer.apple.com/documentation/storekit/skadnetwork) or a third-party attribution SDK.
156138

157139
---
158140

0 commit comments

Comments
 (0)