cryptique-sdk 1.2.8 → 1.2.10

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/lib/cjs/index.js CHANGED
@@ -42,25 +42,17 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
42
42
  // - Single place to change environment (dev/prod)
43
43
  // ============================================================================
44
44
 
45
+ // Single SDK API base — change manually for local vs production.
46
+ const SDK_API_BASE = "https://sdkapi.cryptique.io";
47
+
45
48
  const CONFIG = {
46
- // API Endpoints - All API URLs in one place
49
+ // API Endpoints all SDK writes go to SDK_API_BASE.
47
50
  API: {
48
- TRACK: "https://backend.cryptique.io/api/sdk/track", // Main session tracking
49
- UTM_EVENTS: "https://backend.cryptique.io/api/utm-events", // UTM campaign tracking
50
- EVENTS: "https://backend.cryptique.io/api/events" // Comprehensive events API (replaces old custom events)
51
+ TRACK: SDK_API_BASE + "/api/sdk/track",
52
+ UTM_EVENTS: SDK_API_BASE + "/api/utm-events",
53
+ EVENTS: SDK_API_BASE + "/api/events"
51
54
  },
52
55
 
53
- // Development API (uncomment for local testing)
54
-
55
- /*API: {
56
- TRACK: "http://localhost:3002/api/sdk/track", // Main session tracking
57
- UTM_EVENTS: "http://localhost:3002/api/utm-events", // UTM campaign tracking
58
- EVENTS: "http://localhost:3002/api/events" // Comprehensive events API
59
- },*/
60
-
61
-
62
-
63
-
64
56
 
65
57
  // SDK Version
66
58
  VERSION: "v0.11.24",
@@ -288,7 +280,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
288
280
 
289
281
  return null;
290
282
  } catch (err) {
291
- console.warn('Failed to load session, clearing corrupted data:', err);
292
283
  // Clean up corrupted data
293
284
  try {
294
285
  sessionStorage.removeItem(CONFIG.STORAGE_KEYS.SESSION);
@@ -316,15 +307,13 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
316
307
  this.updateBackup(session);
317
308
  }
318
309
  } catch (err) {
319
- console.warn('Failed to save session:', err);
320
310
  // Try to save at least the backup
321
311
  try {
322
312
  if (session && session.id) {
323
313
  this.updateBackup(session);
324
314
  }
325
315
  } catch (backupErr) {
326
- console.error('Failed to save backup:', backupErr);
327
- }
316
+ }
328
317
  }
329
318
  },
330
319
 
@@ -588,7 +577,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
588
577
  const result = await response.json();
589
578
  return result;
590
579
  } catch (error) {
591
- console.error('Error calling migration endpoint:', error);
592
580
  throw error;
593
581
  }
594
582
  },
@@ -645,18 +633,14 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
645
633
  }
646
634
  })
647
635
  .catch((err) => {
648
- console.warn('⚠️ Failed to migrate userId on backend:', err.message);
649
636
  // UUID already stored in localStorage, migration can happen later
650
637
  });
651
- } else {
652
- console.warn('⚠️ SITE_ID not available, cannot migrate on backend');
653
638
  }
654
639
 
655
640
  // Return new UUID immediately (already stored in localStorage)
656
641
  userId = newUserId;
657
642
  } else if (!uuidRegex.test(userId)) {
658
643
  // Invalid format - regenerate
659
- console.warn('⚠️ Invalid userId format detected. Regenerating as UUID v4...');
660
644
  userId = this.generateUUIDv4();
661
645
  localStorage.setItem(CONFIG.STORAGE_KEYS.USER_ID, userId);
662
646
  }
@@ -665,7 +649,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
665
649
  return userId;
666
650
  } catch (err) {
667
651
  // Fallback: generate temporary UUID (won't persist)
668
- console.warn('Failed to access localStorage for userId:', err);
669
652
  return this.generateUUIDv4(); // Still use UUID even for temp
670
653
  }
671
654
  },
