insert-affiliate-react-native-sdk 1.1.8 → 1.1.9
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/package.json +2 -2
- package/readme.md +135 -60
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "insert-affiliate-react-native-sdk",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "A package
|
|
3
|
+
"version": "1.1.9",
|
|
4
|
+
"description": "A package for connecting with the Insert Affiliate Platform to add app based affiliate marketing.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
package/readme.md
CHANGED
|
@@ -30,7 +30,7 @@ npm install insert-affiliate-react-native-sdk
|
|
|
30
30
|
|
|
31
31
|
## Basic Usage
|
|
32
32
|
|
|
33
|
-
Follow the steps below to install the SDK.
|
|
33
|
+
Follow the steps below to install the SDK.
|
|
34
34
|
|
|
35
35
|
#### Step 1: Initialisation in `App.tsx`
|
|
36
36
|
|
|
@@ -69,10 +69,70 @@ const App = () => {
|
|
|
69
69
|
|
|
70
70
|
## In-App Purchase Setup [Required]
|
|
71
71
|
Insert Affiliate requires a Receipt Verification platform to validate in-app purchases. You must choose **one** of our supported partners:
|
|
72
|
-
- [Iaptic](https://www.iaptic.com/account)
|
|
73
72
|
- [RevenueCat](https://www.revenuecat.com/)
|
|
73
|
+
- [Iaptic](https://www.iaptic.com/account)
|
|
74
|
+
|
|
75
|
+
### Option 1: RevenueCat Integration
|
|
76
|
+
#### Step 1. Code Setup
|
|
77
|
+
First, complete the [RevenueCat SDK installation](https://www.revenuecat.com/docs/getting-started/installation/reactnative). Then modify your `App.tsx`:
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
import {
|
|
81
|
+
DeepLinkIapProvider,
|
|
82
|
+
useDeepLinkIapProvider,
|
|
83
|
+
} from 'insert-affiliate-react-native-sdk';
|
|
84
|
+
|
|
85
|
+
// ... //
|
|
86
|
+
const {
|
|
87
|
+
initialize,
|
|
88
|
+
isInitialized,
|
|
89
|
+
returnInsertAffiliateIdentifier
|
|
90
|
+
} = useDeepLinkIapProvider();
|
|
91
|
+
|
|
92
|
+
React.useEffect(() => {
|
|
93
|
+
const handleAffiliateLogin = async () => {
|
|
94
|
+
try {
|
|
95
|
+
if (isInitialized) {
|
|
96
|
+
const affiliateIdentifier = await returnInsertAffiliateIdentifier();
|
|
97
|
+
|
|
98
|
+
if (affiliateIdentifier) {
|
|
99
|
+
console.log('Logging into RevenueCat...');
|
|
100
|
+
const { customerInfo, created } = await Purchases.logIn(affiliateIdentifier);
|
|
101
|
+
|
|
102
|
+
if (created) {
|
|
103
|
+
console.log('New user created in RevenueCat:', customerInfo);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error('Error during affiliate login flow:', error);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
handleAffiliateLogin();
|
|
113
|
+
}, [isInitialized, returnInsertAffiliateIdentifier]);
|
|
114
|
+
// ... //
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### Step 2. Webhook Setup
|
|
118
|
+
|
|
119
|
+
1. Go to RevenueCat and [create a new webhook](https://www.revenuecat.com/docs/integrations/webhooks)
|
|
120
|
+
|
|
121
|
+
2. Configure the webhook with these settings:
|
|
122
|
+
- Webhook URL: `https://api.insertaffiliate.com/v1/api/revenuecat-webhook`
|
|
123
|
+
- Authorization header: Use the value from your Insert Affiliate dashboard (you'll get this in step 4)
|
|
74
124
|
|
|
75
|
-
|
|
125
|
+
3. In your [Insert Affiliate dashboard settings](https://app.insertaffiliate.com/settings):
|
|
126
|
+
- Navigate to the verification settings
|
|
127
|
+
- Set the in-app purchase verification method to `RevenueCat`
|
|
128
|
+
|
|
129
|
+
4. Back in your Insert Affiliate dashboard:
|
|
130
|
+
- Locate the `RevenueCat Webhook Authentication Header` value
|
|
131
|
+
- Copy this value
|
|
132
|
+
- Paste it as the Authorization header value in your RevenueCat webhook configuration
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
### Option 2: Iaptic Integration
|
|
76
136
|
First, complete the [Iaptic account setup](https://www.iaptic.com/signup) and code integration.
|
|
77
137
|
|
|
78
138
|
Then after setting up the in app purchase (IAP) with Iaptic, call Insert Affiliate's ```validatePurchaseWithIapticAPI``` on purchase.
|
|
@@ -99,39 +159,39 @@ const Child = () => {
|
|
|
99
159
|
|
|
100
160
|
// Initialize the Insert Affiliate SDK at the earliest possible moment
|
|
101
161
|
useEffect(() => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
162
|
+
if (!isInitialized) {
|
|
163
|
+
initialize("{{ your_company_code }}");
|
|
164
|
+
}
|
|
105
165
|
}, [initialize, isInitialized]);
|
|
106
166
|
|
|
107
167
|
|
|
108
168
|
// Validate the purchase with Iaptic through Insert Affiliate's SDK for Affiliate Tracking
|
|
109
169
|
useEffect(() => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
170
|
+
if (currentPurchase) {
|
|
171
|
+
validatePurchaseWithIapticAPI(
|
|
172
|
+
currentPurchase,
|
|
173
|
+
'{{ your_iaptic_app_id }}',
|
|
174
|
+
'{{ your_iaptic_app_name }}',
|
|
175
|
+
'{{ your_iaptic_public_key }}',
|
|
176
|
+
).then((isValid: boolean) => {
|
|
177
|
+
if (isValid) {
|
|
178
|
+
console.log("Purchase validated successfully.");
|
|
179
|
+
} else {
|
|
180
|
+
console.error("Purchase validation failed.");
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
124
184
|
}, [currentPurchase, handlePurchaseValidation]);
|
|
125
185
|
|
|
126
186
|
return (
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
187
|
+
<View>
|
|
188
|
+
<Button
|
|
189
|
+
disabled={iapLoading}
|
|
190
|
+
title={`Click to Buy Subscription`}
|
|
191
|
+
onPress={() => handleBuySubscription("oneMonthSubscriptionTwo")}
|
|
192
|
+
/>
|
|
193
|
+
{iapLoading && <ActivityIndicator size={"small"} color={"black"} />}
|
|
194
|
+
</View>
|
|
135
195
|
);
|
|
136
196
|
};
|
|
137
197
|
|
|
@@ -151,12 +211,6 @@ export default App;
|
|
|
151
211
|
- Replace `{{ your_iaptic_public_key }}` with your **Iaptic Public Key**. You can find this [here](https://www.iaptic.com/settings).
|
|
152
212
|
- 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).
|
|
153
213
|
|
|
154
|
-
### Option 2: RevenueCat Integration
|
|
155
|
-
<!--#### 1. Code Setup-->
|
|
156
|
-
<!--First, complete the [RevenueCat SDK installation](https://www.revenuecat.com/docs/getting-started/installation/ios). Then modify your `AppDelegate.swift`:-->
|
|
157
|
-
|
|
158
|
-
COMING SOON...
|
|
159
|
-
|
|
160
214
|
## Deep Link Setup [Required]
|
|
161
215
|
|
|
162
216
|
### Step 1: Add the Deep Linking Platform Dependency
|
|
@@ -167,31 +221,46 @@ Any alternative deep linking platform can be used by passing the referring link
|
|
|
167
221
|
|
|
168
222
|
After setting up your Branch integration, add the following code to your ```index.js```
|
|
169
223
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
224
|
+
#### Example with RevenueCat
|
|
225
|
+
```javascript
|
|
226
|
+
import { useDeepLinkIapProvider } from 'insert-affiliate-react-native-sdk';
|
|
227
|
+
|
|
228
|
+
const RootComponent = () => {
|
|
229
|
+
const {setInsertAffiliateIdentifier, returnInsertAffiliateIdentifier} = useDeepLinkIapProvider();
|
|
230
|
+
|
|
231
|
+
React.useEffect(() => {
|
|
232
|
+
const branchSubscription = branch.subscribe(async ({error, params}) => {
|
|
233
|
+
if (error) {
|
|
234
|
+
console.error('Error from Branch:', error);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (params['+clicked_branch_link']) {
|
|
239
|
+
const referringLink = params['~referring_link'];
|
|
240
|
+
if (referringLink) {
|
|
241
|
+
try {
|
|
242
|
+
await setInsertAffiliateIdentifier(referringLink);
|
|
243
|
+
|
|
244
|
+
let insertAffiliateIdentifier = await returnInsertAffiliateIdentifier();
|
|
245
|
+
if (insertAffiliateIdentifier) {
|
|
246
|
+
const { customerInfo, created } = await Purchases.logIn(insertAffiliateIdentifier);
|
|
247
|
+
}
|
|
248
|
+
} catch (err) {
|
|
249
|
+
console.error('Error setting affiliate identifier:', err);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
// Cleanup the subscription on component unmount
|
|
256
|
+
return () => {
|
|
257
|
+
branchSubscription();
|
|
258
|
+
};
|
|
259
|
+
}, [setInsertAffiliateIdentifier]);
|
|
260
|
+
|
|
261
|
+
return <App />;
|
|
262
|
+
};
|
|
263
|
+
```
|
|
195
264
|
|
|
196
265
|
#### Example with Iaptic
|
|
197
266
|
```javascript
|
|
@@ -232,7 +301,13 @@ To track an event, use the `trackEvent` function. Make sure to set an affiliate
|
|
|
232
301
|
|
|
233
302
|
```javascript
|
|
234
303
|
const {
|
|
235
|
-
|
|
304
|
+
referrerLink,
|
|
305
|
+
subscriptions,
|
|
306
|
+
iapLoading,
|
|
307
|
+
validatePurchaseWithIapticAPI,
|
|
308
|
+
userId,
|
|
309
|
+
userPurchase,
|
|
310
|
+
trackEvent, // Required for trackEvent
|
|
236
311
|
} = useDeepLinkIapProvider();
|
|
237
312
|
|
|
238
313
|
<Button
|