insert-affiliate-react-native-sdk 1.1.3 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DeepLinkIapProvider.d.ts +11 -10
- package/dist/DeepLinkIapProvider.js +142 -144
- package/dist/useDeepLinkIapProvider.d.ts +8 -6
- package/dist/useDeepLinkIapProvider.js +8 -8
- package/package.json +1 -1
- package/readme.md +205 -76
- package/src/DeepLinkIapProvider.tsx +179 -199
- package/src/useDeepLinkIapProvider.tsx +13 -13
package/readme.md
CHANGED
|
@@ -2,53 +2,70 @@
|
|
|
2
2
|
|
|
3
3
|
## Overview
|
|
4
4
|
|
|
5
|
-
The **InsertAffiliateReactNative SDK** is designed for React Native applications, providing seamless integration with the [Insert Affiliate platform](https://insertaffiliate.com).
|
|
5
|
+
The **InsertAffiliateReactNative SDK** is designed for React Native applications, providing seamless integration with the [Insert Affiliate platform](https://insertaffiliate.com). The InsertAffiliateReactNative SDK simplifies affiliate marketing for iOS apps with in-app-purchases, allowing developers to create a seamless user experience for affiliate tracking and monetisation.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
### Features
|
|
8
8
|
|
|
9
|
-
- **Unique Device
|
|
9
|
+
- **Unique Device ID**: Creates a unique ID to anonymously associate purchases with users for tracking purposes.
|
|
10
10
|
- **Affiliate Identifier Management**: Set and retrieve the affiliate identifier based on user-specific links.
|
|
11
|
-
- **In-App Purchase (IAP) Initialisation**: Easily reinitialise in-app purchases with
|
|
11
|
+
- **In-App Purchase (IAP) Initialisation**: Easily reinitialise in-app purchases with the option to validate using an affiliate identifier.
|
|
12
12
|
|
|
13
13
|
## Peer Dependencies
|
|
14
14
|
|
|
15
15
|
Before using this package, ensure you have the following dependencies installed:
|
|
16
16
|
|
|
17
17
|
- [react-native-iap](https://www.npmjs.com/package/react-native-iap)
|
|
18
|
-
- [react-native-branch](https://www.npmjs.com/package/react-native-branch)
|
|
19
18
|
- [axios](https://www.npmjs.com/package/axios)
|
|
20
19
|
|
|
20
|
+
## Getting Started
|
|
21
|
+
|
|
22
|
+
To get started with the InsertAffiliateReactNative SDK:
|
|
23
|
+
|
|
24
|
+
1. [Install the React Native Package](#installation)
|
|
25
|
+
2. [Initialise the SDK in App.tsx](#basic-usage)
|
|
26
|
+
3. [Set up in-app purchases (Required)](#in-app-purchase-setup-required)
|
|
27
|
+
4. [Set up deep linking (Required)](#deep-link-setup-required)
|
|
28
|
+
|
|
21
29
|
## Installation
|
|
22
30
|
|
|
23
|
-
To integrate the InsertAffiliateReactNative SDK into your
|
|
31
|
+
To integrate the InsertAffiliateReactNative SDK into your app:
|
|
24
32
|
|
|
33
|
+
1. Install the NPM package.
|
|
25
34
|
```bash
|
|
26
35
|
npm install insert-affiliate-react-native-sdk
|
|
27
36
|
```
|
|
28
37
|
|
|
29
|
-
## Usage
|
|
30
|
-
### Importing the SDK
|
|
31
|
-
Import the provider from the package:
|
|
32
|
-
|
|
38
|
+
## Basic Usage
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
import { DeepLinkIapProvider } from 'insert-affiliate-react-native-sdk';
|
|
36
|
-
```
|
|
40
|
+
### Initialisation in `App.tsx`
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
### Step 1: Wrap Your Application with the Iaptic Provider and Pass Context Properties
|
|
42
|
+
First, wrap your with our provider and call the `initialise` method early in your app's lifecycle:
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
```javascript
|
|
45
|
+
const Child = () => {
|
|
46
|
+
const {
|
|
47
|
+
referrerLink,
|
|
48
|
+
subscriptions,
|
|
49
|
+
iapLoading,
|
|
50
|
+
handleBuySubscription,
|
|
51
|
+
userId,
|
|
52
|
+
userPurchase,
|
|
53
|
+
trackEvent,
|
|
54
|
+
initialize,
|
|
55
|
+
isInitialized,
|
|
56
|
+
} = useDeepLinkIapProvider();
|
|
44
57
|
|
|
45
|
-
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
initialize("{{ your-company-code }}");
|
|
60
|
+
}, [initialize, isInitialized]);
|
|
61
|
+
|
|
62
|
+
// ...
|
|
63
|
+
|
|
64
|
+
}
|
|
46
65
|
|
|
47
|
-
```javascript
|
|
48
66
|
const App = () => {
|
|
49
67
|
return (
|
|
50
68
|
<DeepLinkIapProvider
|
|
51
|
-
iapSkus={IAP_SKUS}
|
|
52
69
|
iapticAppId="{{ your_iaptic_app_id }}"
|
|
53
70
|
iapticAppName="{{ your_iaptic_app_name }}"
|
|
54
71
|
iapticPublicKey="{{ your_iaptic_public_key }}">
|
|
@@ -57,63 +74,81 @@ const App = () => {
|
|
|
57
74
|
);
|
|
58
75
|
};
|
|
59
76
|
```
|
|
77
|
+
- Replace `{{ your_iaptic_app_id }}` with your **Iaptic App ID**. You can find this [here](https://www.iaptic.com/account).
|
|
78
|
+
- Replace `{{ your_iaptic_app_name }}` with your **Iaptic App Name**. You can find this [here](https://www.iaptic.com/account).
|
|
79
|
+
- Replace `{{ your_iaptic_public_key }}` with your **Iaptic Public Key**. You can find this [here](https://www.iaptic.com/settings).
|
|
80
|
+
- Replace `{{ your_company_code }}` with the unique company code associated with your Insert Affiliate account. You can find this code in your dashboard under [Settings](http://app.insertaffiliate.com/settings).
|
|
81
|
+
|
|
82
|
+
## In-App Purchase Setup [Required]
|
|
83
|
+
Insert Affiliate requires a Receipt Verification platform to validate in-app purchases. You must choose **one** of our supported partners:
|
|
84
|
+
- [Iaptic](https://www.iaptic.com/account)
|
|
85
|
+
- [RevenueCat](https://www.revenuecat.com/)
|
|
60
86
|
|
|
61
|
-
|
|
62
|
-
|
|
87
|
+
### Option 1: Iaptic Integration
|
|
88
|
+
First, complete the [Iaptic account setup](https://www.iaptic.com/signup) and code integration.
|
|
63
89
|
|
|
64
|
-
|
|
90
|
+
Then after setting up the in app purchase (IAP) with Iaptic, call Insert Affiliate's handlePurchaseValidation on purchase.
|
|
65
91
|
|
|
66
92
|
```javascript
|
|
67
93
|
import React from 'react';
|
|
68
94
|
import { ActivityIndicator, Button, StyleSheet, Text, View } from 'react-native';
|
|
69
95
|
import { DeepLinkIapProvider, useDeepLinkIapProvider } from 'insert-affiliate-react-native-sdk';
|
|
96
|
+
import { useIAP, requestSubscription, withIAPContext, getProducts, getSubscriptions, initConnection } from "react-native-iap";
|
|
70
97
|
|
|
71
98
|
const Child = () => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
const {
|
|
100
|
+
initialize,
|
|
101
|
+
isInitialized,
|
|
102
|
+
handlePurchaseValidation,
|
|
103
|
+
} = useDeepLinkIapProvider();
|
|
104
|
+
|
|
105
|
+
const [iapLoading, setIapLoading] = useState(false);
|
|
106
|
+
const { currentPurchase, connected } = useIAP();
|
|
107
|
+
|
|
108
|
+
// ***...***
|
|
109
|
+
// Fetch & Load your subscription/purchases and handling the IAP purchase here as per the Iaptic Documentation...
|
|
110
|
+
// ***...***
|
|
111
|
+
|
|
112
|
+
// Initialize the Insert Affiliate SDK at the earliest possible moment
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (!isInitialized) {
|
|
115
|
+
initialize("{{ your_company_code }}");
|
|
116
|
+
}
|
|
117
|
+
}, [initialize, isInitialized]);
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
// Validate the purchase with Iaptic through Insert Affiliate's SDK for Affiliate Tracking
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
if (currentPurchase) {
|
|
123
|
+
handlePurchaseValidation(currentPurchase).then((isValid: boolean) => {
|
|
124
|
+
if (isValid) {
|
|
125
|
+
console.log("Purchase validated successfully.");
|
|
126
|
+
} else {
|
|
127
|
+
console.error("Purchase validation failed.");
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}, [currentPurchase, handlePurchaseValidation]);
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<View>
|
|
135
|
+
<Button
|
|
136
|
+
disabled={iapLoading}
|
|
137
|
+
title={`Click to Buy Subscription`}
|
|
138
|
+
onPress={() => handleBuySubscription("oneMonthSubscriptionTwo")}
|
|
139
|
+
/>
|
|
140
|
+
{iapLoading && <ActivityIndicator size={"small"} color={"black"} />}
|
|
141
|
+
</View>
|
|
142
|
+
);
|
|
107
143
|
};
|
|
108
144
|
|
|
109
145
|
const App = () => {
|
|
110
146
|
return (
|
|
111
147
|
// Wrapped application code from the previous step...
|
|
112
148
|
<DeepLinkIapProvider
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
iapticPublicKey="your_iaptic_public_key">
|
|
149
|
+
iapticAppId="{{ your_iaptic_app_id }}"
|
|
150
|
+
iapticAppName="{{ your_iaptic_app_name }}"
|
|
151
|
+
iapticPublicKey="{{ your_iaptic_public_key }}">
|
|
117
152
|
<Child />
|
|
118
153
|
</DeepLinkIapProvider>
|
|
119
154
|
);
|
|
@@ -121,15 +156,89 @@ const App = () => {
|
|
|
121
156
|
|
|
122
157
|
export default App;
|
|
123
158
|
```
|
|
159
|
+
- Replace `{{ your_iaptic_app_id }}` with your **Iaptic App ID**. You can find this [here](https://www.iaptic.com/account).
|
|
160
|
+
- Replace `{{ your_iaptic_app_name }}` with your **Iaptic App Name**. You can find this [here](https://www.iaptic.com/account).
|
|
161
|
+
- Replace `{{ your_iaptic_public_key }}` with your **Iaptic Public Key**. You can find this [here](https://www.iaptic.com/settings).
|
|
162
|
+
- Replace `{{ your_company_code }}` with the unique company code associated with your Insert Affiliate account. You can find this code in your dashboard under [Settings](http://app.insertaffiliate.com/settings).
|
|
163
|
+
|
|
164
|
+
### Option 2: RevenueCat Integration
|
|
165
|
+
<!--#### 1. Code Setup-->
|
|
166
|
+
<!--First, complete the [RevenueCat SDK installation](https://www.revenuecat.com/docs/getting-started/installation/ios). Then modify your `AppDelegate.swift`:-->
|
|
167
|
+
|
|
168
|
+
COMING SOON...
|
|
169
|
+
|
|
170
|
+
## Deep Link Setup [Required]
|
|
171
|
+
|
|
172
|
+
### Step 1: Add the Deep Linking Platform Dependency
|
|
173
|
+
|
|
174
|
+
In this example, the deep linking functionality is implemented using [Branch.io](https://dashboard.branch.io/).
|
|
175
|
+
|
|
176
|
+
Any alternative deep linking platform can be used by passing the referring link to ```InsertAffiliateSwift.setInsertAffiliateIdentifier(referringLink: "{{ link }}")``` as in the below Branch.io example
|
|
177
|
+
|
|
178
|
+
After setting up your Branch integration, add the following code to your ```index.js```
|
|
179
|
+
|
|
180
|
+
<!--#### Example with RevenueCat-->
|
|
181
|
+
<!--```swift-->
|
|
182
|
+
<!--import SwiftUI-->
|
|
183
|
+
<!--import BranchSDK-->
|
|
184
|
+
<!--import InAppPurchaseLib-->
|
|
185
|
+
<!--import InsertAffiliateSwift-->
|
|
186
|
+
|
|
187
|
+
<!--class AppDelegate: UIResponder, UIApplicationDelegate {-->
|
|
188
|
+
<!-- func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {-->
|
|
189
|
+
<!-- Branch.getInstance().initSession(launchOptions: launchOptions) { (params, error) in-->
|
|
190
|
+
<!-- if let referringLink = params?["~referring_link"] as? String {-->
|
|
191
|
+
<!-- InsertAffiliateSwift.setInsertAffiliateIdentifier(referringLink: referringLink) { result in-->
|
|
192
|
+
<!-- guard let shortCode = result else {-->
|
|
193
|
+
<!-- return-->
|
|
194
|
+
<!-- }-->
|
|
195
|
+
|
|
196
|
+
<!-- Purchases.shared.logIn(shortCode) { (customerInfo, created, error) in-->
|
|
197
|
+
<!-- // customerInfo updated for my_app_user_id. If you are having issues, you can investigate here.-->
|
|
198
|
+
<!-- }-->
|
|
199
|
+
<!-- }-->
|
|
200
|
+
<!-- }-->
|
|
201
|
+
<!-- return true-->
|
|
202
|
+
<!-- }-->
|
|
203
|
+
<!--}-->
|
|
204
|
+
<!--```-->
|
|
205
|
+
|
|
206
|
+
#### Example with Iaptic
|
|
207
|
+
```swift
|
|
208
|
+
import branch from 'react-native-branch';
|
|
209
|
+
import { DeepLinkIapProvider, useDeepLinkIapProvider } from 'insert-affiliate-react-native-sdk';
|
|
124
210
|
|
|
211
|
+
branch.subscribe(async ({ error, params }) => {
|
|
212
|
+
if (error) {
|
|
213
|
+
console.error('Error from Branch: ' + error);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (params['+clicked_branch_link']) {
|
|
218
|
+
if (params["~referring_link"]) {
|
|
219
|
+
setInsertAffiliateIdentifier(params["~referring_link"], (shortLink) => {
|
|
220
|
+
console.log("Insert Affiliate - setInsertAffiliateIdentifier: ", params["~referring_link"], " - Stored shortLink ", shortLink);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
```
|
|
125
227
|
|
|
126
|
-
##
|
|
228
|
+
## Additional Features
|
|
127
229
|
|
|
128
|
-
|
|
230
|
+
### 1. Event Tracking (Beta)
|
|
129
231
|
|
|
130
|
-
|
|
232
|
+
The **InsertAffiliateReactNative SDK** now includes a beta feature for event tracking. Use event tracking to log key user actions such as signups, purchases, or referrals. This is useful for:
|
|
233
|
+
- Understanding user behaviour.
|
|
234
|
+
- Measuring the effectiveness of marketing campaigns.
|
|
235
|
+
- Incentivising affiliates for designated actions being taken by the end users, rather than just in app purchases (i.e. pay an affilaite for each signup).
|
|
131
236
|
|
|
132
|
-
|
|
237
|
+
At this stage, we cannot guarantee that this feature is fully resistant to tampering or manipulation.
|
|
238
|
+
|
|
239
|
+
#### Using `trackEvent`
|
|
240
|
+
|
|
241
|
+
To track an event, use the `trackEvent` function. Make sure to set an affiliate identifier first; otherwise, event tracking won’t work. Here’s an example:
|
|
133
242
|
|
|
134
243
|
```javascript
|
|
135
244
|
const {
|
|
@@ -139,7 +248,6 @@ const {
|
|
|
139
248
|
handleBuySubscription,
|
|
140
249
|
userId,
|
|
141
250
|
userPurchase,
|
|
142
|
-
isIapticValidated,
|
|
143
251
|
trackEvent, // Required for trackEvent
|
|
144
252
|
} = useDeepLinkIapProvider();
|
|
145
253
|
|
|
@@ -152,15 +260,36 @@ const {
|
|
|
152
260
|
/>
|
|
153
261
|
```
|
|
154
262
|
|
|
155
|
-
###
|
|
156
|
-
Set the Affiliate Identifier (required for tracking):
|
|
263
|
+
### 2. Short Codes (Beta)
|
|
157
264
|
|
|
158
|
-
|
|
159
|
-
InsertAffiliateSwift.setInsertAffiliateIdentifier(referringLink: "your_affiliate_link")
|
|
160
|
-
```
|
|
265
|
+
#### What are Short Codes?
|
|
161
266
|
|
|
162
|
-
|
|
267
|
+
Short codes are unique, 10-character alphanumeric identifiers that affiliates can use to promote products or subscriptions. These codes are ideal for influencers or partners, making them easier to share than long URLs.
|
|
163
268
|
|
|
164
|
-
|
|
165
|
-
|
|
269
|
+
**Example Use Case**: An influencer promotes a subscription with the short code "JOIN12345" within their TikTok video's description. When users enter this code within your app during sign-up or before purchase, the app tracks the subscription back to the influencer for commission payouts.
|
|
270
|
+
|
|
271
|
+
For more information, visit the [Insert Affiliate Short Codes Documentation](https://docs.insertaffiliate.com/short-codes).
|
|
272
|
+
|
|
273
|
+
#### Setting a Short Code
|
|
274
|
+
|
|
275
|
+
Use the `setShortCode` method to associate a short code with an affiliate. This is ideal for scenarios where users enter the code via an input field, pop-up, or similar UI element.
|
|
276
|
+
|
|
277
|
+
Short codes must meet the following criteria:
|
|
278
|
+
- Exactly **10 characters long**.
|
|
279
|
+
- Contain only **letters and numbers** (alphanumeric characters).
|
|
280
|
+
- Replace {{ user_entered_short_code }} with the short code the user enters through your chosen input method, i.e. an input field / pop up element
|
|
281
|
+
|
|
282
|
+
```javascript
|
|
283
|
+
import {
|
|
284
|
+
DeepLinkIapProvider,
|
|
285
|
+
} from 'insert-affiliate-react-native-sdk';
|
|
286
|
+
|
|
287
|
+
const {
|
|
288
|
+
setShortCode,
|
|
289
|
+
} = useDeepLinkIapProvider();
|
|
290
|
+
|
|
291
|
+
<Button
|
|
292
|
+
title={'Set Short Code'}
|
|
293
|
+
onPress={() => setShortCode('JOIN123456')}
|
|
294
|
+
/>
|
|
166
295
|
```
|