insert-affiliate-react-native-sdk 1.14.0 → 1.15.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.
@@ -54,6 +54,7 @@ type T_DEEPLINK_IAP_CONTEXT = {
54
54
  setInsertAffiliateIdentifierChangeCallback: (callback: InsertAffiliateIdentifierChangeCallback | null) => void;
55
55
  handleInsertLinks: (url: string) => Promise<boolean>;
56
56
  initialize: (code: string | null, verboseLogging?: boolean, insertLinksEnabled?: boolean, insertLinksClipboardEnabled?: boolean, affiliateAttributionActiveTime?: number, preventAffiliateTransfer?: boolean) => Promise<void>;
57
+ setLogger: (logger: InsertAffiliateLogger) => void;
57
58
  isInitialized: boolean;
58
59
  };
59
60
 
@@ -95,6 +96,21 @@ type AffiliateAssociationSource =
95
96
  | 'short_code_manual' // Developer called setShortCode()
96
97
  | 'referring_link'; // Developer called setInsertAffiliateIdentifier()
97
98
 
99
+ // Logger interface for custom logging
100
+ export type InsertAffiliateLogger = {
101
+ debug: (message: string, ...args: any[]) => void;
102
+ info: (message: string, ...args: any[]) => void;
103
+ warn: (message: string, ...args: any[]) => void;
104
+ error: (message: string, ...args: any[]) => void;
105
+ };
106
+
107
+ const DEFAULT_LOGGER: InsertAffiliateLogger = {
108
+ debug: (message, ...args) => console.debug(`[Insert Affiliate] ${message}`, ...args),
109
+ info: (message, ...args) => console.log(`[Insert Affiliate] ${message}`, ...args),
110
+ warn: (message, ...args) => console.warn(`[Insert Affiliate] ${message}`, ...args),
111
+ error: (message, ...args) => console.error(`[Insert Affiliate] ${message}`, ...args),
112
+ };
113
+
98
114
  // STARTING CONTEXT IMPLEMENTATION
99
115
  export const DeepLinkIapContext = createContext<T_DEEPLINK_IAP_CONTEXT>({
100
116
  referrerLink: '',
@@ -119,6 +135,7 @@ export const DeepLinkIapContext = createContext<T_DEEPLINK_IAP_CONTEXT>({
119
135
  setInsertAffiliateIdentifierChangeCallback: (callback: InsertAffiliateIdentifierChangeCallback | null) => {},
120
136
  handleInsertLinks: async (url: string) => false,
121
137
  initialize: async (code: string | null, verboseLogging?: boolean, insertLinksEnabled?: boolean, insertLinksClipboardEnabled?: boolean, affiliateAttributionActiveTime?: number, preventAffiliateTransfer?: boolean) => {},
138
+ setLogger: (logger: InsertAffiliateLogger) => {},
122
139
  isInitialized: false,
123
140
  });
124
141
 
@@ -138,6 +155,9 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
138
155
  const insertAffiliateIdentifierChangeCallbackRef = useRef<InsertAffiliateIdentifierChangeCallback | null>(null);
139
156
  const isInitializingRef = useRef<boolean>(false);
140
157
 
158
+ // Logger ref - defaults to console-based logging, can be swapped via setLogger()
159
+ const loggerRef = useRef<InsertAffiliateLogger>(DEFAULT_LOGGER);
160
+
141
161
  // Refs for values that need to be current inside callbacks (to avoid stale closures)
142
162
  const companyCodeRef = useRef<string | null>(null);
143
163
  const verboseLoggingRef = useRef<boolean>(false);
@@ -177,9 +197,9 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
177
197
  preventAffiliateTransferRef.current = preventAffiliateTransferParam;
178
198
 
179
199
  if (verboseLoggingParam) {
180
- console.log('[Insert Affiliate] [VERBOSE] Starting SDK initialization...');
181
- console.log('[Insert Affiliate] [VERBOSE] Company code provided:', companyCodeParam ? 'Yes' : 'No');
182
- console.log('[Insert Affiliate] [VERBOSE] Verbose logging enabled');
200
+ loggerRef.current.debug('[VERBOSE] Starting SDK initialization...');
201
+ loggerRef.current.debug('[VERBOSE] Company code provided:', companyCodeParam ? 'Yes' : 'No');
202
+ loggerRef.current.debug('[VERBOSE] Verbose logging enabled');
183
203
  }
184
204
 
185
205
  if (companyCodeParam && companyCodeParam.trim() !== '') {
@@ -187,23 +207,19 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
187
207
  companyCodeRef.current = companyCodeParam;
188
208
  await saveValueInAsync(ASYNC_KEYS.COMPANY_CODE, companyCodeParam);
189
209
  setIsInitialized(true);
190
- console.log(
191
- `[Insert Affiliate] SDK initialized with company code: ${companyCodeParam}`
192
- );
210
+ loggerRef.current.info(`SDK initialized with company code: ${companyCodeParam}`);
193
211
  if (verboseLoggingParam) {
194
- console.log('[Insert Affiliate] [VERBOSE] Company code saved to AsyncStorage');
195
- console.log('[Insert Affiliate] [VERBOSE] SDK marked as initialized');
212
+ loggerRef.current.debug('[VERBOSE] Company code saved to AsyncStorage');
213
+ loggerRef.current.debug('[VERBOSE] SDK marked as initialized');
196
214
  }
197
215
 
198
216
  // Report SDK initialization for onboarding verification (fire and forget)
199
217
  reportSdkInitIfNeeded(companyCodeParam, verboseLoggingParam);
200
218
  } else {
201
- console.warn(
202
- '[Insert Affiliate] SDK initialized without a company code.'
203
- );
219
+ loggerRef.current.warn('SDK initialized without a company code.');
204
220
  setIsInitialized(true);
205
221
  if (verboseLoggingParam) {
206
- console.log('[Insert Affiliate] [VERBOSE] No company code provided, SDK initialized in limited mode');
222
+ loggerRef.current.debug('[VERBOSE] No company code provided, SDK initialized in limited mode');
207
223
  }
208
224
  }
209
225
 
@@ -302,7 +318,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
302
318
  }
303
319
  }