@@ -832,8 +815,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
832
815
  try {
833
816
  localStorage.setItem(CONFIG.STORAGE_KEYS.CONSENT, consent ? "true" : "false");
834
817
  } catch (err) {
835
- console.warn('Failed to save consent:', err);
836
- }
818
+ }
837
819
  },
838
820
 
839
821
  /**
@@ -920,8 +902,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
920
902
  try {
921
903
  localStorage.setItem(CONFIG.STORAGE_KEYS.LAST_SESSION, JSON.stringify(sessionData));
922
904
  } catch (err) {
923
- console.warn('Failed to save last session backup:', err);
924
- }
905
+ }
925
906
  },
926
907
 
927
908
  /**
@@ -946,8 +927,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
946
927
  localStorage.removeItem(CONFIG.STORAGE_KEYS.LAST_SESSION);
947
928
  // Note: We don't clear USER_ID or CONSENT as they're persistent preferences
948
929
  } catch (err) {
949
- console.warn('Failed to clear storage:', err);
950
- }
930
+ }
951
931
  },
952
932
 
953
933
  /**
@@ -1334,7 +1314,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
1334
1314
  // Verify it was saved correctly
1335
1315
  const verify = StorageManager.loadSession();
1336
1316
  if (!verify || verify.id !== newSessionId) {
1337
- console.error("⚠️ SessionStorage write verification failed! Session may not persist across page navigation.");
1338
1317
  // Try to recover from localStorage backup
1339
1318
  try {
1340
1319
  const backup = localStorage.getItem(CONFIG.STORAGE_KEYS.SESSION_BACKUP);
@@ -1350,7 +1329,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
1350
1329
 
1351
1330
  return newSessionId;
1352
1331
  } catch (error) {
1353
- console.error("Error in getOrCreateSessionId:", error);
1354
1332
  // Even on error, ensure we have a valid userId
1355
1333
  sessionData.userId = StorageManager.getUserId();
1356
1334
  userSession.userId = sessionData.userId;
@@ -1398,7 +1376,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
1398
1376
 
1399
1377
  // Ensure sessionId is never null/undefined
1400
1378
  if (!sessionData.sessionId) {
1401
- console.error("❌ sessionData.sessionId is null/undefined after initialization!");
1402
1379
  // Try to get from storage first
1403
1380
  const session = StorageManager.loadSession();
1404
1381
  if (session && session.id) {
@@ -1410,7 +1387,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
1410
1387
  }
1411
1388
  }
1412
1389
  } catch (error) {
1413
- console.error("Error initializing session data:", error);
1414
1390
  // Try to get from storage first, then fallback
1415
1391
  try {
1416
1392
  const session = StorageManager.loadSession();
@@ -1598,8 +1574,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
1598
1574
  } else {
1599
1575
  // No timestamp available - use minimum duration
1600
1576
  calculatedDuration = 1; // Minimum 1 second
1601
- console.warn(`⚠️ No mount time or timestamp available for page: ${currentPage.path} - using minimum duration`);
1602
- }
1577
+ }
1603
1578
  }
1604
1579
 
1605
1580
  // Ensure duration is not negative
@@ -1818,8 +1793,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
1818
1793
  resolve(locationData);
1819
1794
  })
1820
1795
  .catch((err) => {
1821
- console.error("Primary geolocation error:", err);
1822
-
1823
1796
  // Fall back to backup URL
1824
1797
  fetch(CONFIG.GEOLOCATION.BACKUP_URL, fetchOptions)
1825
1798
  .then((res) => {
@@ -1858,7 +1831,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
1858
1831
  resolve(locationData);
1859
1832
  })
1860
1833
  .catch((backupErr) => {
1861
- console.error("Backup geolocation error:", backupErr);
1862
1834
  // Set fallback values
1863
1835
  this.storeLocationData(locationData);
1864
1836
  resolve(locationData);
@@ -1925,7 +1897,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
1925
1897
  const locationData = await this.fetchLocationData();
1926
1898
  return locationData.country;
1927
1899
  } catch (err) {
1928
- console.error("Error fetching country name:", err);
1929
1900
  return "Unknown";
1930
1901
  }
1931
1902
  },
@@ -1980,7 +1951,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
1980
1951
  initialize() {
1981
1952
  // Fetch location data in background (non-blocking)
1982
1953
  this.fetchLocationData().catch((err) => {
1983
- console.warn("Background location fetch failed:", err);
1984
1954
  // Continue with default values
1985
1955
  });
1986
1956
  }
@@ -2740,8 +2710,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
2740
2710
  return `0x${chainId.toString(16)}`;
2741
2711
  }
2742
2712
  } catch (err) {
2743
- console.warn('Error detecting chain ID:', err);
2744
- }
2713
+ }
2745
2714
 
2746
2715
  return null;
2747
2716
  },
@@ -2775,7 +2744,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
2775
2744
  const accounts = await window.ethereum.request({ method: 'eth_accounts' });
2776
2745
  return accounts && accounts.length > 0;
2777
2746
  } catch (error) {
2778
- console.warn('Error checking wallet connection:', error);
2779
2747
  return false;
2780
2748
  }
2781
2749
  },
@@ -2794,7 +2762,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
2794
2762
  const accounts = await window.ethereum.request({ method: 'eth_accounts' });
2795
2763
  return accounts && accounts.length > 0 ? accounts[0] : null;
2796
2764
  } catch (error) {
2797
- console.warn('Error getting wallet address:', error);
2798
2765
  return null;
2799
2766
  }
2800
2767
  },
@@ -2823,7 +2790,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
2823
2790
  try {
2824
2791
  chainName = await this.detectChainName();
2825
2792
  } catch (chainError) {
2826
- console.warn('Error detecting chain name:', chainError);
2827
2793
  chainName = "Unknown Chain";
2828
2794
  }
2829
2795
  }
@@ -2967,13 +2933,11 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
2967
2933
  retries: 1
2968
2934
  });
2969
2935
  } catch (error) {
2970
- console.warn('Error sending wallet update:', error);
2971
2936
  // Don't throw - wallet connection succeeded, just failed to send update
2972
2937
  }
2973
2938
 
2974
2939
  return accounts[0];
2975
2940
  } catch (error) {
2976
- console.error('Error connecting with selected provider:', error);
2977
2941
  throw error;
2978
2942
  }
2979
2943
  },
@@ -3070,9 +3034,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
3070
3034
  return await this.connectWithProvider(selectedProvider);
3071
3035
  } catch (error) {
3072
3036
  // Only log if it's not a cancellation
3073
- if (!error.message || !error.message.includes('cancelled')) {
3074
- console.error('Error connecting wallet:', error);
3075
- }
3037
+ if (!error.message || !error.message.includes('cancelled')) ;
3076
3038
  return null; // Return null instead of throwing
3077
3039
  }
3078
3040
  },
@@ -3104,8 +3066,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
3104
3066
 
3105
3067
  // Update UTM event with newly connected wallet
3106
3068
  APIClient.updateUTMEventWithWallet().catch((error) => {
3107
- console.error('Error updating UTM event with connected wallet:', error);
3108
- });
3069
+ });
3109
3070
  } catch (error) {
3110
3071
  // Only log actual errors (not user cancellations or missing wallets)
3111
3072
  if (error && error.message && !error.message.includes('No wallet provider found')) {
@@ -3188,8 +3149,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
3188
3149
  async initialize() {
3189
3150
  // Initial wallet detection (non-blocking)
3190
3151
  this.updateWalletInfo().catch((err) => {
3191
- console.warn('Initial wallet detection failed:', err);
3192
- });
3152
+ });
3193
3153
 
3194
3154
  // Setup event listeners
3195
3155
  this.setupEventListeners();
@@ -3314,7 +3274,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
3314
3274
 
3315
3275
  // Validate category
3316
3276
  if (!this.CATEGORIES.includes(category)) {
3317
- console.warn(`Invalid interaction category: ${category}`);
3318
3277
  return;
3319
3278
  }
3320
3279
 
@@ -3369,8 +3328,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
3369
3328
  StorageManager.saveSession(storedSession);
3370
3329
  }
3371
3330
  } catch (error) {
3372
- console.warn('Error updating session storage with interactions:', error);
3373
- }
3331
+ }
3374
3332
  },
3375
3333
 
3376
3334
  /**
@@ -3504,7 +3462,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
3504
3462
  }
3505
3463
 
3506
3464
  if (!this.CATEGORIES.includes(category)) {
3507
- console.warn(`Invalid interaction category: ${category}`);
3508
3465
  return [];
3509
3466
  }
3510
3467
 
@@ -3795,8 +3752,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
3795
3752
  // Save updated session
3796
3753
  StorageManager.saveSession(session);
3797
3754
  } catch (error) {
3798
- console.error("Error tracking page visit:", error);
3799
- }
3755
+ }
3800
3756
  },
3801
3757
 
3802
3758
  /**
@@ -3809,7 +3765,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
3809
3765
  try {
3810
3766
  const session = StorageManager.loadSession();
3811
3767
  if (!session || !session.sessionData || !session.sessionData.pageVisits) {
3812
- console.warn('trackBrowserClose: No session data found');
3813
3768
  return;
3814
3769
  }
3815
3770
 
@@ -3851,11 +3806,9 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
3851
3806
  // Save updated session
3852
3807
  StorageManager.saveSession(session);
3853
3808
  } else {
3854
- console.warn(`trackBrowserClose: Last page already has unmountTime or not found`);
3855
- }
3809
+ }
3856
3810
  } catch (error) {
3857
- console.error("Error tracking browser close:", error);
3858
- }
3811
+ }
3859
3812
  },
3860
3813
 
3861
3814
  /**
@@ -4335,8 +4288,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4335
4288
  return referrerHostname;
4336
4289
  }
4337
4290
  } catch (error) {
4338
- console.warn("Error parsing referrer:", error);
4339
- }
4291
+ }
4340
4292
  }
4341
4293
 
4342
4294
  // Step 3: Default to direct traffic
@@ -4394,11 +4346,9 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4394
4346
  if (success) {
4395
4347
  return Promise.resolve();
4396
4348
  } else {
4397
- console.warn('⚠️ sendBeacon returned false, falling back to fetch');
4398
- }
4349
+ }
4399
4350
  } catch (error) {
4400
- console.error('❌ Error with sendBeacon:', error);
4401
- }
4351
+ }
4402
4352
  }
4403
4353
 
4404
4354
  // Use fetch for regular sends or as fallback
@@ -4439,32 +4389,18 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4439
4389
 
4440
4390
  if (!response.ok) {
4441
4391
  // Log detailed error information
4442
- console.error(`❌ API Error (${response.status} ${response.statusText}):`, {
4443
- endpoint: endpoint,
4444
- status: response.status,
4445
- statusText: response.statusText,
4446
- errorResponse: responseData
4447
- });
4448
-
4449
4392
  // Log specific error reasons
4450
4393
  if (response.status === 400) {
4451
- console.error('❌ REASON: Bad Request - Validation error');
4452
4394
  if (responseData && responseData.error) {
4453
- console.error('❌ Validation Error:', responseData.error);
4454
- }
4395
+ }
4455
4396
  if (responseData && responseData.details) {
4456
- console.error('❌ Error Details:', responseData.details);
4457
- }
4397
+ }
4458
4398
  if (responseData && responseData.message) {
4459
- console.error('❌ Error Message:', responseData.message);
4460
- }
4399
+ }
4461
4400
  // Log the payload that failed (for debugging)
4462
- console.error('❌ Failed Payload:', JSON.stringify(payload, null, 2));
4463
- } else if (response.status === 404) {
4464
- console.error('❌ REASON: Not Found - Check if endpoint URL is correct:', endpoint);
4465
- } else if (response.status === 500) {
4466
- console.error('❌ REASON: Server Error - Check backend logs for details');
4467
- }
4401
+ } else if (response.status === 404) {
4402
+ } else if (response.status === 500) {
4403
+ }
4468
4404
 
4469
4405
  throw new Error(`API request failed: ${response.status} ${response.statusText} - ${JSON.stringify(responseData)}`);
4470
4406
  }
@@ -4542,8 +4478,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4542
4478
  timeout: 15000
4543
4479
  });
4544
4480
  } catch (error) {
4545
- console.error('❌ Error sending session data:', error);
4546
- }
4481
+ }
4547
4482
  },
4548
4483
 
4549
4484
 
@@ -4589,8 +4524,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4589
4524
  retries: 1
4590
4525
  });
4591
4526
  } catch (error) {
4592
- console.error('❌ Error sending UTM event:', error);
4593
- }
4527
+ }
4594
4528
  },
4595
4529
 
4596
4530
  /**
@@ -4700,8 +4634,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4700
4634
  }
4701
4635
  });
4702
4636
  } catch (error) {
4703
- console.error('Error in click tracking:', error);
4704
- }
4637
+ }
4705
4638
  },
4706
4639
 
4707
4640
  /**
@@ -4801,8 +4734,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4801
4734
  }
4802
4735
  }, true);
4803
4736
  } catch (error) {
4804
- console.error('Error in form tracking:', error);
4805
- }
4737
+ }
4806
4738
  },
4807
4739
 
4808
4740
  /**
@@ -4871,8 +4803,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4871
4803
  }
4872
4804
  });
4873
4805
  } catch (error) {
4874
- console.error('Error in media tracking:', error);
4875
- }
4806
+ }
4876
4807
  },
4877
4808
 
4878
4809
  /**
@@ -4909,8 +4840,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4909
4840
  }, 150); // Debounce scroll events
4910
4841
  });
4911
4842
  } catch (error) {
4912
- console.error('Error in scroll tracking:', error);
4913
- }
4843
+ }
4914
4844
  },
4915
4845
 
4916
4846
  /**
@@ -4979,8 +4909,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4979
4909
  }
4980
4910
  });
4981
4911
  } catch (error) {
4982
- console.error('Error in hover tracking:', error);
4983
- }
4912
+ }
4984
4913
  },
4985
4914
 
4986
4915
  /**
@@ -5019,8 +4948,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5019
4948
  }
5020
4949
  });
5021
4950
  } catch (error) {
5022
- console.error('Error in keyboard tracking:', error);
5023
- }
4951
+ }
5024
4952
  },
5025
4953
 
5026
4954
  /**
@@ -5055,8 +4983,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5055
4983
  InteractionManager.add('copyPasteEvents', pasteData);
5056
4984
  });
5057
4985
  } catch (error) {
5058
- console.error('Error in copy/paste tracking:', error);
5059
- }
4986
+ }
5060
4987
  },
5061
4988
 
5062
4989
  /**
@@ -5082,8 +5009,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5082
5009
  InteractionManager.add('contextMenuEvents', contextData);
5083
5010
  });
5084
5011
  } catch (error) {
5085
- console.error('Error in context menu tracking:', error);
5086
- }
5012
+ }
5087
5013
  },
5088
5014
 
5089
5015
  /**
@@ -5127,8 +5053,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5127
5053
  InteractionManager.add('dragDropEvents', dropData);
5128
5054
  });
5129
5055
  } catch (error) {
5130
- console.error('Error in drag/drop tracking:', error);
5131
- }
5056
+ }
5132
5057
  },
5133
5058
 
5134
5059
  /**
@@ -5175,8 +5100,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5175
5100
  InteractionManager.add('touchEvents', touchData);
5176
5101
  });
5177
5102
  } catch (error) {
5178
- console.error('Error in touch tracking:', error);
5179
- }
5103
+ }
5180
5104
  },
5181
5105
 
5182
5106
  /**
@@ -5253,8 +5177,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5253
5177
  InteractionManager.add('windowEvents', blurData);
5254
5178
  });
5255
5179
  } catch (error) {
5256
- console.error('Error in window tracking:', error);
5257
- }
5180
+ }
5258
5181
  },
5259
5182
 
5260
5183
  /**
@@ -5281,8 +5204,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5281
5204
  }, 1000);
5282
5205
  });
5283
5206
  } catch (error) {
5284
- console.error('Error in performance tracking:', error);
5285
- }
5207
+ }
5286
5208
  },
5287
5209
 
5288
5210
  /**
@@ -5323,8 +5245,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5323
5245
  InteractionManager.add('errorEvents', errorData);
5324
5246
  });
5325
5247
  } catch (error) {
5326
- console.error('Error in error tracking:', error);
5327
- }
5248
+ }
5328
5249
  },
5329
5250
 
5330
5251
  /**
@@ -5390,8 +5311,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5390
5311
  return originalXHRSend.apply(this, args);
5391
5312
  };
5392
5313
  } catch (error) {
5393
- console.error('Error in network tracking:', error);
5394
- }
5314
+ }
5395
5315
  },
5396
5316
 
5397
5317
  /**
@@ -5429,8 +5349,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5429
5349
  }
5430
5350
  });
5431
5351
  } catch (error) {
5432
- console.error('Error in advanced form tracking:', error);
5433
- }
5352
+ }
5434
5353
  },
5435
5354
 
5436
5355
  /**
@@ -5506,8 +5425,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5506
5425
  localStorage.removeItem(CONFIG.STORAGE_KEYS.LAST_SESSION);
5507
5426
  }
5508
5427
  } catch (error) {
5509
- console.error('Error checking for unsent session data:', error);
5510
- }
5428
+ }
5511
5429
  },
5512
5430
 
5513
5431
  /**
@@ -5532,8 +5450,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5532
5450
  // Initialize page visits
5533
5451
  PageVisitManager.initialize();
5534
5452
  } catch (error) {
5535
- console.error('Error initializing session data:', error);
5536
- }
5453
+ }
5537
5454
  },
5538
5455
 
5539
5456
  /**
@@ -5545,11 +5462,9 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5545
5462
  try {
5546
5463
  // Start location fetch (non-blocking)
5547
5464
  LocationManager.getLocationData().catch(error => {
5548
- console.warn('Location fetch failed (non-critical):', error);
5549
- });
5465
+ });
5550
5466
  } catch (error) {
5551
- console.error('Error initializing location:', error);
5552
- }
5467
+ }
5553
5468
  },
5554
5469
 
5555
5470
  /**
@@ -5560,8 +5475,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5560
5475
  // FIX: Call initialize() which both detects AND stores the data
5561
5476
  await BrowserDeviceManager.initialize();
5562
5477
  } catch (error) {
5563
- console.error('Error initializing browser/device detection:', error);
5564
- }
5478
+ }
5565
5479
  },
5566
5480
 
5567
5481
  /**
@@ -5571,8 +5485,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5571
5485
  try {
5572
5486
  UTMManager.initialize();
5573
5487
  } catch (error) {
5574
- console.error('Error initializing UTM parameters:', error);
5575
- }
5488
+ }
5576
5489
  },
5577
5490
 
5578
5491
  /**
@@ -5582,8 +5495,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5582
5495
  try {
5583
5496
  WalletManager.initialize();
5584
5497
  } catch (error) {
5585
- console.error('Error initializing wallet detection:', error);
5586
- }
5498
+ }
5587
5499
  },
5588
5500
 
5589
5501
  /**
@@ -5593,8 +5505,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5593
5505
  try {
5594
5506
  PageVisitManager.track();
5595
5507
  } catch (error) {
5596
- console.error('Error tracking initial page:', error);
5597
- }
5508
+ }
5598
5509
  },
5599
5510
 
5600
5511
  /**
@@ -5680,12 +5591,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5680
5591
  // Send session data
5681
5592
  await APIClient.sendSessionData();
5682
5593
  } catch (error) {
5683
- console.error('Error in session tracking interval:', error);
5684
- }
5594
+ }
5685
5595
  }, CONFIG.INTERVALS.SESSION_TRACKING_MS);
5686
5596
  } catch (error) {
5687
- console.error('Error starting session tracking:', error);
5688
- }
5597
+ }
5689
5598
  },
5690
5599
 
5691
5600
  /**
@@ -5771,8 +5680,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5771
5680
  JSON.stringify(transformedData)
5772
5681
  );
5773
5682
  } catch (storageError) {
5774
- console.error('Failed to store session backup:', storageError);
5775
- }
5683
+ }
5776
5684
  });
5777
5685
 
5778
5686
  // Clear tracking interval
@@ -5781,12 +5689,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5781
5689
  runtimeState.timer = null;
5782
5690
  }
5783
5691
  } catch (error) {
5784
- console.error('Error in beforeunload handler:', error);
5785
- }
5692
+ }
5786
5693
  });
5787
5694
  } catch (error) {
5788
- console.error('Error setting up beforeunload handler:', error);
5789
- }
5695
+ }
5790
5696
  },
5791
5697
 
5792
5698
  /**
@@ -5805,11 +5711,9 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5805
5711
  // Send UTM event if UTM parameters are present (non-blocking)
5806
5712
  // This should happen after session data is sent so we have sessionId and userId
5807
5713
  APIClient.sendUTMEvent().catch((error) => {
5808
- console.error('Error sending UTM event:', error);
5809
- });
5714
+ });
5810
5715
  } catch (error) {
5811
- console.error('Error sending initial session data:', error);
5812
- }
5716
+ }
5813
5717
  },
5814
5718
 
5815
5719
  /**
@@ -5821,7 +5725,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5821
5725
  try {
5822
5726
  // Check for sessionStorage availability
5823
5727
  if (!window.sessionStorage) {
5824
- console.error('SessionStorage is not available in this browser');
5825
5728
  return;
5826
5729
  }
5827
5730
 
@@ -5861,12 +5764,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5861
5764
  // Mark SDK as initialized
5862
5765
  runtimeState.isInitialized = true;
5863
5766
 
5864
- // Resolve ready promise only after we're initialized (so enableAutoEvents/setup don't see "not initialized")
5865
- if (typeof _readyPromiseResolve === 'function') {
5866
- _readyPromiseResolve();
5867
- _readyPromiseResolve = null;
5868
- }
5869
-
5870
5767
  // Send initial session data (non-blocking)
5871
5768
  this.sendInitialSessionData().catch(() => {
5872
5769
  // Ignore errors, will retry in interval
@@ -5875,10 +5772,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5875
5772
  } catch (error) {
5876
5773
  console.error('Error initializing Cryptique SDK:', error);
5877
5774
  } finally {
5878
- // If init threw before setting isInitialized, resolve anyway so _waitForReady() callers don't hang
5775
+ // Always resolve ready promise so awaiters don't hang (even if init failed)
5879
5776
  if (typeof _readyPromiseResolve === 'function') {
5880
5777
  _readyPromiseResolve();
5881
- _readyPromiseResolve = null;
5778
+ _readyPromiseResolve = null; // Prevent multiple resolves
5882
5779
  }
5883
5780
  }
5884
5781
  }
@@ -5909,8 +5806,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5909
5806
  }
5910
5807
  }
5911
5808
  } catch (error) {
5912
- console.error('Error tracking session continuity:', error);
5913
- }
5809
+ }
5914
5810
  }
5915
5811
 
5916
5812
  /**
@@ -5935,8 +5831,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5935
5831
  try {
5936
5832
  await WalletManager.updateWalletInfo();
5937
5833
  } catch (walletError) {
5938
- console.warn('Error updating wallet info:', walletError);
5939
- }
5834
+ }
5940
5835
 
5941
5836
  // Update session data from storage
5942
5837
  const storedSession = StorageManager.loadSession();
@@ -5965,8 +5860,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5965
5860
  // This function is primarily for internal SDK events
5966
5861
  // Custom events should use trackEvent instead
5967
5862
  } catch (error) {
5968
- console.error('Error in trackEvent:', error);
5969
- }
5863
+ }
5970
5864
  }
5971
5865
 
5972
5866
  // ============================================================================
@@ -5987,14 +5881,12 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5987
5881
  async trackEvent(eventName, properties = {}, options = {}) {
5988
5882
  try {
5989
5883
  if (!runtimeState.isInitialized) {
5990
- console.warn('⚠️ [Events] SDK not initialized, queuing event:', eventName);
5991
5884
  return;
5992
5885
  }
5993
5886
 
5994
5887
  // Get session from storage - it returns { id, userId, ... }
5995
5888
  const storedSession = StorageManager.loadSession();
5996
5889
  if (!storedSession || !storedSession.id) {
5997
- console.error('❌ [Events] No session ID available for custom event tracking');
5998
5890
  return;
5999
5891
  }
6000
5892
 
@@ -6003,7 +5895,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6003
5895
  const sessionId = storedSession.id || sessionData.sessionId || sessionData.session_id;
6004
5896
 
6005
5897
  if (!sessionId) {
6006
- console.error('❌ [Events] Session ID is missing');
6007
5898
  return;
6008
5899
  }
6009
5900
 
@@ -6133,8 +6024,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6133
6024
  // Get session from storage - it returns { id, userId, ... }
6134
6025
  const storedSession = StorageManager.loadSession();
6135
6026
  if (!storedSession || !storedSession.id) {
6136
- console.error('❌ [Events] No session ID available for auto event tracking');
6137
- console.error('❌ [Events] Stored session:', storedSession);
6138
6027
  return;
6139
6028
  }
6140
6029
 
@@ -6143,7 +6032,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6143
6032
  const sessionId = storedSession.id || sessionData.sessionId || sessionData.session_id;
6144
6033
 
6145
6034
  if (!sessionId) {
6146
- console.error('❌ [Events] Session ID is missing');
6147
6035
  return;
6148
6036
  }
6149
6037
 
@@ -6216,11 +6104,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6216
6104
 
6217
6105
  if (!response.ok) {
6218
6106
  const errorData = await response.text();
6219
- console.error('❌ [Events SDK] API error:', {
6220
- status: response.status,
6221
- statusText: response.statusText,
6222
- error: errorData
6223
- });
6224
6107
  throw new Error(`Events API error: ${response.status} ${response.statusText} - ${errorData}`);
6225
6108
  }
6226
6109
 
@@ -6228,7 +6111,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6228
6111
  return result;
6229
6112
 
6230
6113
  } catch (error) {
6231
- console.error('❌ [Events SDK] Error sending event to API:', error);
6232
6114
  throw error;
6233
6115
  }
6234
6116
  },
@@ -6754,8 +6636,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6754
6636
  page_load_time: performance.now(),
6755
6637
  scroll_position: 0
6756
6638
  }).catch(err => {
6757
- console.warn('⚠️ [AutoEvents] Failed to track page_view:', err);
6758
- });
6639
+ });
6759
6640
  }, 1000); // Wait 1 second for session to be created
6760
6641
  },
6761
6642
 
@@ -6878,8 +6759,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6878
6759
  element_area: element.offsetWidth * element.offsetHeight,
6879
6760
  element_category: elementCategory
6880
6761
  }, elementData).catch(err => {
6881
- console.error('❌ [AutoEvents] Failed to track rage_click:', err);
6882
- });
6762
+ });
6883
6763
  }
6884
6764
  } else {
6885
6765
  clickCount = 1;
@@ -6964,8 +6844,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6964
6844
  double_click: event.detail === 2,
6965
6845
  element_category: elementCategory
6966
6846
  }, elementData).catch(err => {
6967
- console.error('❌ [AutoEvents] Failed to track element_click:', err);
6968
- });
6847
+ });
6969
6848
 
6970
6849
  lastClickTime = now;
6971
6850
  lastClickElement = element;
@@ -7002,8 +6881,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
7002
6881
  document_height: docHeight,
7003
6882
  document_width: docWidth
7004
6883
  }).catch(err => {
7005
- console.error('❌ [AutoEvents] Failed to track page_scroll:', err);
7006
- });
6884
+ });
7007
6885
  }
7008
6886
  }, 250);
7009
6887
  });
@@ -8028,7 +7906,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
8028
7906
  * The script.js file is inlined during the build process by Rollup.
8029
7907
  */
8030
7908
 
8031
-
8032
7909
  // Create a wrapper that provides programmatic initialization
8033
7910
  const CryptiqueSDK = {
8034
7911
  /**