insert-affiliate-react-native-sdk 1.12.0 → 1.13.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.
@@ -1182,7 +1182,7 @@ const DeepLinkIapProvider = ({ children, }) => {
1182
1182
  const isValidCharacters = /^[a-zA-Z0-9_]+$/.test(referringLink);
1183
1183
  return isValidCharacters && referringLink.length >= 3 && referringLink.length <= 25;
1184
1184
  };
1185
- const checkAffiliateExists = (affiliateCode) => __awaiter(void 0, void 0, void 0, function* () {
1185
+ const checkAffiliateExists = (affiliateCode_1, ...args_1) => __awaiter(void 0, [affiliateCode_1, ...args_1], void 0, function* (affiliateCode, trackUsage = false) {
1186
1186
  try {
1187
1187
  const activeCompanyCode = yield getActiveCompanyCode();
1188
1188
  if (!activeCompanyCode) {
@@ -1194,6 +1194,9 @@ const DeepLinkIapProvider = ({ children, }) => {
1194
1194
  companyId: activeCompanyCode,
1195
1195
  affiliateCode: affiliateCode
1196
1196
  };
1197
+ if (trackUsage) {
1198
+ payload.trackUsage = true;
1199
+ }
1197
1200
  verboseLog(`Checking if affiliate exists: ${affiliateCode}`);
1198
1201
  const response = yield axios_1.default.post(url, payload, {
1199
1202
  headers: {
@@ -1267,7 +1270,7 @@ const DeepLinkIapProvider = ({ children, }) => {
1267
1270
  const capitalisedShortCode = shortCode.toUpperCase();
1268
1271
  isShortCode(capitalisedShortCode);
1269
1272
  // Check if the affiliate exists before storing
1270
- const exists = yield checkAffiliateExists(capitalisedShortCode);
1273
+ const exists = yield checkAffiliateExists(capitalisedShortCode, true);
1271
1274
  if (exists) {
1272
1275
  // If affiliate exists, set the Insert Affiliate Identifier
1273
1276
  yield storeInsertAffiliateIdentifier({ link: capitalisedShortCode, source: 'short_code_manual' });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "insert-affiliate-react-native-sdk",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
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",
package/readme.md CHANGED
@@ -1011,6 +1011,29 @@ const rawIdentifier = await returnInsertAffiliateIdentifier(true);
1011
1011
 
1012
1012
  </details>
1013
1013
 
1014
+ ### Prevent Affiliate Transfer
1015
+
1016
+ By default, clicking a new affiliate link will overwrite any existing attribution. Enable `preventAffiliateTransfer` to lock the first affiliate:
1017
+
1018
+ ```javascript
1019
+ initialize(
1020
+ "YOUR_COMPANY_CODE",
1021
+ false, // verboseLogging
1022
+ false, // insertLinksEnabled
1023
+ false, // insertLinksClipboardEnabled
1024
+ 604800, // affiliateAttributionActiveTime (7 days)
1025
+ true // preventAffiliateTransfer - locks first affiliate
1026
+ );
1027
+ ```
1028
+
1029
+ **How it works:**
1030
+ - When enabled, once a user is attributed to an affiliate, that attribution is locked
1031
+ - New affiliate links will not overwrite the existing attribution
1032
+ - The callback still fires with the existing affiliate data (not the new one)
1033
+ - Useful for preventing "affiliate stealing" where users click competitor links
1034
+
1035
+ Learn more: [Prevent Affiliate Transfer Documentation](https://docs.insertaffiliate.com/prevent-affiliate-transfer)
1036
+
1014
1037
  ---
1015
1038
 
1016
1039
  ## 🔍 Troubleshooting
@@ -1367,7 +1367,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1367
1367
  return isValidCharacters && referringLink.length >= 3 && referringLink.length <= 25;
1368
1368
  };
1369
1369
 
1370
- const checkAffiliateExists = async (affiliateCode: string): Promise<boolean> => {
1370
+ const checkAffiliateExists = async (affiliateCode: string, trackUsage: boolean = false): Promise<boolean> => {
1371
1371
  try {
1372
1372
  const activeCompanyCode = await getActiveCompanyCode();
1373
1373
  if (!activeCompanyCode) {
@@ -1376,11 +1376,15 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1376
1376
  }
1377
1377
 
1378
1378
  const url = 'https://api.insertaffiliate.com/V1/checkAffiliateExists';
1379
- const payload = {
1379
+ const payload: Record<string, any> = {
1380
1380
  companyId: activeCompanyCode,
1381
1381
  affiliateCode: affiliateCode
1382
1382
  };
1383
1383
 
1384
+ if (trackUsage) {
1385
+ payload.trackUsage = true;
1386
+ }
1387
+
1384
1388
  verboseLog(`Checking if affiliate exists: ${affiliateCode}`);
1385
1389
 
1386
1390
  const response = await axios.post(url, payload, {
@@ -1463,7 +1467,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1463
1467
  isShortCode(capitalisedShortCode);
1464
1468
 
1465
1469
  // Check if the affiliate exists before storing
1466
- const exists = await checkAffiliateExists(capitalisedShortCode);
1470
+ const exists = await checkAffiliateExists(capitalisedShortCode, true);
1467
1471
 
1468
1472
  if (exists) {
1469
1473
  // If affiliate exists, set the Insert Affiliate Identifier