304
320
  } catch (error) {
305
- console.error('[Insert Affiliate] Error getting initial URL:', error);
321
+ loggerRef.current.error('Error getting initial URL:', error);
306
322
  }
307
323
  };
308
324
 
@@ -317,7 +333,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
317
333
  verboseLog('URL was not handled by Insert Affiliate SDK');
318
334
  }
319
335
  } catch (error) {
320
- console.error('[Insert Affiliate] Error handling URL change:', error);
336
+ loggerRef.current.error('Error handling URL change:', error);
321
337
  }
322
338
  };
323
339
 
@@ -398,7 +414,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
398
414
  const reset = (): void => {
399
415
  setCompanyCode(null);
400
416
  setIsInitialized(false);
401
- console.log('[Insert Affiliate] SDK has been reset.');
417
+ loggerRef.current.info('SDK has been reset.');
402
418
  };
403
419
 
404
420
  // MARK: Deep Link Handling
@@ -611,16 +627,16 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
611
627
  // Handles Insert Links deep linking - equivalent to iOS handleInsertLinks
612
628
  const handleInsertLinksImpl = async (url: string): Promise<boolean> => {
613
629
  try {
614
- console.log(`[Insert Affiliate] Attempting to handle URL: ${url}`);
630
+ loggerRef.current.info(`Attempting to handle URL: ${url}`);
615
631
 
616
632
  if (!url || typeof url !== 'string') {
617
- console.log('[Insert Affiliate] Invalid URL provided to handleInsertLinks');
633
+ loggerRef.current.info('Invalid URL provided to handleInsertLinks');
618
634
  return false;
619
635
  }
620
636
 
621
637
  // Check if deep links are enabled synchronously
622
638
  if (!insertLinksEnabled) {
623
- console.log('[Insert Affiliate] Deep links are disabled, not handling URL');
639
+ loggerRef.current.info('Deep links are disabled, not handling URL');
624
640
  return false;
625
641
  }
626
642
 
@@ -638,7 +654,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
638
654
 
639
655
  return false;
640
656
  } catch (error) {
641
- console.error('[Insert Affiliate] Error handling Insert Link:', error);
657
+ loggerRef.current.error('Error handling Insert Link:', error);
642
658
  verboseLog(`Error in handleInsertLinks: ${error}`);
643
659
  return false;
644
660
  }
@@ -658,16 +674,16 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
658
674
 
659
675
  const shortCode = parseShortCodeFromURLString(url);
660
676
  if (!shortCode) {
661
- console.log(`[Insert Affiliate] Failed to parse short code from deep link: ${url}`);
677
+ loggerRef.current.info(`Failed to parse short code from deep link: ${url}`);
662
678
  return false;
663
679
  }
664
680
 
665
- console.log(`[Insert Affiliate] Custom URL scheme detected - Company: ${companyCode}, Short code: ${shortCode}`);
681
+ loggerRef.current.info(`Custom URL scheme detected - Company: ${companyCode}, Short code: ${shortCode}`);
666
682
 
667
683
  // Validate company code matches initialized one
668
684
  const activeCompanyCode = await getActiveCompanyCode();
669
685
  if (activeCompanyCode && companyCode.toLowerCase() !== activeCompanyCode.toLowerCase()) {
670
- console.log(`[Insert Affiliate] Warning: URL company code (${companyCode}) doesn't match initialized company code (${activeCompanyCode})`);
686
+ loggerRef.current.info(`Warning: URL company code (${companyCode}) doesn't match initialized company code (${activeCompanyCode})`);
671
687
  }
672
688
 
673
689
  // If URL scheme is used, we can straight away store the short code as the referring link
@@ -677,7 +693,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
677
693
 
678
694
  return true;
679
695
  } catch (error) {
680
- console.error('[Insert Affiliate] Error handling custom URL scheme:', error);
696
+ loggerRef.current.error('Error handling custom URL scheme:', error);
681
697
  return false;
682
698
  }
