insert-affiliate-react-native-sdk 1.2.9 → 1.3.4
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.js +11 -3
- package/package.json +1 -1
- package/readme.md +36 -32
- package/src/DeepLinkIapProvider.tsx +13 -6
|
@@ -44,6 +44,7 @@ const ASYNC_KEYS = {
|
|
|
44
44
|
REFERRER_LINK: "@app_referrer_link",
|
|
45
45
|
USER_PURCHASE: "@app_user_purchase",
|
|
46
46
|
USER_ID: "@app_user_id",
|
|
47
|
+
COMPANY_CODE: "@app_company_code",
|
|
47
48
|
};
|
|
48
49
|
// STARTING CONTEXT IMPLEMENTATION
|
|
49
50
|
exports.DeepLinkIapContext = (0, react_1.createContext)({
|
|
@@ -70,6 +71,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
70
71
|
}
|
|
71
72
|
if (companyCode && companyCode.trim() !== "") {
|
|
72
73
|
setCompanyCode(companyCode);
|
|
74
|
+
yield saveValueInAsync(ASYNC_KEYS.COMPANY_CODE, companyCode);
|
|
73
75
|
setIsInitialized(true);
|
|
74
76
|
console.log(`[Insert Affiliate] SDK initialized with company code: ${companyCode}`);
|
|
75
77
|
}
|
|
@@ -184,9 +186,15 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
184
186
|
yield storeInsertAffiliateIdentifier({ link: referringLink });
|
|
185
187
|
return;
|
|
186
188
|
}
|
|
187
|
-
if (!companyCode || companyCode.trim() === "") {
|
|
188
|
-
|
|
189
|
-
|
|
189
|
+
if (!companyCode || companyCode.trim() === "" && companyCode !== null) {
|
|
190
|
+
let companyCodeFromStorage = yield getValueFromAsync(ASYNC_KEYS.COMPANY_CODE);
|
|
191
|
+
if (companyCodeFromStorage !== null) {
|
|
192
|
+
setCompanyCode(companyCodeFromStorage);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
console.error("[Insert Affiliate] Company code is not set. Please initialize the SDK with a valid company code.");
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
190
198
|
}
|
|
191
199
|
// Check if referring link is already a short code, if so save it and stop here.
|
|
192
200
|
if (isShortCode(referringLink)) {
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -219,47 +219,51 @@ In this example, the deep linking functionality is implemented using [Branch.io]
|
|
|
219
219
|
|
|
220
220
|
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
|
|
221
221
|
|
|
222
|
-
After setting up your Branch integration, add the following code to your ```
|
|
222
|
+
After setting up your Branch integration, add the following code to your ```App.tsx```
|
|
223
223
|
|
|
224
224
|
#### Example with RevenueCat
|
|
225
225
|
```javascript
|
|
226
226
|
import { useDeepLinkIapProvider } from 'insert-affiliate-react-native-sdk';
|
|
227
227
|
|
|
228
|
-
|
|
228
|
+
//...
|
|
229
229
|
const {setInsertAffiliateIdentifier, returnInsertAffiliateIdentifier} = useDeepLinkIapProvider();
|
|
230
230
|
|
|
231
|
-
|
|
232
|
-
|
|
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
|
-
});
|
|
231
|
+
useEffect(() => {
|
|
232
|
+
if (!isInitialized) return;
|
|
254
233
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
234
|
+
const branchSubscription = branch.subscribe(async ({error, params}) => {
|
|
235
|
+
if (error) {
|
|
236
|
+
console.error('Error from Branch:', error);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
260
239
|
|
|
261
|
-
|
|
262
|
-
|
|
240
|
+
if (!params) {
|
|
241
|
+
return
|
|
242
|
+
}
|
|
243
|
+
if (params['+clicked_branch_link']) {
|
|
244
|
+
const referringLink = params['~referring_link'];
|
|
245
|
+
if (referringLink) {
|
|
246
|
+
try {
|
|
247
|
+
await setInsertAffiliateIdentifier(referringLink);
|
|
248
|
+
|
|
249
|
+
let insertAffiliateIdentifier = await returnInsertAffiliateIdentifier();
|
|
250
|
+
if (insertAffiliateIdentifier) {
|
|
251
|
+
const { customerInfo, created } = await Purchases.logIn(insertAffiliateIdentifier);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
} catch (err) {
|
|
255
|
+
console.error('Error setting affiliate identifier:', err);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
// Cleanup the subscription on component unmount
|
|
262
|
+
return () => {
|
|
263
|
+
branchSubscription();
|
|
264
|
+
};
|
|
265
|
+
}, [setInsertAffiliateIdentifier, isInitialized]);
|
|
266
|
+
//...
|
|
263
267
|
```
|
|
264
268
|
|
|
265
269
|
#### Example with Iaptic
|
|
@@ -49,6 +49,7 @@ const ASYNC_KEYS = {
|
|
|
49
49
|
REFERRER_LINK: "@app_referrer_link",
|
|
50
50
|
USER_PURCHASE: "@app_user_purchase",
|
|
51
51
|
USER_ID: "@app_user_id",
|
|
52
|
+
COMPANY_CODE: "@app_company_code",
|
|
52
53
|
};
|
|
53
54
|
|
|
54
55
|
// STARTING CONTEXT IMPLEMENTATION
|
|
@@ -86,6 +87,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
|
|
|
86
87
|
|
|
87
88
|
if (companyCode && companyCode.trim() !== "") {
|
|
88
89
|
setCompanyCode(companyCode);
|
|
90
|
+
await saveValueInAsync(ASYNC_KEYS.COMPANY_CODE, companyCode);
|
|
89
91
|
setIsInitialized(true);
|
|
90
92
|
console.log(`[Insert Affiliate] SDK initialized with company code: ${companyCode}`);
|
|
91
93
|
} else {
|
|
@@ -207,7 +209,6 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
|
|
|
207
209
|
|
|
208
210
|
try {
|
|
209
211
|
await generateThenSetUserID();
|
|
210
|
-
|
|
211
212
|
console.log("[Insert Affiliate] Completed generateThenSetUserID within setInsertAffiliateIdentifier.");
|
|
212
213
|
|
|
213
214
|
if (!referringLink) {
|
|
@@ -216,11 +217,17 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
|
|
|
216
217
|
return;
|
|
217
218
|
}
|
|
218
219
|
|
|
219
|
-
if (!companyCode || companyCode.trim() === "") {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
)
|
|
223
|
-
|
|
220
|
+
if (!companyCode || companyCode.trim() === "" && companyCode !== null) {
|
|
221
|
+
let companyCodeFromStorage = await getValueFromAsync(ASYNC_KEYS.COMPANY_CODE);
|
|
222
|
+
|
|
223
|
+
if (companyCodeFromStorage !== null) {
|
|
224
|
+
setCompanyCode(companyCodeFromStorage);
|
|
225
|
+
} else {
|
|
226
|
+
console.error(
|
|
227
|
+
"[Insert Affiliate] Company code is not set. Please initialize the SDK with a valid company code."
|
|
228
|
+
);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
224
231
|
}
|
|
225
232
|
|
|
226
233
|
// Check if referring link is already a short code, if so save it and stop here.
|