insert-affiliate-react-native-sdk 1.8.0 → 1.10.0
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 +7 -1
- package/dist/DeepLinkIapProvider.js +209 -17
- package/dist/index.d.ts +1 -1
- package/dist/useDeepLinkIapProvider.d.ts +2 -1
- package/dist/useDeepLinkIapProvider.js +2 -1
- package/docs/deep-linking-appsflyer.md +364 -0
- package/docs/deep-linking-branch.md +330 -0
- package/docs/dynamic-offer-codes.md +369 -0
- package/package.json +1 -1
- package/readme.md +600 -982
- package/src/DeepLinkIapProvider.tsx +256 -28
- package/src/index.ts +1 -1
- package/src/useDeepLinkIapProvider.tsx +2 -0
|
@@ -3,6 +3,11 @@ type T_DEEPLINK_IAP_PROVIDER = {
|
|
|
3
3
|
children: React.ReactNode;
|
|
4
4
|
};
|
|
5
5
|
export type InsertAffiliateIdentifierChangeCallback = (identifier: string | null) => void;
|
|
6
|
+
export type AffiliateDetails = {
|
|
7
|
+
affiliateName: string;
|
|
8
|
+
affiliateShortCode: string;
|
|
9
|
+
deeplinkurl: string;
|
|
10
|
+
} | null;
|
|
6
11
|
type CustomPurchase = {
|
|
7
12
|
[key: string]: any;
|
|
8
13
|
};
|
|
@@ -17,7 +22,8 @@ type T_DEEPLINK_IAP_CONTEXT = {
|
|
|
17
22
|
returnUserAccountTokenAndStoreExpectedTransaction: () => Promise<string | null>;
|
|
18
23
|
storeExpectedStoreTransaction: (purchaseToken: string) => Promise<void>;
|
|
19
24
|
trackEvent: (eventName: string) => Promise<void>;
|
|
20
|
-
setShortCode: (shortCode: string) => Promise<
|
|
25
|
+
setShortCode: (shortCode: string) => Promise<boolean>;
|
|
26
|
+
getAffiliateDetails: (affiliateCode: string) => Promise<AffiliateDetails>;
|
|
21
27
|
setInsertAffiliateIdentifier: (referringLink: string) => Promise<void | string>;
|
|
22
28
|
setInsertAffiliateIdentifierChangeCallback: (callback: InsertAffiliateIdentifierChangeCallback | null) => void;
|
|
23
29
|
handleInsertLinks: (url: string) => Promise<boolean>;
|
|
@@ -54,6 +54,8 @@ const ASYNC_KEYS = {
|
|
|
54
54
|
USER_ACCOUNT_TOKEN: '@app_user_account_token',
|
|
55
55
|
IOS_OFFER_CODE: '@app_ios_offer_code',
|
|
56
56
|
AFFILIATE_STORED_DATE: '@app_affiliate_stored_date',
|
|
57
|
+
SDK_INIT_REPORTED: '@app_sdk_init_reported',
|
|
58
|
+
REPORTED_AFFILIATE_ASSOCIATIONS: '@app_reported_affiliate_associations',
|
|
57
59
|
};
|
|
58
60
|
// STARTING CONTEXT IMPLEMENTATION
|
|
59
61
|
exports.DeepLinkIapContext = (0, react_1.createContext)({
|
|
@@ -67,7 +69,8 @@ exports.DeepLinkIapContext = (0, react_1.createContext)({
|
|
|
67
69
|
returnUserAccountTokenAndStoreExpectedTransaction: () => __awaiter(void 0, void 0, void 0, function* () { return ''; }),
|
|
68
70
|
storeExpectedStoreTransaction: (purchaseToken) => __awaiter(void 0, void 0, void 0, function* () { }),
|
|
69
71
|
trackEvent: (eventName) => __awaiter(void 0, void 0, void 0, function* () { }),
|
|
70
|
-
setShortCode: (shortCode) => __awaiter(void 0, void 0, void 0, function* () { }),
|
|
72
|
+
setShortCode: (shortCode) => __awaiter(void 0, void 0, void 0, function* () { return false; }),
|
|
73
|
+
getAffiliateDetails: (affiliateCode) => __awaiter(void 0, void 0, void 0, function* () { return null; }),
|
|
71
74
|
setInsertAffiliateIdentifier: (referringLink) => __awaiter(void 0, void 0, void 0, function* () { }),
|
|
72
75
|
setInsertAffiliateIdentifierChangeCallback: (callback) => { },
|
|
73
76
|
handleInsertLinks: (url) => __awaiter(void 0, void 0, void 0, function* () { return false; }),
|
|
@@ -111,6 +114,8 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
111
114
|
console.log('[Insert Affiliate] [VERBOSE] Company code saved to AsyncStorage');
|
|
112
115
|
console.log('[Insert Affiliate] [VERBOSE] SDK marked as initialized');
|
|
113
116
|
}
|
|
117
|
+
// Report SDK initialization for onboarding verification (fire and forget)
|
|
118
|
+
reportSdkInitIfNeeded(companyCode, verboseLogging);
|
|
114
119
|
}
|
|
115
120
|
else {
|
|
116
121
|
console.warn('[Insert Affiliate] SDK initialized without a company code.');
|
|
@@ -329,12 +334,24 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
329
334
|
verboseLog('Invalid URL provided to handleInsertLinkAndroid');
|
|
330
335
|
return false;
|
|
331
336
|
}
|
|
332
|
-
// Parse the URL to extract query parameters
|
|
333
|
-
|
|
334
|
-
|
|
337
|
+
// Parse the URL to extract query parameters (React Native compatible)
|
|
338
|
+
// URLSearchParams is not available in React Native, so parse manually
|
|
339
|
+
let insertAffiliate = null;
|
|
340
|
+
const queryIndex = url.indexOf('?');
|
|
341
|
+
if (queryIndex !== -1) {
|
|
342
|
+
const queryString = url.substring(queryIndex + 1);
|
|
343
|
+
const params = queryString.split('&');
|
|
344
|
+
for (const param of params) {
|
|
345
|
+
const [key, value] = param.split('=');
|
|
346
|
+
if (key === 'insertAffiliate' && value) {
|
|
347
|
+
insertAffiliate = decodeURIComponent(value);
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
335
352
|
if (insertAffiliate && insertAffiliate.length > 0) {
|
|
336
353
|
verboseLog(`Found insertAffiliate parameter: ${insertAffiliate}`);
|
|
337
|
-
yield storeInsertAffiliateIdentifier({ link: insertAffiliate });
|
|
354
|
+
yield storeInsertAffiliateIdentifier({ link: insertAffiliate, source: 'deep_link_android' });
|
|
338
355
|
return true;
|
|
339
356
|
}
|
|
340
357
|
else {
|
|
@@ -448,7 +465,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
448
465
|
// If we have insertAffiliate parameter, use it as the affiliate identifier
|
|
449
466
|
if (insertAffiliate && insertAffiliate.length > 0) {
|
|
450
467
|
verboseLog(`Found insertAffiliate parameter, setting as affiliate identifier: ${insertAffiliate}`);
|
|
451
|
-
yield storeInsertAffiliateIdentifier({ link: insertAffiliate });
|
|
468
|
+
yield storeInsertAffiliateIdentifier({ link: insertAffiliate, source: 'install_referrer' });
|
|
452
469
|
return true;
|
|
453
470
|
}
|
|
454
471
|
else {
|
|
@@ -512,7 +529,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
512
529
|
console.log(`[Insert Affiliate] Warning: URL company code (${companyCode}) doesn't match initialized company code (${activeCompanyCode})`);
|
|
513
530
|
}
|
|
514
531
|
// If URL scheme is used, we can straight away store the short code as the referring link
|
|
515
|
-
yield storeInsertAffiliateIdentifier({ link: shortCode });
|
|
532
|
+
yield storeInsertAffiliateIdentifier({ link: shortCode, source: 'deep_link_ios' });
|
|
516
533
|
// Collect and send enhanced system info to backend
|
|
517
534
|
try {
|
|
518
535
|
const enhancedSystemInfo = yield getEnhancedSystemInfo();
|
|
@@ -629,6 +646,87 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
629
646
|
break;
|
|
630
647
|
}
|
|
631
648
|
};
|
|
649
|
+
// Reports a new affiliate association to the backend for tracking.
|
|
650
|
+
// Only reports each unique affiliateIdentifier once to prevent duplicates.
|
|
651
|
+
const reportAffiliateAssociationIfNeeded = (affiliateIdentifier, source) => __awaiter(void 0, void 0, void 0, function* () {
|
|
652
|
+
try {
|
|
653
|
+
const activeCompanyCode = yield getActiveCompanyCode();
|
|
654
|
+
if (!activeCompanyCode) {
|
|
655
|
+
verboseLog('Cannot report affiliate association: no company code available');
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
// Get the set of already-reported affiliate identifiers
|
|
659
|
+
const reportedAssociationsJson = yield async_storage_1.default.getItem(ASYNC_KEYS.REPORTED_AFFILIATE_ASSOCIATIONS);
|
|
660
|
+
const reportedAssociations = reportedAssociationsJson ? JSON.parse(reportedAssociationsJson) : [];
|
|
661
|
+
// Check if this affiliate identifier has already been reported
|
|
662
|
+
if (reportedAssociations.includes(affiliateIdentifier)) {
|
|
663
|
+
verboseLog(`Affiliate association already reported for: ${affiliateIdentifier}, skipping`);
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
verboseLog(`Reporting new affiliate association: ${affiliateIdentifier} (source: ${source})`);
|
|
667
|
+
const response = yield fetch('https://api.insertaffiliate.com/V1/onboarding/affiliate-associated', {
|
|
668
|
+
method: 'POST',
|
|
669
|
+
headers: {
|
|
670
|
+
'Content-Type': 'application/json',
|
|
671
|
+
},
|
|
672
|
+
body: JSON.stringify({
|
|
673
|
+
companyId: activeCompanyCode,
|
|
674
|
+
affiliateIdentifier: affiliateIdentifier,
|
|
675
|
+
source: source,
|
|
676
|
+
timestamp: new Date().toISOString(),
|
|
677
|
+
}),
|
|
678
|
+
});
|
|
679
|
+
if (response.ok) {
|
|
680
|
+
// Add to reported set and persist
|
|
681
|
+
reportedAssociations.push(affiliateIdentifier);
|
|
682
|
+
yield async_storage_1.default.setItem(ASYNC_KEYS.REPORTED_AFFILIATE_ASSOCIATIONS, JSON.stringify(reportedAssociations));
|
|
683
|
+
verboseLog(`Affiliate association reported successfully for: ${affiliateIdentifier}`);
|
|
684
|
+
}
|
|
685
|
+
else {
|
|
686
|
+
verboseLog(`Affiliate association report failed with status: ${response.status}`);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
catch (error) {
|
|
690
|
+
// Silently fail - this is non-critical telemetry
|
|
691
|
+
verboseLog(`Affiliate association report error: ${error}`);
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
// Reports SDK initialization to the backend for onboarding verification.
|
|
695
|
+
// Only reports once per install to minimize server load.
|
|
696
|
+
const reportSdkInitIfNeeded = (companyCode, verboseLogging) => __awaiter(void 0, void 0, void 0, function* () {
|
|
697
|
+
try {
|
|
698
|
+
// Only report once per install
|
|
699
|
+
const alreadyReported = yield async_storage_1.default.getItem(ASYNC_KEYS.SDK_INIT_REPORTED);
|
|
700
|
+
if (alreadyReported === 'true') {
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
if (verboseLogging) {
|
|
704
|
+
console.log('[Insert Affiliate] Reporting SDK initialization for onboarding verification...');
|
|
705
|
+
}
|
|
706
|
+
const response = yield fetch('https://api.insertaffiliate.com/V1/onboarding/sdk-init', {
|
|
707
|
+
method: 'POST',
|
|
708
|
+
headers: {
|
|
709
|
+
'Content-Type': 'application/json',
|
|
710
|
+
},
|
|
711
|
+
body: JSON.stringify({ companyId: companyCode }),
|
|
712
|
+
});
|
|
713
|
+
if (response.ok) {
|
|
714
|
+
yield async_storage_1.default.setItem(ASYNC_KEYS.SDK_INIT_REPORTED, 'true');
|
|
715
|
+
if (verboseLogging) {
|
|
716
|
+
console.log('[Insert Affiliate] SDK initialization reported successfully');
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
else if (verboseLogging) {
|
|
720
|
+
console.log(`[Insert Affiliate] SDK initialization report failed with status: ${response.status}`);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
catch (error) {
|
|
724
|
+
// Silently fail - this is non-critical telemetry
|
|
725
|
+
if (verboseLogging) {
|
|
726
|
+
console.log(`[Insert Affiliate] SDK initialization report error: ${error}`);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
});
|
|
632
730
|
// MARK: - Deep Linking Utilities
|
|
633
731
|
// Retrieves and validates clipboard content for UUID format
|
|
634
732
|
const getClipboardUUID = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -994,7 +1092,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
994
1092
|
if (matchFound && response.data.matched_affiliate_shortCode && response.data.matched_affiliate_shortCode.length > 0) {
|
|
995
1093
|
const matchedShortCode = response.data.matched_affiliate_shortCode;
|
|
996
1094
|
verboseLog(`Storing Matched short code from backend: ${matchedShortCode}`);
|
|
997
|
-
yield storeInsertAffiliateIdentifier({ link: matchedShortCode });
|
|
1095
|
+
yield storeInsertAffiliateIdentifier({ link: matchedShortCode, source: 'clipboard_match' });
|
|
998
1096
|
}
|
|
999
1097
|
}
|
|
1000
1098
|
// Check for a successful response
|
|
@@ -1019,6 +1117,84 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1019
1117
|
const isValidCharacters = /^[a-zA-Z0-9_]+$/.test(referringLink);
|
|
1020
1118
|
return isValidCharacters && referringLink.length >= 3 && referringLink.length <= 25;
|
|
1021
1119
|
};
|
|
1120
|
+
const checkAffiliateExists = (affiliateCode) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1121
|
+
try {
|
|
1122
|
+
const activeCompanyCode = yield getActiveCompanyCode();
|
|
1123
|
+
if (!activeCompanyCode) {
|
|
1124
|
+
verboseLog('Cannot check affiliate: no company code available');
|
|
1125
|
+
return false;
|
|
1126
|
+
}
|
|
1127
|
+
const url = 'https://api.insertaffiliate.com/V1/checkAffiliateExists';
|
|
1128
|
+
const payload = {
|
|
1129
|
+
companyId: activeCompanyCode,
|
|
1130
|
+
affiliateCode: affiliateCode
|
|
1131
|
+
};
|
|
1132
|
+
verboseLog(`Checking if affiliate exists: ${affiliateCode}`);
|
|
1133
|
+
const response = yield axios_1.default.post(url, payload, {
|
|
1134
|
+
headers: {
|
|
1135
|
+
'Content-Type': 'application/json',
|
|
1136
|
+
},
|
|
1137
|
+
});
|
|
1138
|
+
verboseLog(`Affiliate check response: ${JSON.stringify(response.data)}`);
|
|
1139
|
+
if (response.status === 200 && response.data) {
|
|
1140
|
+
const exists = response.data.exists === true;
|
|
1141
|
+
if (exists) {
|
|
1142
|
+
verboseLog(`Affiliate ${affiliateCode} exists and is valid`);
|
|
1143
|
+
}
|
|
1144
|
+
else {
|
|
1145
|
+
verboseLog(`Affiliate ${affiliateCode} does not exist`);
|
|
1146
|
+
}
|
|
1147
|
+
return exists;
|
|
1148
|
+
}
|
|
1149
|
+
else {
|
|
1150
|
+
verboseLog(`Unexpected response checking affiliate: status ${response.status}`);
|
|
1151
|
+
return false;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
catch (error) {
|
|
1155
|
+
verboseLog(`Error checking affiliate exists: ${error}`);
|
|
1156
|
+
return false;
|
|
1157
|
+
}
|
|
1158
|
+
});
|
|
1159
|
+
const getAffiliateDetails = (affiliateCode) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1160
|
+
try {
|
|
1161
|
+
const activeCompanyCode = yield getActiveCompanyCode();
|
|
1162
|
+
if (!activeCompanyCode) {
|
|
1163
|
+
verboseLog('Cannot get affiliate details: no company code available');
|
|
1164
|
+
return null;
|
|
1165
|
+
}
|
|
1166
|
+
const url = 'https://api.insertaffiliate.com/V1/checkAffiliateExists';
|
|
1167
|
+
const payload = {
|
|
1168
|
+
companyId: activeCompanyCode,
|
|
1169
|
+
affiliateCode: affiliateCode
|
|
1170
|
+
};
|
|
1171
|
+
verboseLog(`Getting affiliate details for: ${affiliateCode}`);
|
|
1172
|
+
const response = yield axios_1.default.post(url, payload, {
|
|
1173
|
+
headers: {
|
|
1174
|
+
'Content-Type': 'application/json',
|
|
1175
|
+
},
|
|
1176
|
+
});
|
|
1177
|
+
verboseLog(`Affiliate details response: ${JSON.stringify(response.data)}`);
|
|
1178
|
+
if (response.status === 200 && response.data && response.data.exists === true) {
|
|
1179
|
+
const affiliate = response.data.affiliate;
|
|
1180
|
+
if (affiliate) {
|
|
1181
|
+
verboseLog(`Retrieved affiliate details: ${JSON.stringify(affiliate)}`);
|
|
1182
|
+
return {
|
|
1183
|
+
affiliateName: affiliate.affiliateName || '',
|
|
1184
|
+
affiliateShortCode: affiliate.affiliateShortCode || '',
|
|
1185
|
+
deeplinkurl: affiliate.deeplinkurl || ''
|
|
1186
|
+
};
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
verboseLog(`Affiliate ${affiliateCode} not found or invalid response`);
|
|
1190
|
+
return null;
|
|
1191
|
+
}
|
|
1192
|
+
catch (error) {
|
|
1193
|
+
verboseLog(`Error getting affiliate details: ${error}`);
|
|
1194
|
+
console.error('[Insert Affiliate] Error getting affiliate details:', error);
|
|
1195
|
+
return null;
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1022
1198
|
function setShortCode(shortCode) {
|
|
1023
1199
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1024
1200
|
console.log('[Insert Affiliate] Setting short code.');
|
|
@@ -1026,8 +1202,18 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1026
1202
|
// Validate it is a short code
|
|
1027
1203
|
const capitalisedShortCode = shortCode.toUpperCase();
|
|
1028
1204
|
isShortCode(capitalisedShortCode);
|
|
1029
|
-
//
|
|
1030
|
-
yield
|
|
1205
|
+
// Check if the affiliate exists before storing
|
|
1206
|
+
const exists = yield checkAffiliateExists(capitalisedShortCode);
|
|
1207
|
+
if (exists) {
|
|
1208
|
+
// If affiliate exists, set the Insert Affiliate Identifier
|
|
1209
|
+
yield storeInsertAffiliateIdentifier({ link: capitalisedShortCode, source: 'short_code_manual' });
|
|
1210
|
+
console.log(`[Insert Affiliate] Short code ${capitalisedShortCode} validated and stored successfully.`);
|
|
1211
|
+
return true;
|
|
1212
|
+
}
|
|
1213
|
+
else {
|
|
1214
|
+
console.warn(`[Insert Affiliate] Short code ${capitalisedShortCode} does not exist. Not storing.`);
|
|
1215
|
+
return false;
|
|
1216
|
+
}
|
|
1031
1217
|
});
|
|
1032
1218
|
}
|
|
1033
1219
|
function getOrCreateUserAccountToken() {
|
|
@@ -1173,7 +1359,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1173
1359
|
if (!referringLink) {
|
|
1174
1360
|
console.warn('[Insert Affiliate] Referring link is invalid.');
|
|
1175
1361
|
verboseLog('Referring link is empty or invalid, storing as-is');
|
|
1176
|
-
yield storeInsertAffiliateIdentifier({ link: referringLink });
|
|
1362
|
+
yield storeInsertAffiliateIdentifier({ link: referringLink, source: 'referring_link' });
|
|
1177
1363
|
return `${referringLink}-${customerID}`;
|
|
1178
1364
|
}
|
|
1179
1365
|
// Get company code from state or storage
|
|
@@ -1190,7 +1376,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1190
1376
|
if (isShortCode(referringLink)) {
|
|
1191
1377
|
console.log('[Insert Affiliate] Referring link is already a short code.');
|
|
1192
1378
|
verboseLog('Link is already a short code, storing directly');
|
|
1193
|
-
yield storeInsertAffiliateIdentifier({ link: referringLink });
|
|
1379
|
+
yield storeInsertAffiliateIdentifier({ link: referringLink, source: 'referring_link' });
|
|
1194
1380
|
return `${referringLink}-${customerID}`;
|
|
1195
1381
|
}
|
|
1196
1382
|
verboseLog('Link is not a short code, will convert via API');
|
|
@@ -1201,7 +1387,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1201
1387
|
if (!encodedAffiliateLink) {
|
|
1202
1388
|
console.error('[Insert Affiliate] Failed to encode affiliate link.');
|
|
1203
1389
|
verboseLog('Failed to encode link, storing original');
|
|
1204
|
-
yield storeInsertAffiliateIdentifier({ link: referringLink });
|
|
1390
|
+
yield storeInsertAffiliateIdentifier({ link: referringLink, source: 'referring_link' });
|
|
1205
1391
|
return `${referringLink}-${customerID}`;
|
|
1206
1392
|
}
|
|
1207
1393
|
// Create the request URL
|
|
@@ -1220,7 +1406,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1220
1406
|
console.log('[Insert Affiliate] Short link received:', shortLink);
|
|
1221
1407
|
verboseLog(`Successfully converted to short link: ${shortLink}`);
|
|
1222
1408
|
verboseLog('Storing short link to AsyncStorage...');
|
|
1223
|
-
yield storeInsertAffiliateIdentifier({ link: shortLink });
|
|
1409
|
+
yield storeInsertAffiliateIdentifier({ link: shortLink, source: 'referring_link' });
|
|
1224
1410
|
verboseLog('Short link stored successfully');
|
|
1225
1411
|
return `${shortLink}-${customerID}`;
|
|
1226
1412
|
}
|
|
@@ -1228,7 +1414,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1228
1414
|
console.warn('[Insert Affiliate] Unexpected response format.');
|
|
1229
1415
|
verboseLog(`Unexpected API response. Status: ${response.status}, Data: ${JSON.stringify(response.data)}`);
|
|
1230
1416
|
verboseLog('Storing original link as fallback');
|
|
1231
|
-
yield storeInsertAffiliateIdentifier({ link: referringLink });
|
|
1417
|
+
yield storeInsertAffiliateIdentifier({ link: referringLink, source: 'referring_link' });
|
|
1232
1418
|
return `${referringLink}-${customerID}`;
|
|
1233
1419
|
}
|
|
1234
1420
|
}
|
|
@@ -1240,8 +1426,8 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1240
1426
|
}
|
|
1241
1427
|
;
|
|
1242
1428
|
function storeInsertAffiliateIdentifier(_a) {
|
|
1243
|
-
return __awaiter(this, arguments, void 0, function* ({ link }) {
|
|
1244
|
-
console.log(`[Insert Affiliate] Storing affiliate identifier: ${link}`);
|
|
1429
|
+
return __awaiter(this, arguments, void 0, function* ({ link, source }) {
|
|
1430
|
+
console.log(`[Insert Affiliate] Storing affiliate identifier: ${link} (source: ${source})`);
|
|
1245
1431
|
// Check if we're trying to store the same link (prevent duplicate storage)
|
|
1246
1432
|
const existingLink = yield getValueFromAsync(ASYNC_KEYS.REFERRER_LINK);
|
|
1247
1433
|
if (existingLink === link) {
|
|
@@ -1266,6 +1452,11 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1266
1452
|
verboseLog(`Triggering callback with identifier: ${currentIdentifier}`);
|
|
1267
1453
|
insertAffiliateIdentifierChangeCallbackRef.current(currentIdentifier);
|
|
1268
1454
|
}
|
|
1455
|
+
// Report this new affiliate association to the backend (fire and forget)
|
|
1456
|
+
const fullIdentifier = yield returnInsertAffiliateIdentifier();
|
|
1457
|
+
if (fullIdentifier) {
|
|
1458
|
+
reportAffiliateAssociationIfNeeded(fullIdentifier, source);
|
|
1459
|
+
}
|
|
1269
1460
|
});
|
|
1270
1461
|
}
|
|
1271
1462
|
const validatePurchaseWithIapticAPI = (jsonIapPurchase, iapticAppId, iapticAppName, iapticPublicKey) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -1529,6 +1720,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1529
1720
|
userId,
|
|
1530
1721
|
OfferCode,
|
|
1531
1722
|
setShortCode,
|
|
1723
|
+
getAffiliateDetails,
|
|
1532
1724
|
returnInsertAffiliateIdentifier,
|
|
1533
1725
|
isAffiliateAttributionValid,
|
|
1534
1726
|
getAffiliateStoredDate,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import DeepLinkIapProvider from "./DeepLinkIapProvider";
|
|
2
2
|
import useDeepLinkIapProvider from "./useDeepLinkIapProvider";
|
|
3
3
|
export { DeepLinkIapProvider, useDeepLinkIapProvider };
|
|
4
|
-
export type { InsertAffiliateIdentifierChangeCallback } from "./DeepLinkIapProvider";
|
|
4
|
+
export type { InsertAffiliateIdentifierChangeCallback, AffiliateDetails } from "./DeepLinkIapProvider";
|
|
@@ -10,7 +10,8 @@ declare const useDeepLinkIapProvider: () => {
|
|
|
10
10
|
isAffiliateAttributionValid: () => Promise<boolean>;
|
|
11
11
|
getAffiliateStoredDate: () => Promise<Date | null>;
|
|
12
12
|
trackEvent: (eventName: string) => Promise<void>;
|
|
13
|
-
setShortCode: (shortCode: string) => Promise<
|
|
13
|
+
setShortCode: (shortCode: string) => Promise<boolean>;
|
|
14
|
+
getAffiliateDetails: (affiliateCode: string) => Promise<import("./DeepLinkIapProvider").AffiliateDetails>;
|
|
14
15
|
setInsertAffiliateIdentifier: (referringLink: string) => Promise<void | string>;
|
|
15
16
|
setInsertAffiliateIdentifierChangeCallback: (callback: import("./DeepLinkIapProvider").InsertAffiliateIdentifierChangeCallback | null) => void;
|
|
16
17
|
handleInsertLinks: (url: string) => Promise<boolean>;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const react_1 = require("react");
|
|
4
4
|
const DeepLinkIapProvider_1 = require("./DeepLinkIapProvider");
|
|
5
5
|
const useDeepLinkIapProvider = () => {
|
|
6
|
-
const { referrerLink, userId, validatePurchaseWithIapticAPI, storeExpectedStoreTransaction, returnUserAccountTokenAndStoreExpectedTransaction, returnInsertAffiliateIdentifier, isAffiliateAttributionValid, getAffiliateStoredDate, trackEvent, setShortCode, setInsertAffiliateIdentifier, setInsertAffiliateIdentifierChangeCallback, handleInsertLinks, initialize, isInitialized, OfferCode, } = (0, react_1.useContext)(DeepLinkIapProvider_1.DeepLinkIapContext);
|
|
6
|
+
const { referrerLink, userId, validatePurchaseWithIapticAPI, storeExpectedStoreTransaction, returnUserAccountTokenAndStoreExpectedTransaction, returnInsertAffiliateIdentifier, isAffiliateAttributionValid, getAffiliateStoredDate, trackEvent, setShortCode, getAffiliateDetails, setInsertAffiliateIdentifier, setInsertAffiliateIdentifierChangeCallback, handleInsertLinks, initialize, isInitialized, OfferCode, } = (0, react_1.useContext)(DeepLinkIapProvider_1.DeepLinkIapContext);
|
|
7
7
|
return {
|
|
8
8
|
referrerLink,
|
|
9
9
|
userId,
|
|
@@ -15,6 +15,7 @@ const useDeepLinkIapProvider = () => {
|
|
|
15
15
|
getAffiliateStoredDate,
|
|
16
16
|
trackEvent,
|
|
17
17
|
setShortCode,
|
|
18
|
+
getAffiliateDetails,
|
|
18
19
|
setInsertAffiliateIdentifier,
|
|
19
20
|
setInsertAffiliateIdentifierChangeCallback,
|
|
20
21
|
handleInsertLinks,
|