683
699
  };
@@ -689,19 +705,19 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
689
705
 
690
706
  // // Expected format: /V1/companycode/shortcode
691
707
  // if (pathComponents.length < 3 || pathComponents[0] !== 'V1') {
692
- // console.log(`[Insert Affiliate] Invalid universal link format: ${url.href}`);
708
+ // loggerRef.current.info(`Invalid universal link format: ${url.href}`);
693
709
  // return false;
694
710
  // }
695
711
 
696
712
  // const companyCode = pathComponents[1];
697
713
  // const shortCode = pathComponents[2];
698
714
 
699
- // console.log(`[Insert Affiliate] Universal link detected - Company: ${companyCode}, Short code: ${shortCode}`);
715
+ // loggerRef.current.info(`Universal link detected - Company: ${companyCode}, Short code: ${shortCode}`);
700
716
 
701
717
  // // Validate company code matches initialized one
702
718
  // const activeCompanyCode = await getActiveCompanyCode();
703
719
  // if (activeCompanyCode && companyCode.toLowerCase() !== activeCompanyCode.toLowerCase()) {
704
- // console.log(`[Insert Affiliate] Warning: URL company code (${companyCode}) doesn't match initialized company code (${activeCompanyCode})`);
720
+ // loggerRef.current.info(`Warning: URL company code (${companyCode}) doesn't match initialized company code (${activeCompanyCode})`);
705
721
  // }
706
722
 
707
723
  // // Process the affiliate attribution
@@ -710,7 +726,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
710
726
 
711
727
  // return true;
712
728
  // } catch (error) {
713
- // console.error('[Insert Affiliate] Error handling universal link:', error);
729
+ // loggerRef.current.error('Error handling universal link:', error);
714
730
  // return false;
715
731
  // }
716
732
  // };
@@ -753,7 +769,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
753
769
  // First try to extract from query parameter (new format: scheme://insert-affiliate?code=SHORTCODE)
754
770
  const queryCode = parseShortCodeFromQuery(url);
755
771
  if (queryCode) {
756
- console.log(`[Insert Affiliate] Found short code in query parameter: ${queryCode}`);
772
+ loggerRef.current.info(`Found short code in query parameter: ${queryCode}`);
757
773
  return queryCode;
758
774
  }
759
775
 
@@ -767,7 +783,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
767
783
  if (shortCode === 'insert-affiliate' || shortCode.startsWith('insert-affiliate?')) {
768
784
  return null;
769
785
  }
770
- console.log(`[Insert Affiliate] Found short code in URL path (legacy format): ${shortCode}`);
786
+ loggerRef.current.info(`Found short code in URL path (legacy format): ${shortCode}`);
771
787
  return shortCode;
772
788
  }
773
789
  return null;
@@ -815,7 +831,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
815
831
  // Helper function for verbose logging (uses ref to avoid stale closures)
816
832
  const verboseLog = (message: string) => {
817
833
  if (verboseLoggingRef.current) {
818
- console.log(`[Insert Affiliate] [VERBOSE] ${message}`);
834
+ loggerRef.current.debug(`[VERBOSE] ${message}`);
819
835
  }
820
836
  };
821
837
 
@@ -823,13 +839,13 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
823
839
  const errorLog = (message: string, type?: 'error' | 'warn' | 'log') => {
824
840
  switch (type) {
825
841
  case 'error':
826
- console.error(`ENCOUNTER ERROR ~ ${message}`);
842
+ loggerRef.current.error(`ENCOUNTER ERROR ~ ${message}`);
827
843
  break;
828
844
  case 'warn':
829
- console.warn(`ENCOUNTER WARNING ~ ${message}`);
845
+ loggerRef.current.warn(`ENCOUNTER WARNING ~ ${message}`);
830
846
  break;
831
847
  default:
832
- console.log(`LOGGING ~ ${message}`);
848
+ loggerRef.current.info(`LOGGING ~ ${message}`);
833
849
  break;
834
850
  }
835
851
  };
@@ -897,7 +913,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
897
913
  }
898
914
 
