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 +70 -193
- package/lib/esm/index.js +70 -193
- package/lib/umd/index.js +70 -193
- package/package.json +1 -1
package/lib/umd/index.js
CHANGED
|
@@ -46,25 +46,17 @@
|
|
|
46
46
|
// - Single place to change environment (dev/prod)
|
|
47
47
|
// ============================================================================
|
|
48
48
|
|
|
49
|
+
// Single SDK API base — change manually for local vs production.
|
|
50
|
+
const SDK_API_BASE = "https://sdkapi.cryptique.io";
|
|
51
|
+
|
|
49
52
|
const CONFIG = {
|
|
50
|
-
// API Endpoints
|
|
53
|
+
// API Endpoints — all SDK writes go to SDK_API_BASE.
|
|
51
54
|
API: {
|
|
52
|
-
TRACK: "
|
|
53
|
-
UTM_EVENTS: "
|
|
54
|
-
EVENTS: "
|
|
55
|
+
TRACK: SDK_API_BASE + "/api/sdk/track",
|
|
56
|
+
UTM_EVENTS: SDK_API_BASE + "/api/utm-events",
|
|
57
|
+
EVENTS: SDK_API_BASE + "/api/events"
|
|
55
58
|
},
|
|
56
59
|
|
|
57
|
-
// Development API (uncomment for local testing)
|
|
58
|
-
|
|
59
|
-
/*API: {
|
|
60
|
-
TRACK: "http://localhost:3002/api/sdk/track", // Main session tracking
|
|
61
|
-
UTM_EVENTS: "http://localhost:3002/api/utm-events", // UTM campaign tracking
|
|
62
|
-
EVENTS: "http://localhost:3002/api/events" // Comprehensive events API
|
|
63
|
-
},*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
60
|
|
|
69
61
|
// SDK Version
|
|
70
62
|
VERSION: "v0.11.24",
|
|
@@ -292,7 +284,6 @@
|
|
|
292
284
|
|
|
293
285
|
return null;
|
|
294
286
|
} catch (err) {
|
|
295
|
-
console.warn('Failed to load session, clearing corrupted data:', err);
|
|
296
287
|
// Clean up corrupted data
|
|
297
288
|
try {
|
|
298
289
|
sessionStorage.removeItem(CONFIG.STORAGE_KEYS.SESSION);
|
|
@@ -320,15 +311,13 @@
|
|
|
320
311
|
this.updateBackup(session);
|
|
321
312
|
}
|
|
322
313
|
} catch (err) {
|
|
323
|
-
console.warn('Failed to save session:', err);
|
|
324
314
|
// Try to save at least the backup
|
|
325
315
|
try {
|
|
326
316
|
if (session && session.id) {
|
|
327
317
|
this.updateBackup(session);
|
|
328
318
|
}
|
|
329
319
|
} catch (backupErr) {
|
|
330
|
-
|
|
331
|
-
}
|
|
320
|
+
}
|
|
332
321
|
}
|
|
333
322
|
},
|
|
334
323
|
|
|
@@ -592,7 +581,6 @@
|
|
|
592
581
|
const result = await response.json();
|
|
593
582
|
return result;
|
|
594
583
|
} catch (error) {
|
|
595
|
-
console.error('Error calling migration endpoint:', error);
|
|
596
584
|
throw error;
|
|
597
585
|
}
|
|
598
586
|
},
|
|
@@ -649,18 +637,14 @@
|
|
|
649
637
|
}
|
|
650
638
|
})
|
|
651
639
|
.catch((err) => {
|
|
652
|
-
console.warn('⚠️ Failed to migrate userId on backend:', err.message);
|
|
653
640
|
// UUID already stored in localStorage, migration can happen later
|
|
654
641
|
});
|
|
655
|
-
} else {
|
|
656
|
-
console.warn('⚠️ SITE_ID not available, cannot migrate on backend');
|
|
657
642
|
}
|
|
658
643
|
|
|
659
644
|
// Return new UUID immediately (already stored in localStorage)
|
|
660
645
|
userId = newUserId;
|
|
661
646
|
} else if (!uuidRegex.test(userId)) {
|
|
662
647
|
// Invalid format - regenerate
|
|
663
|
-
console.warn('⚠️ Invalid userId format detected. Regenerating as UUID v4...');
|
|
664
648
|
userId = this.generateUUIDv4();
|
|
665
649
|
localStorage.setItem(CONFIG.STORAGE_KEYS.USER_ID, userId);
|
|
666
650
|
}
|
|
@@ -669,7 +653,6 @@
|
|
|
669
653
|
return userId;
|
|
670
654
|
} catch (err) {
|
|
671
655
|
// Fallback: generate temporary UUID (won't persist)
|
|
672
|
-
console.warn('Failed to access localStorage for userId:', err);
|
|
673
656
|
return this.generateUUIDv4(); // Still use UUID even for temp
|
|
674
657
|
}
|
|
675
658
|
},
|
|
@@ -836,8 +819,7 @@
|
|
|
836
819
|
try {
|
|
837
820
|
localStorage.setItem(CONFIG.STORAGE_KEYS.CONSENT, consent ? "true" : "false");
|
|
838
821
|
} catch (err) {
|
|
839
|
-
|
|
840
|
-
}
|
|
822
|
+
}
|
|
841
823
|
},
|
|
842
824
|
|
|
843
825
|
/**
|
|
@@ -924,8 +906,7 @@
|
|
|
924
906
|
try {
|
|
925
907
|
localStorage.setItem(CONFIG.STORAGE_KEYS.LAST_SESSION, JSON.stringify(sessionData));
|
|
926
908
|
} catch (err) {
|
|
927
|
-
|
|
928
|
-
}
|
|
909
|
+
}
|
|
929
910
|
},
|
|
930
911
|
|
|
931
912
|
/**
|
|
@@ -950,8 +931,7 @@
|
|
|
950
931
|
localStorage.removeItem(CONFIG.STORAGE_KEYS.LAST_SESSION);
|
|
951
932
|
// Note: We don't clear USER_ID or CONSENT as they're persistent preferences
|
|
952
933
|
} catch (err) {
|
|
953
|
-
|
|
954
|
-
}
|
|
934
|
+
}
|
|
955
935
|
},
|
|
956
936
|
|
|
957
937
|
/**
|
|
@@ -1338,7 +1318,6 @@
|
|
|
1338
1318
|
// Verify it was saved correctly
|
|
1339
1319
|
const verify = StorageManager.loadSession();
|
|
1340
1320
|
if (!verify || verify.id !== newSessionId) {
|
|
1341
|
-
console.error("⚠️ SessionStorage write verification failed! Session may not persist across page navigation.");
|
|
1342
1321
|
// Try to recover from localStorage backup
|
|
1343
1322
|
try {
|
|
1344
1323
|
const backup = localStorage.getItem(CONFIG.STORAGE_KEYS.SESSION_BACKUP);
|
|
@@ -1354,7 +1333,6 @@
|
|
|
1354
1333
|
|
|
1355
1334
|
return newSessionId;
|
|
1356
1335
|
} catch (error) {
|
|
1357
|
-
console.error("Error in getOrCreateSessionId:", error);
|
|
1358
1336
|
// Even on error, ensure we have a valid userId
|
|
1359
1337
|
sessionData.userId = StorageManager.getUserId();
|
|
1360
1338
|
userSession.userId = sessionData.userId;
|
|
@@ -1402,7 +1380,6 @@
|
|
|
1402
1380
|
|
|
1403
1381
|
// Ensure sessionId is never null/undefined
|
|
1404
1382
|
if (!sessionData.sessionId) {
|
|
1405
|
-
console.error("❌ sessionData.sessionId is null/undefined after initialization!");
|
|
1406
1383
|
// Try to get from storage first
|
|
1407
1384
|
const session = StorageManager.loadSession();
|
|
1408
1385
|
if (session && session.id) {
|
|
@@ -1414,7 +1391,6 @@
|
|
|
1414
1391
|
}
|
|
1415
1392
|
}
|
|
1416
1393
|
} catch (error) {
|
|
1417
|
-
console.error("Error initializing session data:", error);
|
|
1418
1394
|
// Try to get from storage first, then fallback
|
|
1419
1395
|
try {
|
|
1420
1396
|
const session = StorageManager.loadSession();
|
|
@@ -1602,8 +1578,7 @@
|
|
|
1602
1578
|
} else {
|
|
1603
1579
|
// No timestamp available - use minimum duration
|
|
1604
1580
|
calculatedDuration = 1; // Minimum 1 second
|
|
1605
|
-
|
|
1606
|
-
}
|
|
1581
|
+
}
|
|
1607
1582
|
}
|
|
1608
1583
|
|
|
1609
1584
|
// Ensure duration is not negative
|
|
@@ -1822,8 +1797,6 @@
|
|
|
1822
1797
|
resolve(locationData);
|
|
1823
1798
|
})
|
|
1824
1799
|
.catch((err) => {
|
|
1825
|
-
console.error("Primary geolocation error:", err);
|
|
1826
|
-
|
|
1827
1800
|
// Fall back to backup URL
|
|
1828
1801
|
fetch(CONFIG.GEOLOCATION.BACKUP_URL, fetchOptions)
|
|
1829
1802
|
.then((res) => {
|
|
@@ -1862,7 +1835,6 @@
|
|
|
1862
1835
|
resolve(locationData);
|
|
1863
1836
|
})
|
|
1864
1837
|
.catch((backupErr) => {
|
|
1865
|
-
console.error("Backup geolocation error:", backupErr);
|
|
1866
1838
|
// Set fallback values
|
|
1867
1839
|
this.storeLocationData(locationData);
|
|
1868
1840
|
resolve(locationData);
|
|
@@ -1929,7 +1901,6 @@
|
|
|
1929
1901
|
const locationData = await this.fetchLocationData();
|
|
1930
1902
|
return locationData.country;
|
|
1931
1903
|
} catch (err) {
|
|
1932
|
-
console.error("Error fetching country name:", err);
|
|
1933
1904
|
return "Unknown";
|
|
1934
1905
|
}
|
|
1935
1906
|
},
|
|
@@ -1984,7 +1955,6 @@
|
|
|
1984
1955
|
initialize() {
|
|
1985
1956
|
// Fetch location data in background (non-blocking)
|
|
1986
1957
|
this.fetchLocationData().catch((err) => {
|
|
1987
|
-
console.warn("Background location fetch failed:", err);
|
|
1988
1958
|
// Continue with default values
|
|
1989
1959
|
});
|
|
1990
1960
|
}
|
|
@@ -2744,8 +2714,7 @@
|
|
|
2744
2714
|
return `0x${chainId.toString(16)}`;
|
|
2745
2715
|
}
|
|
2746
2716
|
} catch (err) {
|
|
2747
|
-
|
|
2748
|
-
}
|
|
2717
|
+
}
|
|
2749
2718
|
|
|
2750
2719
|
return null;
|
|
2751
2720
|
},
|
|
@@ -2779,7 +2748,6 @@
|
|
|
2779
2748
|
const accounts = await window.ethereum.request({ method: 'eth_accounts' });
|
|
2780
2749
|
return accounts && accounts.length > 0;
|
|
2781
2750
|
} catch (error) {
|
|
2782
|
-
console.warn('Error checking wallet connection:', error);
|
|
2783
2751
|
return false;
|
|
2784
2752
|
}
|
|
2785
2753
|
},
|
|
@@ -2798,7 +2766,6 @@
|
|
|
2798
2766
|
const accounts = await window.ethereum.request({ method: 'eth_accounts' });
|
|
2799
2767
|
return accounts && accounts.length > 0 ? accounts[0] : null;
|
|
2800
2768
|
} catch (error) {
|
|
2801
|
-
console.warn('Error getting wallet address:', error);
|
|
2802
2769
|
return null;
|
|
2803
2770
|
}
|
|
2804
2771
|
},
|
|
@@ -2827,7 +2794,6 @@
|
|
|
2827
2794
|
try {
|
|
2828
2795
|
chainName = await this.detectChainName();
|
|
2829
2796
|
} catch (chainError) {
|
|
2830
|
-
console.warn('Error detecting chain name:', chainError);
|
|
2831
2797
|
chainName = "Unknown Chain";
|
|
2832
2798
|
}
|
|
2833
2799
|
}
|
|
@@ -2971,13 +2937,11 @@
|
|
|
2971
2937
|
retries: 1
|
|
2972
2938
|
});
|
|
2973
2939
|
} catch (error) {
|
|
2974
|
-
console.warn('Error sending wallet update:', error);
|
|
2975
2940
|
// Don't throw - wallet connection succeeded, just failed to send update
|
|
2976
2941
|
}
|
|
2977
2942
|
|
|
2978
2943
|
return accounts[0];
|
|
2979
2944
|
} catch (error) {
|
|
2980
|
-
console.error('Error connecting with selected provider:', error);
|
|
2981
2945
|
throw error;
|
|
2982
2946
|
}
|
|
2983
2947
|
},
|
|
@@ -3074,9 +3038,7 @@
|
|
|
3074
3038
|
return await this.connectWithProvider(selectedProvider);
|
|
3075
3039
|
} catch (error) {
|
|
3076
3040
|
// Only log if it's not a cancellation
|
|
3077
|
-
if (!error.message || !error.message.includes('cancelled'))
|
|
3078
|
-
console.error('Error connecting wallet:', error);
|
|
3079
|
-
}
|
|
3041
|
+
if (!error.message || !error.message.includes('cancelled')) ;
|
|
3080
3042
|
return null; // Return null instead of throwing
|
|
3081
3043
|
}
|
|
3082
3044
|
},
|
|
@@ -3108,8 +3070,7 @@
|
|
|
3108
3070
|
|
|
3109
3071
|
// Update UTM event with newly connected wallet
|
|
3110
3072
|
APIClient.updateUTMEventWithWallet().catch((error) => {
|
|
3111
|
-
|
|
3112
|
-
});
|
|
3073
|
+
});
|
|
3113
3074
|
} catch (error) {
|
|
3114
3075
|
// Only log actual errors (not user cancellations or missing wallets)
|
|
3115
3076
|
if (error && error.message && !error.message.includes('No wallet provider found')) {
|
|
@@ -3192,8 +3153,7 @@
|
|
|
3192
3153
|
async initialize() {
|
|
3193
3154
|
// Initial wallet detection (non-blocking)
|
|
3194
3155
|
this.updateWalletInfo().catch((err) => {
|
|
3195
|
-
|
|
3196
|
-
});
|
|
3156
|
+
});
|
|
3197
3157
|
|
|
3198
3158
|
// Setup event listeners
|
|
3199
3159
|
this.setupEventListeners();
|
|
@@ -3318,7 +3278,6 @@
|
|
|
3318
3278
|
|
|
3319
3279
|
// Validate category
|
|
3320
3280
|
if (!this.CATEGORIES.includes(category)) {
|
|
3321
|
-
console.warn(`Invalid interaction category: ${category}`);
|
|
3322
3281
|
return;
|
|
3323
3282
|
}
|
|
3324
3283
|
|
|
@@ -3373,8 +3332,7 @@
|
|
|
3373
3332
|
StorageManager.saveSession(storedSession);
|
|
3374
3333
|
}
|
|
3375
3334
|
} catch (error) {
|
|
3376
|
-
|
|
3377
|
-
}
|
|
3335
|
+
}
|
|
3378
3336
|
},
|
|
3379
3337
|
|
|
3380
3338
|
/**
|
|
@@ -3508,7 +3466,6 @@
|
|
|
3508
3466
|
}
|
|
3509
3467
|
|
|
3510
3468
|
if (!this.CATEGORIES.includes(category)) {
|
|
3511
|
-
console.warn(`Invalid interaction category: ${category}`);
|
|
3512
3469
|
return [];
|
|
3513
3470
|
}
|
|
3514
3471
|
|
|
@@ -3799,8 +3756,7 @@
|
|
|
3799
3756
|
// Save updated session
|
|
3800
3757
|
StorageManager.saveSession(session);
|
|
3801
3758
|
} catch (error) {
|
|
3802
|
-
|
|
3803
|
-
}
|
|
3759
|
+
}
|
|
3804
3760
|
},
|
|
3805
3761
|
|
|
3806
3762
|
/**
|
|
@@ -3813,7 +3769,6 @@
|
|
|
3813
3769
|
try {
|
|
3814
3770
|
const session = StorageManager.loadSession();
|
|
3815
3771
|
if (!session || !session.sessionData || !session.sessionData.pageVisits) {
|
|
3816
|
-
console.warn('trackBrowserClose: No session data found');
|
|
3817
3772
|
return;
|
|
3818
3773
|
}
|
|
3819
3774
|
|
|
@@ -3855,11 +3810,9 @@
|
|
|
3855
3810
|
// Save updated session
|
|
3856
3811
|
StorageManager.saveSession(session);
|
|
3857
3812
|
} else {
|
|
3858
|
-
|
|
3859
|
-
}
|
|
3813
|
+
}
|
|
3860
3814
|
} catch (error) {
|
|
3861
|
-
|
|
3862
|
-
}
|
|
3815
|
+
}
|
|
3863
3816
|
},
|
|
3864
3817
|
|
|
3865
3818
|
/**
|
|
@@ -4339,8 +4292,7 @@
|
|
|
4339
4292
|
return referrerHostname;
|
|
4340
4293
|
}
|
|
4341
4294
|
} catch (error) {
|
|
4342
|
-
|
|
4343
|
-
}
|
|
4295
|
+
}
|
|
4344
4296
|
}
|
|
4345
4297
|
|
|
4346
4298
|
// Step 3: Default to direct traffic
|
|
@@ -4398,11 +4350,9 @@
|
|
|
4398
4350
|
if (success) {
|
|
4399
4351
|
return Promise.resolve();
|
|
4400
4352
|
} else {
|
|
4401
|
-
|
|
4402
|
-
}
|
|
4353
|
+
}
|
|
4403
4354
|
} catch (error) {
|
|
4404
|
-
|
|
4405
|
-
}
|
|
4355
|
+
}
|
|
4406
4356
|
}
|
|
4407
4357
|
|
|
4408
4358
|
// Use fetch for regular sends or as fallback
|
|
@@ -4443,32 +4393,18 @@
|
|
|
4443
4393
|
|
|
4444
4394
|
if (!response.ok) {
|
|
4445
4395
|
// Log detailed error information
|
|
4446
|
-
console.error(`❌ API Error (${response.status} ${response.statusText}):`, {
|
|
4447
|
-
endpoint: endpoint,
|
|
4448
|
-
status: response.status,
|
|
4449
|
-
statusText: response.statusText,
|
|
4450
|
-
errorResponse: responseData
|
|
4451
|
-
});
|
|
4452
|
-
|
|
4453
4396
|
// Log specific error reasons
|
|
4454
4397
|
if (response.status === 400) {
|
|
4455
|
-
console.error('❌ REASON: Bad Request - Validation error');
|
|
4456
4398
|
if (responseData && responseData.error) {
|
|
4457
|
-
|
|
4458
|
-
}
|
|
4399
|
+
}
|
|
4459
4400
|
if (responseData && responseData.details) {
|
|
4460
|
-
|
|
4461
|
-
}
|
|
4401
|
+
}
|
|
4462
4402
|
if (responseData && responseData.message) {
|
|
4463
|
-
|
|
4464
|
-
}
|
|
4403
|
+
}
|
|
4465
4404
|
// Log the payload that failed (for debugging)
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
} else if (response.status === 500) {
|
|
4470
|
-
console.error('❌ REASON: Server Error - Check backend logs for details');
|
|
4471
|
-
}
|
|
4405
|
+
} else if (response.status === 404) {
|
|
4406
|
+
} else if (response.status === 500) {
|
|
4407
|
+
}
|
|
4472
4408
|
|
|
4473
4409
|
throw new Error(`API request failed: ${response.status} ${response.statusText} - ${JSON.stringify(responseData)}`);
|
|
4474
4410
|
}
|
|
@@ -4546,8 +4482,7 @@
|
|
|
4546
4482
|
timeout: 15000
|
|
4547
4483
|
});
|
|
4548
4484
|
} catch (error) {
|
|
4549
|
-
|
|
4550
|
-
}
|
|
4485
|
+
}
|
|
4551
4486
|
},
|
|
4552
4487
|
|
|
4553
4488
|
|
|
@@ -4593,8 +4528,7 @@
|
|
|
4593
4528
|
retries: 1
|
|
4594
4529
|
});
|
|
4595
4530
|
} catch (error) {
|
|
4596
|
-
|
|
4597
|
-
}
|
|
4531
|
+
}
|
|
4598
4532
|
},
|
|
4599
4533
|
|
|
4600
4534
|
/**
|
|
@@ -4704,8 +4638,7 @@
|
|
|
4704
4638
|
}
|
|
4705
4639
|
});
|
|
4706
4640
|
} catch (error) {
|
|
4707
|
-
|
|
4708
|
-
}
|
|
4641
|
+
}
|
|
4709
4642
|
},
|
|
4710
4643
|
|
|
4711
4644
|
/**
|
|
@@ -4805,8 +4738,7 @@
|
|
|
4805
4738
|
}
|
|
4806
4739
|
}, true);
|
|
4807
4740
|
} catch (error) {
|
|
4808
|
-
|
|
4809
|
-
}
|
|
4741
|
+
}
|
|
4810
4742
|
},
|
|
4811
4743
|
|
|
4812
4744
|
/**
|
|
@@ -4875,8 +4807,7 @@
|
|
|
4875
4807
|
}
|
|
4876
4808
|
});
|
|
4877
4809
|
} catch (error) {
|
|
4878
|
-
|
|
4879
|
-
}
|
|
4810
|
+
}
|
|
4880
4811
|
},
|
|
4881
4812
|
|
|
4882
4813
|
/**
|
|
@@ -4913,8 +4844,7 @@
|
|
|
4913
4844
|
}, 150); // Debounce scroll events
|
|
4914
4845
|
});
|
|
4915
4846
|
} catch (error) {
|
|
4916
|
-
|
|
4917
|
-
}
|
|
4847
|
+
}
|
|
4918
4848
|
},
|
|
4919
4849
|
|
|
4920
4850
|
/**
|
|
@@ -4983,8 +4913,7 @@
|
|
|
4983
4913
|
}
|
|
4984
4914
|
});
|
|
4985
4915
|
} catch (error) {
|
|
4986
|
-
|
|
4987
|
-
}
|
|
4916
|
+
}
|
|
4988
4917
|
},
|
|
4989
4918
|
|
|
4990
4919
|
/**
|
|
@@ -5023,8 +4952,7 @@
|
|
|
5023
4952
|
}
|
|
5024
4953
|
});
|
|
5025
4954
|
} catch (error) {
|
|
5026
|
-
|
|
5027
|
-
}
|
|
4955
|
+
}
|
|
5028
4956
|
},
|
|
5029
4957
|
|
|
5030
4958
|
/**
|
|
@@ -5059,8 +4987,7 @@
|
|
|
5059
4987
|
InteractionManager.add('copyPasteEvents', pasteData);
|
|
5060
4988
|
});
|
|
5061
4989
|
} catch (error) {
|
|
5062
|
-
|
|
5063
|
-
}
|
|
4990
|
+
}
|
|
5064
4991
|
},
|
|
5065
4992
|
|
|
5066
4993
|
/**
|
|
@@ -5086,8 +5013,7 @@
|
|
|
5086
5013
|
InteractionManager.add('contextMenuEvents', contextData);
|
|
5087
5014
|
});
|
|
5088
5015
|
} catch (error) {
|
|
5089
|
-
|
|
5090
|
-
}
|
|
5016
|
+
}
|
|
5091
5017
|
},
|
|
5092
5018
|
|
|
5093
5019
|
/**
|
|
@@ -5131,8 +5057,7 @@
|
|
|
5131
5057
|
InteractionManager.add('dragDropEvents', dropData);
|
|
5132
5058
|
});
|
|
5133
5059
|
} catch (error) {
|
|
5134
|
-
|
|
5135
|
-
}
|
|
5060
|
+
}
|
|
5136
5061
|
},
|
|
5137
5062
|
|
|
5138
5063
|
/**
|
|
@@ -5179,8 +5104,7 @@
|
|
|
5179
5104
|
InteractionManager.add('touchEvents', touchData);
|
|
5180
5105
|
});
|
|
5181
5106
|
} catch (error) {
|
|
5182
|
-
|
|
5183
|
-
}
|
|
5107
|
+
}
|
|
5184
5108
|
},
|
|
5185
5109
|
|
|
5186
5110
|
/**
|
|
@@ -5257,8 +5181,7 @@
|
|
|
5257
5181
|
InteractionManager.add('windowEvents', blurData);
|
|
5258
5182
|
});
|
|
5259
5183
|
} catch (error) {
|
|
5260
|
-
|
|
5261
|
-
}
|
|
5184
|
+
}
|
|
5262
5185
|
},
|
|
5263
5186
|
|
|
5264
5187
|
/**
|
|
@@ -5285,8 +5208,7 @@
|
|
|
5285
5208
|
}, 1000);
|
|
5286
5209
|
});
|
|
5287
5210
|
} catch (error) {
|
|
5288
|
-
|
|
5289
|
-
}
|
|
5211
|
+
}
|
|
5290
5212
|
},
|
|
5291
5213
|
|
|
5292
5214
|
/**
|
|
@@ -5327,8 +5249,7 @@
|
|
|
5327
5249
|
InteractionManager.add('errorEvents', errorData);
|
|
5328
5250
|
});
|
|
5329
5251
|
} catch (error) {
|
|
5330
|
-
|
|
5331
|
-
}
|
|
5252
|
+
}
|
|
5332
5253
|
},
|
|
5333
5254
|
|
|
5334
5255
|
/**
|
|
@@ -5394,8 +5315,7 @@
|
|
|
5394
5315
|
return originalXHRSend.apply(this, args);
|
|
5395
5316
|
};
|
|
5396
5317
|
} catch (error) {
|
|
5397
|
-
|
|
5398
|
-
}
|
|
5318
|
+
}
|
|
5399
5319
|
},
|
|
5400
5320
|
|
|
5401
5321
|
/**
|
|
@@ -5433,8 +5353,7 @@
|
|
|
5433
5353
|
}
|
|
5434
5354
|
});
|
|
5435
5355
|
} catch (error) {
|
|
5436
|
-
|
|
5437
|
-
}
|
|
5356
|
+
}
|
|
5438
5357
|
},
|
|
5439
5358
|
|
|
5440
5359
|
/**
|
|
@@ -5510,8 +5429,7 @@
|
|
|
5510
5429
|
localStorage.removeItem(CONFIG.STORAGE_KEYS.LAST_SESSION);
|
|
5511
5430
|
}
|
|
5512
5431
|
} catch (error) {
|
|
5513
|
-
|
|
5514
|
-
}
|
|
5432
|
+
}
|
|
5515
5433
|
},
|
|
5516
5434
|
|
|
5517
5435
|
/**
|
|
@@ -5536,8 +5454,7 @@
|
|
|
5536
5454
|
// Initialize page visits
|
|
5537
5455
|
PageVisitManager.initialize();
|
|
5538
5456
|
} catch (error) {
|
|
5539
|
-
|
|
5540
|
-
}
|
|
5457
|
+
}
|
|
5541
5458
|
},
|
|
5542
5459
|
|
|
5543
5460
|
/**
|
|
@@ -5549,11 +5466,9 @@
|
|
|
5549
5466
|
try {
|
|
5550
5467
|
// Start location fetch (non-blocking)
|
|
5551
5468
|
LocationManager.getLocationData().catch(error => {
|
|
5552
|
-
|
|
5553
|
-
});
|
|
5469
|
+
});
|
|
5554
5470
|
} catch (error) {
|
|
5555
|
-
|
|
5556
|
-
}
|
|
5471
|
+
}
|
|
5557
5472
|
},
|
|
5558
5473
|
|
|
5559
5474
|
/**
|
|
@@ -5564,8 +5479,7 @@
|
|
|
5564
5479
|
// FIX: Call initialize() which both detects AND stores the data
|
|
5565
5480
|
await BrowserDeviceManager.initialize();
|
|
5566
5481
|
} catch (error) {
|
|
5567
|
-
|
|
5568
|
-
}
|
|
5482
|
+
}
|
|
5569
5483
|
},
|
|
5570
5484
|
|
|
5571
5485
|
/**
|
|
@@ -5575,8 +5489,7 @@
|
|
|
5575
5489
|
try {
|
|
5576
5490
|
UTMManager.initialize();
|
|
5577
5491
|
} catch (error) {
|
|
5578
|
-
|
|
5579
|
-
}
|
|
5492
|
+
}
|
|
5580
5493
|
},
|
|
5581
5494
|
|
|
5582
5495
|
/**
|
|
@@ -5586,8 +5499,7 @@
|
|
|
5586
5499
|
try {
|
|
5587
5500
|
WalletManager.initialize();
|
|
5588
5501
|
} catch (error) {
|
|
5589
|
-
|
|
5590
|
-
}
|
|
5502
|
+
}
|
|
5591
5503
|
},
|
|
5592
5504
|
|
|
5593
5505
|
/**
|
|
@@ -5597,8 +5509,7 @@
|
|
|
5597
5509
|
try {
|
|
5598
5510
|
PageVisitManager.track();
|
|
5599
5511
|
} catch (error) {
|
|
5600
|
-
|
|
5601
|
-
}
|
|
5512
|
+
}
|
|
5602
5513
|
},
|
|
5603
5514
|
|
|
5604
5515
|
/**
|
|
@@ -5684,12 +5595,10 @@
|
|
|
5684
5595
|
// Send session data
|
|
5685
5596
|
await APIClient.sendSessionData();
|
|
5686
5597
|
} catch (error) {
|
|
5687
|
-
|
|
5688
|
-
}
|
|
5598
|
+
}
|
|
5689
5599
|
}, CONFIG.INTERVALS.SESSION_TRACKING_MS);
|
|
5690
5600
|
} catch (error) {
|
|
5691
|
-
|
|
5692
|
-
}
|
|
5601
|
+
}
|
|
5693
5602
|
},
|
|
5694
5603
|
|
|
5695
5604
|
/**
|
|
@@ -5775,8 +5684,7 @@
|
|
|
5775
5684
|
JSON.stringify(transformedData)
|
|
5776
5685
|
);
|
|
5777
5686
|
} catch (storageError) {
|
|
5778
|
-
|
|
5779
|
-
}
|
|
5687
|
+
}
|
|
5780
5688
|
});
|
|
5781
5689
|
|
|
5782
5690
|
// Clear tracking interval
|
|
@@ -5785,12 +5693,10 @@
|
|
|
5785
5693
|
runtimeState.timer = null;
|
|
5786
5694
|
}
|
|
5787
5695
|
} catch (error) {
|
|
5788
|
-
|
|
5789
|
-
}
|
|
5696
|
+
}
|
|
5790
5697
|
});
|
|
5791
5698
|
} catch (error) {
|
|
5792
|
-
|
|
5793
|
-
}
|
|
5699
|
+
}
|
|
5794
5700
|
},
|
|
5795
5701
|
|
|
5796
5702
|
/**
|
|
@@ -5809,11 +5715,9 @@
|
|
|
5809
5715
|
// Send UTM event if UTM parameters are present (non-blocking)
|
|
5810
5716
|
// This should happen after session data is sent so we have sessionId and userId
|
|
5811
5717
|
APIClient.sendUTMEvent().catch((error) => {
|
|
5812
|
-
|
|
5813
|
-
});
|
|
5718
|
+
});
|
|
5814
5719
|
} catch (error) {
|
|
5815
|
-
|
|
5816
|
-
}
|
|
5720
|
+
}
|
|
5817
5721
|
},
|
|
5818
5722
|
|
|
5819
5723
|
/**
|
|
@@ -5825,7 +5729,6 @@
|
|
|
5825
5729
|
try {
|
|
5826
5730
|
// Check for sessionStorage availability
|
|
5827
5731
|
if (!window.sessionStorage) {
|
|
5828
|
-
console.error('SessionStorage is not available in this browser');
|
|
5829
5732
|
return;
|
|
5830
5733
|
}
|
|
5831
5734
|
|
|
@@ -5865,12 +5768,6 @@
|
|
|
5865
5768
|
// Mark SDK as initialized
|
|
5866
5769
|
runtimeState.isInitialized = true;
|
|
5867
5770
|
|
|
5868
|
-
// Resolve ready promise only after we're initialized (so enableAutoEvents/setup don't see "not initialized")
|
|
5869
|
-
if (typeof _readyPromiseResolve === 'function') {
|
|
5870
|
-
_readyPromiseResolve();
|
|
5871
|
-
_readyPromiseResolve = null;
|
|
5872
|
-
}
|
|
5873
|
-
|
|
5874
5771
|
// Send initial session data (non-blocking)
|
|
5875
5772
|
this.sendInitialSessionData().catch(() => {
|
|
5876
5773
|
// Ignore errors, will retry in interval
|
|
@@ -5879,10 +5776,10 @@
|
|
|
5879
5776
|
} catch (error) {
|
|
5880
5777
|
console.error('Error initializing Cryptique SDK:', error);
|
|
5881
5778
|
} finally {
|
|
5882
|
-
//
|
|
5779
|
+
// Always resolve ready promise so awaiters don't hang (even if init failed)
|
|
5883
5780
|
if (typeof _readyPromiseResolve === 'function') {
|
|
5884
5781
|
_readyPromiseResolve();
|
|
5885
|
-
_readyPromiseResolve = null;
|
|
5782
|
+
_readyPromiseResolve = null; // Prevent multiple resolves
|
|
5886
5783
|
}
|
|
5887
5784
|
}
|
|
5888
5785
|
}
|
|
@@ -5913,8 +5810,7 @@
|
|
|
5913
5810
|
}
|
|
5914
5811
|
}
|
|
5915
5812
|
} catch (error) {
|
|
5916
|
-
|
|
5917
|
-
}
|
|
5813
|
+
}
|
|
5918
5814
|
}
|
|
5919
5815
|
|
|
5920
5816
|
/**
|
|
@@ -5939,8 +5835,7 @@
|
|
|
5939
5835
|
try {
|
|
5940
5836
|
await WalletManager.updateWalletInfo();
|
|
5941
5837
|
} catch (walletError) {
|
|
5942
|
-
|
|
5943
|
-
}
|
|
5838
|
+
}
|
|
5944
5839
|
|
|
5945
5840
|
// Update session data from storage
|
|
5946
5841
|
const storedSession = StorageManager.loadSession();
|
|
@@ -5969,8 +5864,7 @@
|
|
|
5969
5864
|
// This function is primarily for internal SDK events
|
|
5970
5865
|
// Custom events should use trackEvent instead
|
|
5971
5866
|
} catch (error) {
|
|
5972
|
-
|
|
5973
|
-
}
|
|
5867
|
+
}
|
|
5974
5868
|
}
|
|
5975
5869
|
|
|
5976
5870
|
// ============================================================================
|
|
@@ -5991,14 +5885,12 @@
|
|
|
5991
5885
|
async trackEvent(eventName, properties = {}, options = {}) {
|
|
5992
5886
|
try {
|
|
5993
5887
|
if (!runtimeState.isInitialized) {
|
|
5994
|
-
console.warn('⚠️ [Events] SDK not initialized, queuing event:', eventName);
|
|
5995
5888
|
return;
|
|
5996
5889
|
}
|
|
5997
5890
|
|
|
5998
5891
|
// Get session from storage - it returns { id, userId, ... }
|
|
5999
5892
|
const storedSession = StorageManager.loadSession();
|
|
6000
5893
|
if (!storedSession || !storedSession.id) {
|
|
6001
|
-
console.error('❌ [Events] No session ID available for custom event tracking');
|
|
6002
5894
|
return;
|
|
6003
5895
|
}
|
|
6004
5896
|
|
|
@@ -6007,7 +5899,6 @@
|
|
|
6007
5899
|
const sessionId = storedSession.id || sessionData.sessionId || sessionData.session_id;
|
|
6008
5900
|
|
|
6009
5901
|
if (!sessionId) {
|
|
6010
|
-
console.error('❌ [Events] Session ID is missing');
|
|
6011
5902
|
return;
|
|
6012
5903
|
}
|
|
6013
5904
|
|
|
@@ -6137,8 +6028,6 @@
|
|
|
6137
6028
|
// Get session from storage - it returns { id, userId, ... }
|
|
6138
6029
|
const storedSession = StorageManager.loadSession();
|
|
6139
6030
|
if (!storedSession || !storedSession.id) {
|
|
6140
|
-
console.error('❌ [Events] No session ID available for auto event tracking');
|
|
6141
|
-
console.error('❌ [Events] Stored session:', storedSession);
|
|
6142
6031
|
return;
|
|
6143
6032
|
}
|
|
6144
6033
|
|
|
@@ -6147,7 +6036,6 @@
|
|
|
6147
6036
|
const sessionId = storedSession.id || sessionData.sessionId || sessionData.session_id;
|
|
6148
6037
|
|
|
6149
6038
|
if (!sessionId) {
|
|
6150
|
-
console.error('❌ [Events] Session ID is missing');
|
|
6151
6039
|
return;
|
|
6152
6040
|
}
|
|
6153
6041
|
|
|
@@ -6220,11 +6108,6 @@
|
|
|
6220
6108
|
|
|
6221
6109
|
if (!response.ok) {
|
|
6222
6110
|
const errorData = await response.text();
|
|
6223
|
-
console.error('❌ [Events SDK] API error:', {
|
|
6224
|
-
status: response.status,
|
|
6225
|
-
statusText: response.statusText,
|
|
6226
|
-
error: errorData
|
|
6227
|
-
});
|
|
6228
6111
|
throw new Error(`Events API error: ${response.status} ${response.statusText} - ${errorData}`);
|
|
6229
6112
|
}
|
|
6230
6113
|
|
|
@@ -6232,7 +6115,6 @@
|
|
|
6232
6115
|
return result;
|
|
6233
6116
|
|
|
6234
6117
|
} catch (error) {
|
|
6235
|
-
console.error('❌ [Events SDK] Error sending event to API:', error);
|
|
6236
6118
|
throw error;
|
|
6237
6119
|
}
|
|
6238
6120
|
},
|
|
@@ -6758,8 +6640,7 @@
|
|
|
6758
6640
|
page_load_time: performance.now(),
|
|
6759
6641
|
scroll_position: 0
|
|
6760
6642
|
}).catch(err => {
|
|
6761
|
-
|
|
6762
|
-
});
|
|
6643
|
+
});
|
|
6763
6644
|
}, 1000); // Wait 1 second for session to be created
|
|
6764
6645
|
},
|
|
6765
6646
|
|
|
@@ -6882,8 +6763,7 @@
|
|
|
6882
6763
|
element_area: element.offsetWidth * element.offsetHeight,
|
|
6883
6764
|
element_category: elementCategory
|
|
6884
6765
|
}, elementData).catch(err => {
|
|
6885
|
-
|
|
6886
|
-
});
|
|
6766
|
+
});
|
|
6887
6767
|
}
|
|
6888
6768
|
} else {
|
|
6889
6769
|
clickCount = 1;
|
|
@@ -6968,8 +6848,7 @@
|
|
|
6968
6848
|
double_click: event.detail === 2,
|
|
6969
6849
|
element_category: elementCategory
|
|
6970
6850
|
}, elementData).catch(err => {
|
|
6971
|
-
|
|
6972
|
-
});
|
|
6851
|
+
});
|
|
6973
6852
|
|
|
6974
6853
|
lastClickTime = now;
|
|
6975
6854
|
lastClickElement = element;
|
|
@@ -7006,8 +6885,7 @@
|
|
|
7006
6885
|
document_height: docHeight,
|
|
7007
6886
|
document_width: docWidth
|
|
7008
6887
|
}).catch(err => {
|
|
7009
|
-
|
|
7010
|
-
});
|
|
6888
|
+
});
|
|
7011
6889
|
}
|
|
7012
6890
|
}, 250);
|
|
7013
6891
|
});
|
|
@@ -8032,7 +7910,6 @@
|
|
|
8032
7910
|
* The script.js file is inlined during the build process by Rollup.
|
|
8033
7911
|
*/
|
|
8034
7912
|
|
|
8035
|
-
|
|
8036
7913
|
// Create a wrapper that provides programmatic initialization
|
|
8037
7914
|
const CryptiqueSDK = {
|
|
8038
7915
|
/**
|