899
915
  if (verboseLogging) {
900
- console.log('[Insert Affiliate] Reporting SDK initialization for onboarding verification...');
916
+ loggerRef.current.info('Reporting SDK initialization for onboarding verification...');
901
917
  }
902
918
 
903
919
  const response = await fetch('https://api.insertaffiliate.com/V1/onboarding/sdk-init', {
@@ -911,15 +927,15 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
911
927
  if (response.ok) {
912
928
  await AsyncStorage.setItem(ASYNC_KEYS.SDK_INIT_REPORTED, 'true');
913
929
  if (verboseLogging) {
914
- console.log('[Insert Affiliate] SDK initialization reported successfully');
930
+ loggerRef.current.info('SDK initialization reported successfully');
915
931
  }
916
932
  } else if (verboseLogging) {
917
- console.log(`[Insert Affiliate] SDK initialization report failed with status: ${response.status}`);
933
+ loggerRef.current.info(`SDK initialization report failed with status: ${response.status}`);
918
934
  }
919
935
  } catch (error) {
920
936
  // Silently fail - this is non-critical telemetry
921
937
  if (verboseLogging) {
922
- console.log(`[Insert Affiliate] SDK initialization report error: ${error}`);
938
+ loggerRef.current.info(`SDK initialization report error: ${error}`);
923
939
  }
924
940
  }
925
941
  };
@@ -1157,7 +1173,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1157
1173
  }
1158
1174
 
1159
1175
  if (verboseLogging) {
1160
- console.log('[Insert Affiliate] system info:', systemInfo);
1176
+ loggerRef.current.info('system info:', systemInfo);
1161
1177
  }
1162
1178
 
1163
1179
  return systemInfo;
@@ -1318,7 +1334,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1318
1334
  // Sends enhanced system info to the backend API for deep link event tracking
1319
1335
  const sendSystemInfoToBackend = async (systemInfo: {[key: string]: any}): Promise<void> => {
1320
1336
  if (verboseLogging) {
1321
- console.log('[Insert Affiliate] Sending system info to backend...');
1337
+ loggerRef.current.info('Sending system info to backend...');
1322
1338
  }
1323
1339
 
1324
1340
  try {
@@ -1457,13 +1473,13 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1457
1473
  return null;
1458
1474
  } catch (error) {
1459
1475
  verboseLog(`Error getting affiliate details: ${error}`);
1460
- console.error('[Insert Affiliate] Error getting affiliate details:', error);
1476
+ loggerRef.current.error('Error getting affiliate details:', error);
1461
1477
  return null;
1462
1478
  }
1463
1479
  };
1464
1480
 
1465
1481
  const setShortCodeImpl = async (shortCode: string): Promise<boolean> => {
1466
- console.log('[Insert Affiliate] Setting short code.');
1482
+ loggerRef.current.info('Setting short code.');
1467
1483
  await generateThenSetUserID();
1468
1484
 
1469
1485
  // Validate it is a short code
@@ -1476,10 +1492,10 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1476
1492
  if (exists) {
1477
1493
  // If affiliate exists, set the Insert Affiliate Identifier
1478
1494
  await storeInsertAffiliateIdentifier({ link: capitalisedShortCode, source: 'short_code_manual' });
1479
- console.log(`[Insert Affiliate] Short code ${capitalisedShortCode} validated and stored successfully.`);
1495
+ loggerRef.current.info(`Short code ${capitalisedShortCode} validated and stored successfully.`);
1480
1496
  return true;
1481
1497
  } else {
1482
- console.warn(`[Insert Affiliate] Short code ${capitalisedShortCode} does not exist. Not storing.`);
1498
+ loggerRef.current.warn(`Short code ${capitalisedShortCode} does not exist. Not storing.`);
1483
1499
  return false;
1484
1500
  }
1485
1501
  };
@@ -1499,15 +1515,15 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1499
1515
  try {
1500
1516
  const shortCode = await returnInsertAffiliateIdentifierImpl();
1501
1517
  if (!shortCode) {
1502
- console.log('[Insert Affiliate] No affiliate stored - not saving expected transaction.');
1518
+ loggerRef.current.info('No affiliate stored - not saving expected transaction.');
1503
1519
  return null;
1504
1520
  }
1505
1521
 
1506
1522
  const userAccountToken = await getOrCreateUserAccountToken();
1507
- console.log('[Insert Affiliate] User account token:', userAccountToken);
1523
+ loggerRef.current.info('User account token:', userAccountToken);
1508
1524
 
1509
1525
  if (!userAccountToken) {
1510
- console.error('[Insert Affiliate] Failed to generate user account token.');
1526
+ loggerRef.current.error('Failed to generate user account token.');
1511
1527
  return null;
1512
1528
  } else {
1513
1529
  await storeExpectedStoreTransactionImpl(userAccountToken);
@@ -1519,13 +1535,13 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1519
1535
  (error instanceof Error && error.message.includes('E_IAP_NOT_AVAILABLE'))) {
1520
1536
 
1521
1537
  if (isDevelopmentEnvironment) {
1522
- console.warn('[Insert Affiliate] IAP not available in development environment. Cannot store expected transaction.');
1538
+ loggerRef.current.warn('IAP not available in development environment. Cannot store expected transaction.');
1523
1539
  verboseLog('E_IAP_NOT_AVAILABLE error in returnUserAccountTokenAndStoreExpectedTransaction - gracefully handling in development');
1524
1540
  }
1525
1541
  return null; // Return null but don't crash
1526
1542
  }
1527
1543
 
1528
- console.error('[Insert Affiliate] Error in returnUserAccountTokenAndStoreExpectedTransaction:', error);
1544
+ loggerRef.current.error('Error in returnUserAccountTokenAndStoreExpectedTransaction:', error);
1529
1545
  return null;
1530
1546
  };
1531
1547
  };
@@ -1661,19 +1677,17 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1661
1677
  const setInsertAffiliateIdentifierImpl = async (
1662
1678
  referringLink: string
1663
1679
  ): Promise<void | string> => {
1664
- console.log('[Insert Affiliate] Setting affiliate identifier.');
1680
+ loggerRef.current.info('Setting affiliate identifier.');
1665
1681
  verboseLog(`Input referringLink: ${referringLink}`);
1666
1682
 
1667
1683
  try {
1668
1684
  verboseLog('Generating or retrieving user ID...');
1669
1685
  const customerID = await generateThenSetUserID();
1670
- console.log(
1671
- '[Insert Affiliate] Completed generateThenSetUserID within setInsertAffiliateIdentifier.'
1672
- );
1686
+ loggerRef.current.info('Completed generateThenSetUserID within setInsertAffiliateIdentifier.');
1673
1687
  verboseLog(`Customer ID: ${customerID}`);
1674
1688
 
1675
1689
  if (!referringLink) {
1676
- console.warn('[Insert Affiliate] Referring link is invalid.');
1690
+ loggerRef.current.warn('Referring link is invalid.');
1677
1691
  verboseLog('Referring link is empty or invalid, storing as-is');
1678
1692
  await storeInsertAffiliateIdentifier({ link: referringLink, source: 'referring_link' });
1679
1693
  return `${referringLink}-${customerID}`;
@@ -1685,9 +1699,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1685
1699
  verboseLog(`Active company code: ${activeCompanyCode || 'Not found'}`);
1686
1700
 
1687
1701
  if (!activeCompanyCode) {
1688
- console.error(
1689
- '[Insert Affiliate] Company code is not set. Please initialize the SDK with a valid company code.'
1690
- );
1702
+ loggerRef.current.error('Company code is not set. Please initialize the SDK with a valid company code.');
1691
1703
  verboseLog('Company code missing, cannot proceed with API call');
1692
1704
  return;
1693
1705
  }
@@ -1695,9 +1707,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1695
1707
  // Check if referring link is already a short code, if so save it and stop here.
1696
1708
  verboseLog('Checking if referring link is already a short code...');
1697
1709
  if (isShortCode(referringLink)) {
1698
- console.log(
1699
- '[Insert Affiliate] Referring link is already a short code.'
1700
- );
1710
+ loggerRef.current.info('Referring link is already a short code.');
1701
1711
  verboseLog('Link is already a short code, storing directly');
1702
1712
  await storeInsertAffiliateIdentifier({ link: referringLink, source: 'referring_link' });
1703
1713
  return `${referringLink}-${customerID}`;
@@ -1710,7 +1720,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1710
1720
  verboseLog('Encoding referring link for API call...');
1711
1721
  const encodedAffiliateLink = encodeURIComponent(referringLink);
1712
1722
  if (!encodedAffiliateLink) {
1713
- console.error('[Insert Affiliate] Failed to encode affiliate link.');
1723
+ loggerRef.current.error('Failed to encode affiliate link.');
1714
1724
  verboseLog('Failed to encode link, storing original');
1715
1725
  await storeInsertAffiliateIdentifier({ link: referringLink, source: 'referring_link' });
1716
1726
  return `${referringLink}-${customerID}`;
@@ -1718,7 +1728,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1718
1728
 
1719
1729
  // Create the request URL
1720
1730
  const urlString = `https://api.insertaffiliate.com/V1/convert-deep-link-to-short-link?companyId=${activeCompanyCode}&deepLinkUrl=${encodedAffiliateLink}`;
1721
- console.log('[Insert Affiliate] urlString .', urlString);
1731
+ loggerRef.current.info('urlString .', urlString);
1722
1732
  verboseLog('Making API request to convert deep link to short code...');
1723
1733
 
1724
1734
  const response = await axios.get(urlString, {
@@ -1732,21 +1742,21 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1732
1742
  // Call to the backend for the short code and save the resolse in valid
1733
1743
  if (response.status === 200 && response.data.shortLink) {
1734
1744
  const shortLink = response.data.shortLink;
1735
- console.log('[Insert Affiliate] Short link received:', shortLink);
1745
+ loggerRef.current.info('Short link received:', shortLink);
1736
1746
  verboseLog(`Successfully converted to short link: ${shortLink}`);
1737
1747
  verboseLog('Storing short link to AsyncStorage...');
1738
1748
  await storeInsertAffiliateIdentifier({ link: shortLink, source: 'referring_link' });
1739
1749
  verboseLog('Short link stored successfully');
1740
1750
  return `${shortLink}-${customerID}`;
1741
1751
  } else {
1742
- console.warn('[Insert Affiliate] Unexpected response format.');
1752
+ loggerRef.current.warn('Unexpected response format.');
1743
1753
  verboseLog(`Unexpected API response. Status: ${response.status}, Data: ${JSON.stringify(response.data)}`);
1744
1754
  verboseLog('Storing original link as fallback');
1745
1755
  await storeInsertAffiliateIdentifier({ link: referringLink, source: 'referring_link' });
1746
1756
  return `${referringLink}-${customerID}`;
1747
1757
  }
1748
1758
  } catch (error) {
1749
- console.error('[Insert Affiliate] Error:', error);
1759
+ loggerRef.current.error('Error:', error);
1750
1760
  verboseLog(`Error in setInsertAffiliateIdentifier: ${error}`);
1751
1761
  }
1752
1762
  };
@@ -1811,10 +1821,10 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1811
1821
  (typeof jsonIapPurchase === 'string' && (jsonIapPurchase as string).includes('E_IAP_NOT_AVAILABLE'))) {
1812
1822
 
1813
1823
  if (isDevelopmentEnvironment) {
1814
- console.warn('[Insert Affiliate] IAP not available in development environment. This is expected behavior.');
1824
+ loggerRef.current.warn('IAP not available in development environment. This is expected behavior.');
1815
1825
  verboseLog('E_IAP_NOT_AVAILABLE error detected in development - gracefully handling');
1816
1826
  } else {
1817
- console.error('[Insert Affiliate] IAP not available in production environment. Please check your IAP configuration.');
1827
+ loggerRef.current.error('IAP not available in production environment. Please check your IAP configuration.');
1818
1828
  }
1819
1829
  return false; // Return false but don't crash
1820
1830
  }
@@ -1870,10 +1880,10 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1870
1880
  });
1871
1881
 
1872
1882
  if (response.status === 200) {
1873
- console.log('Validation successful:', response.data);
1883
+ loggerRef.current.info('Validation successful:', response.data);
1874
1884
  return true;
1875
1885
  } else {
1876
- console.error('Validation failed:', response.data);
1886
+ loggerRef.current.error('Validation failed:', response.data);
1877
1887
  return false;
1878
1888
  }
1879
1889
  } catch (error) {
@@ -1882,22 +1892,18 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1882
1892
  (error instanceof Error && error.message.includes('E_IAP_NOT_AVAILABLE'))) {
1883
1893
 
1884
1894
  if (isDevelopmentEnvironment) {
1885
- console.warn('[Insert Affiliate] IAP not available in development environment. SDK will continue without purchase validation.');
1895
+ loggerRef.current.warn('IAP not available in development environment. SDK will continue without purchase validation.');
1886
1896
  verboseLog('E_IAP_NOT_AVAILABLE error caught in validatePurchaseWithIapticAPI - gracefully handling in development');
1887
1897
  } else {
1888
- console.error('[Insert Affiliate] IAP not available in production environment. Please check your IAP configuration.');
1898
+ loggerRef.current.error('IAP not available in production environment. Please check your IAP configuration.');
1889
1899
  }
1890
1900
  return false; // Return false but don't crash
1891
1901
  }
1892
1902
 
1893
1903
  if (error instanceof Error) {
1894
- console.error(`validatePurchaseWithIapticAPI Error: ${error.message}`);
1904
+ loggerRef.current.error(`validatePurchaseWithIapticAPI Error: ${error.message}`);
1895
1905
  } else {
1896
- console.error(
1897
- `validatePurchaseWithIapticAPI Unknown Error: ${JSON.stringify(
1898
- error
1899
- )}`
1900
- );
1906
+ loggerRef.current.error(`validatePurchaseWithIapticAPI Unknown Error: ${JSON.stringify(error)}`);
1901
1907
  }
1902
1908
 
1903
1909
  return false;
@@ -1909,14 +1915,14 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1909
1915
 
1910
1916
  const activeCompanyCode = await getActiveCompanyCode();
1911
1917
  if (!activeCompanyCode) {
1912
- console.error("[Insert Affiliate] Company code is not set. Please initialize the SDK with a valid company code.");
1918
+ loggerRef.current.error("Company code is not set. Please initialize the SDK with a valid company code.");
1913
1919
  verboseLog("Cannot store transaction: no company code available");
1914
1920
  return;
1915
1921
  }
1916
1922
 
1917
1923
  const shortCode = await returnInsertAffiliateIdentifierImpl();
1918
1924
  if (!shortCode) {
1919
- console.error("[Insert Affiliate] No affiliate identifier found. Please set one before tracking events.");
1925
+ loggerRef.current.error("No affiliate identifier found. Please set one before tracking events.");
1920
1926
  verboseLog("Cannot store transaction: no affiliate identifier available");
1921
1927
  return;
1922
1928
  }
@@ -1931,7 +1937,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1931
1937
  storedDate: new Date().toISOString(), // ISO8601 format
1932
1938
  };
1933
1939
 
1934
- console.log("[Insert Affiliate] Storing expected transaction: ", payload);
1940
+ loggerRef.current.info("Storing expected transaction: ", payload);
1935
1941
  verboseLog("Making API call to store expected transaction...");
1936
1942
 
1937
1943
  try {
@@ -1946,15 +1952,15 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1946
1952
  verboseLog(`API response status: ${response.status}`);
1947
1953
 
1948
1954
  if (response.ok) {
1949
- console.info("[Insert Affiliate] Expected transaction stored successfully.");
1955
+ loggerRef.current.info("Expected transaction stored successfully.");
1950
1956
  verboseLog("Expected transaction stored successfully on server");
1951
1957
  } else {
1952
1958
  const errorText = await response.text();
1953
- console.error(`[Insert Affiliate] Failed to store expected transaction with status code: ${response.status}. Response: ${errorText}`);
1959
+ loggerRef.current.error(`Failed to store expected transaction with status code: ${response.status}. Response: ${errorText}`);
1954
1960
  verboseLog(`API error response: ${errorText}`);
1955
1961
  }
1956
1962
  } catch (error) {
1957
- console.error(`[Insert Affiliate] Error storing expected transaction: ${error}`);
1963
+ loggerRef.current.error(`Error storing expected transaction: ${error}`);
1958
1964
  verboseLog(`Network error storing transaction: ${error}`);
1959
1965
  }
1960
1966
  };
@@ -1966,17 +1972,15 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
1966
1972
 
1967
1973
  const activeCompanyCode = await getActiveCompanyCode();
1968
1974
  if (!activeCompanyCode) {
1969
- console.error("[Insert Affiliate] Company code is not set. Please initialize the SDK with a valid company code.");
1975
+ loggerRef.current.error("Company code is not set. Please initialize the SDK with a valid company code.");
1970
1976
  verboseLog("Cannot track event: no company code available");
1971
1977
  return Promise.resolve();
1972
1978
  }
1973
1979
 
1974
- console.log("track event called with - companyCode: ", activeCompanyCode);
1980
+ loggerRef.current.info("track event called with - companyCode: ", activeCompanyCode);
1975
1981
 
1976
1982
  if (!referrerLink || !userId) {
1977
- console.warn(
1978
- '[Insert Affiliate] No affiliate identifier found. Please set one before tracking events.'
1979
- );
1983
+ loggerRef.current.warn('No affiliate identifier found. Please set one before tracking events.');
1980
1984
  verboseLog("Cannot track event: no affiliate identifier available");
1981
1985
  return Promise.resolve();
1982
1986
  }
@@ -2005,16 +2009,14 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
2005
2009
  verboseLog(`Track event API response status: ${response.status}`);
2006
2010
 
2007
2011
  if (response.status === 200) {
2008
- console.log('[Insert Affiliate] Event tracked successfully');
2012
+ loggerRef.current.info('Event tracked successfully');
2009
2013
  verboseLog("Event tracked successfully on server");
2010
2014
  } else {
2011
- console.error(
2012
- `[Insert Affiliate] Failed to track event with status code: ${response.status}`
2013
- );
2015
+ loggerRef.current.error(`Failed to track event with status code: ${response.status}`);
2014
2016
  verboseLog(`Track event API error: status ${response.status}, response: ${JSON.stringify(response.data)}`);
2015
2017
  }
2016
2018
  } catch (error) {
2017
- console.error('[Insert Affiliate] Error tracking event:', error);
2019
+ loggerRef.current.error('Error tracking event:', error);
2018
2020
  verboseLog(`Network error tracking event: ${error}`);
2019
2021
  return Promise.reject(error);
2020
2022
  }
@@ -2054,7 +2056,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
2054
2056
  offerCode.includes("errorAffiliateoffercodenotfoundinanycompanyAffiliatelinkwas") ||
2055
2057
  offerCode.includes("Routenotfound")
2056
2058
  )) {
2057
- console.warn(`[Insert Affiliate] Offer code not found or invalid: ${offerCode}`);
2059
+ loggerRef.current.warn(`Offer code not found or invalid: ${offerCode}`);
2058
2060
  verboseLog(`Offer code not found or invalid: ${offerCode}`);
2059
2061
  return null;
2060
2062
  }
@@ -2063,12 +2065,12 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
2063
2065
  verboseLog(`Successfully fetched and cleaned offer code: ${cleanedOfferCode}`);
2064
2066
  return cleanedOfferCode;
2065
2067
  } else {
2066
- console.error(`[Insert Affiliate] Failed to fetch offer code. Status code: ${response.status}, Response: ${JSON.stringify(response.data)}`);
2068
+ loggerRef.current.error(`Failed to fetch offer code. Status code: ${response.status}, Response: ${JSON.stringify(response.data)}`);
2067
2069
  verboseLog(`Failed to fetch offer code. Status code: ${response.status}, Response: ${JSON.stringify(response.data)}`);
2068
2070
  return null;
2069
2071
  }
2070
2072
  } catch (error) {
2071
- console.error('[Insert Affiliate] Error fetching offer code:', error);
2073
+ loggerRef.current.error('Error fetching offer code:', error);
2072
2074
  verboseLog(`Error fetching offer code: ${error}`);
2073
2075
  return null;
2074
2076
  }
@@ -2085,7 +2087,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
2085
2087
  await saveValueInAsync(ASYNC_KEYS.OFFER_CODE, offerCode);
2086
2088
  setOfferCode(offerCode);
2087
2089
  verboseLog(`Successfully stored offer code: ${offerCode}`);
2088
- console.log('[Insert Affiliate] Offer code retrieved and stored successfully');
2090
+ loggerRef.current.info('Offer code retrieved and stored successfully');
2089
2091
  return offerCode;
2090
2092
  } else {
2091
2093
  verboseLog('No valid offer code found to store');
@@ -2095,7 +2097,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
2095
2097
  return null;
2096
2098
  }
2097
2099
  } catch (error) {
2098
- console.error('[Insert Affiliate] Error retrieving and storing offer code:', error);
2100
+ loggerRef.current.error('Error retrieving and storing offer code:', error);
2099
2101
  verboseLog(`Error in retrieveAndStoreOfferCode: ${error}`);
2100
2102
  return null;
2101
2103
  }
@@ -2216,6 +2218,10 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
2216
2218
  return handleInsertLinksImplRef.current(url);
2217
2219
  }, []);
2218
2220
 
2221
+ const setLogger = useCallback((logger: InsertAffiliateLogger) => {
2222
+ loggerRef.current = logger;
2223
+ }, []);
2224
+
2219
2225
  return (
2220
2226
  <DeepLinkIapContext.Provider
2221
2227
  value={{
@@ -2236,6 +2242,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
2236
2242
  setInsertAffiliateIdentifierChangeCallback: setInsertAffiliateIdentifierChangeCallbackHandler,
2237
2243
  handleInsertLinks,
2238
2244
  initialize,
2245
+ setLogger,
2239
2246
  isInitialized,
2240
2247
  }}
2241
2248
  >
package/src/index.ts CHANGED
@@ -4,4 +4,4 @@ import useDeepLinkIapProvider from "./useDeepLinkIapProvider";
4
4
  export { DeepLinkIapProvider, useDeepLinkIapProvider };
5
5
 
6
6
  // Export types
7
- export type { InsertAffiliateIdentifierChangeCallback, AffiliateDetails } from "./DeepLinkIapProvider";
7
+ export type { InsertAffiliateIdentifierChangeCallback, AffiliateDetails, InsertAffiliateLogger } from "./DeepLinkIapProvider";
@@ -19,6 +19,7 @@ const useDeepLinkIapProvider = () => {
19
19
  setInsertAffiliateIdentifierChangeCallback,
20
20
  handleInsertLinks,
21
21
  initialize,
22
+ setLogger,
22
23
  isInitialized,
23
24
  OfferCode,
24
25
  } = useContext(DeepLinkIapContext);
@@ -40,6 +41,7 @@ const useDeepLinkIapProvider = () => {
40
41
  setInsertAffiliateIdentifierChangeCallback,
41
42
  handleInsertLinks,
42
43
  initialize,
44
+ setLogger,
43
45
  isInitialized,
44
46
  OfferCode,
45
47
  };