cryptique-sdk 1.0.2 → 1.0.3

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
@@ -114,7 +114,18 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
114
114
 
115
115
  // Get Site ID from script tag attribute
116
116
  const analyticsScript = document.currentScript || document.querySelector('script[src*="script.js"]') || document.querySelector('script[src*="cryptique"]');
117
- const SITE_ID = analyticsScript ? analyticsScript.getAttribute("site-id") : null;
117
+ let SITE_ID = analyticsScript ? analyticsScript.getAttribute("site-id") : null;
118
+
119
+ // Fallback: Check window.Cryptique.siteId or global variable (for npm usage)
120
+ if (!SITE_ID) {
121
+ SITE_ID = window.Cryptique?.siteId || window.__CRYPTIQUE_SITE_ID__ || null;
122
+ }
123
+
124
+ // Helper function to get current site ID (checks all sources dynamically)
125
+ // This allows site ID to be set via init() after SDK loads
126
+ function getCurrentSiteId() {
127
+ return SITE_ID || window.Cryptique?.siteId || window.__CRYPTIQUE_SITE_ID__ || null;
128
+ }
118
129
 
119
130
  // Parse auto events configuration from script tag attributes
120
131
  // Default: auto events disabled, empty disabled paths array
@@ -723,7 +734,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
723
734
  let sessionData = {
724
735
  // IDs (internal camelCase)
725
736
  sessionId: null, // Will be set by Session ID Management
726
- siteId: SITE_ID,
737
+ siteId: getCurrentSiteId(),
727
738
  teamId: null, // May be set externally or from backend
728
739
  userId: null, // Will be set from StorageManager
729
740
 
@@ -1678,7 +1689,9 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
1678
1689
  initialize() {
1679
1690
  // Ensure all required fields exist (some may already be set)
1680
1691
  if (!sessionData.sessionId) sessionData.sessionId = null;
1681
- if (!sessionData.siteId) sessionData.siteId = SITE_ID;
1692
+ // Get current SITE_ID (may have been set via init() after SDK loaded)
1693
+ const currentSiteId = SITE_ID || window.Cryptique?.siteId || window.__CRYPTIQUE_SITE_ID__ || null;
1694
+ if (!sessionData.siteId) sessionData.siteId = currentSiteId;
1682
1695
  if (!sessionData.teamId) sessionData.teamId = null;
1683
1696
  if (!sessionData.userId) sessionData.userId = null;
1684
1697
 
@@ -3786,7 +3799,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
3786
3799
  const transformed = {
3787
3800
  // IDs - only session_id (snake_case), no id (PostgreSQL auto-generates it)
3788
3801
  session_id: sourceData.session_id || sourceData.sessionId,
3789
- site_id: sourceData.site_id || sourceData.siteId || SITE_ID,
3802
+ site_id: sourceData.site_id || sourceData.siteId || getCurrentSiteId() || null,
3790
3803
  team_id: sourceData.team_id || sourceData.teamId || null,
3791
3804
  user_id: sourceData.user_id || sourceData.userId || null,
3792
3805
 
@@ -4106,7 +4119,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4106
4119
  const country = sessionData.locationData?.country || null;
4107
4120
 
4108
4121
  const utmEventPayload = {
4109
- siteId: SITE_ID,
4122
+ siteId: getCurrentSiteId(),
4110
4123
  sessionId: sessionData.sessionId,
4111
4124
  userId: sessionData.userId,
4112
4125
  utm_source: utmData.utm_source,
@@ -5723,7 +5736,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5723
5736
  method: 'POST',
5724
5737
  headers: {
5725
5738
  'Content-Type': 'application/json',
5726
- 'X-Cryptique-Site-Id': SITE_ID
5739
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
5727
5740
  },
5728
5741
  body: JSON.stringify(eventData)
5729
5742
  });
@@ -5858,7 +5871,8 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5858
5871
  return { success: false, error: 'No user ID' };
5859
5872
  }
5860
5873
 
5861
- if (!SITE_ID) {
5874
+ const currentSiteId = getCurrentSiteId();
5875
+ if (!currentSiteId) {
5862
5876
  console.error('❌ [Identity] Site ID not found');
5863
5877
  return { success: false, error: 'Site ID not found' };
5864
5878
  }
@@ -5869,10 +5883,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5869
5883
  method: 'POST',
5870
5884
  headers: {
5871
5885
  'Content-Type': 'application/json',
5872
- 'X-Cryptique-Site-Id': SITE_ID
5886
+ 'X-Cryptique-Site-Id': currentSiteId
5873
5887
  },
5874
5888
  body: JSON.stringify({
5875
- siteId: SITE_ID,
5889
+ siteId: getCurrentSiteId(),
5876
5890
  sessionId: session.id,
5877
5891
  userId: currentUserId,
5878
5892
  identifyId: identifyId.trim()
@@ -5968,10 +5982,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5968
5982
  method: 'POST',
5969
5983
  headers: {
5970
5984
  'Content-Type': 'application/json',
5971
- 'X-Cryptique-Site-Id': SITE_ID
5985
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
5972
5986
  },
5973
5987
  body: JSON.stringify({
5974
- siteId: SITE_ID,
5988
+ siteId: getCurrentSiteId(),
5975
5989
  sessionId: session.id,
5976
5990
  userId: currentUserId,
5977
5991
  walletAddress: trimmedWalletAddress
@@ -6442,10 +6456,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6442
6456
  method: 'POST',
6443
6457
  headers: {
6444
6458
  'Content-Type': 'application/json',
6445
- 'X-Cryptique-Site-Id': SITE_ID
6459
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6446
6460
  },
6447
6461
  body: JSON.stringify({
6448
- siteId: SITE_ID,
6462
+ siteId: getCurrentSiteId(),
6449
6463
  userId: currentUserId,
6450
6464
  properties: properties
6451
6465
  })
@@ -6492,10 +6506,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6492
6506
  method: 'POST',
6493
6507
  headers: {
6494
6508
  'Content-Type': 'application/json',
6495
- 'X-Cryptique-Site-Id': SITE_ID
6509
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6496
6510
  },
6497
6511
  body: JSON.stringify({
6498
- siteId: SITE_ID,
6512
+ siteId: getCurrentSiteId(),
6499
6513
  userId: currentUserId,
6500
6514
  properties: properties
6501
6515
  })
@@ -6542,10 +6556,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6542
6556
  method: 'POST',
6543
6557
  headers: {
6544
6558
  'Content-Type': 'application/json',
6545
- 'X-Cryptique-Site-Id': SITE_ID
6559
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6546
6560
  },
6547
6561
  body: JSON.stringify({
6548
- siteId: SITE_ID,
6562
+ siteId: getCurrentSiteId(),
6549
6563
  userId: currentUserId,
6550
6564
  keys: keys
6551
6565
  })
@@ -6598,10 +6612,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6598
6612
  method: 'POST',
6599
6613
  headers: {
6600
6614
  'Content-Type': 'application/json',
6601
- 'X-Cryptique-Site-Id': SITE_ID
6615
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6602
6616
  },
6603
6617
  body: JSON.stringify({
6604
- siteId: SITE_ID,
6618
+ siteId: getCurrentSiteId(),
6605
6619
  userId: currentUserId,
6606
6620
  key: key,
6607
6621
  amount: amount
@@ -6655,10 +6669,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6655
6669
  method: 'POST',
6656
6670
  headers: {
6657
6671
  'Content-Type': 'application/json',
6658
- 'X-Cryptique-Site-Id': SITE_ID
6672
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6659
6673
  },
6660
6674
  body: JSON.stringify({
6661
- siteId: SITE_ID,
6675
+ siteId: getCurrentSiteId(),
6662
6676
  userId: currentUserId,
6663
6677
  key: key,
6664
6678
  values: values
@@ -6712,10 +6726,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6712
6726
  method: 'POST',
6713
6727
  headers: {
6714
6728
  'Content-Type': 'application/json',
6715
- 'X-Cryptique-Site-Id': SITE_ID
6729
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6716
6730
  },
6717
6731
  body: JSON.stringify({
6718
- siteId: SITE_ID,
6732
+ siteId: getCurrentSiteId(),
6719
6733
  userId: currentUserId,
6720
6734
  key: key,
6721
6735
  values: values
@@ -6769,10 +6783,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6769
6783
  method: 'POST',
6770
6784
  headers: {
6771
6785
  'Content-Type': 'application/json',
6772
- 'X-Cryptique-Site-Id': SITE_ID
6786
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6773
6787
  },
6774
6788
  body: JSON.stringify({
6775
- siteId: SITE_ID,
6789
+ siteId: getCurrentSiteId(),
6776
6790
  userId: currentUserId,
6777
6791
  key: key,
6778
6792
  values: values
@@ -6821,10 +6835,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6821
6835
  method: 'POST',
6822
6836
  headers: {
6823
6837
  'Content-Type': 'application/json',
6824
- 'X-Cryptique-Site-Id': SITE_ID
6838
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6825
6839
  },
6826
6840
  body: JSON.stringify({
6827
- siteId: SITE_ID,
6841
+ siteId: getCurrentSiteId(),
6828
6842
  userId: currentUserId,
6829
6843
  amount: amount,
6830
6844
  properties: properties
@@ -6866,10 +6880,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6866
6880
  method: 'POST',
6867
6881
  headers: {
6868
6882
  'Content-Type': 'application/json',
6869
- 'X-Cryptique-Site-Id': SITE_ID
6883
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6870
6884
  },
6871
6885
  body: JSON.stringify({
6872
- siteId: SITE_ID,
6886
+ siteId: getCurrentSiteId(),
6873
6887
  userId: currentUserId
6874
6888
  })
6875
6889
  });
@@ -6909,10 +6923,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6909
6923
  method: 'POST',
6910
6924
  headers: {
6911
6925
  'Content-Type': 'application/json',
6912
- 'X-Cryptique-Site-Id': SITE_ID
6926
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6913
6927
  },
6914
6928
  body: JSON.stringify({
6915
- siteId: SITE_ID,
6929
+ siteId: getCurrentSiteId(),
6916
6930
  userId: currentUserId
6917
6931
  })
6918
6932
  });
@@ -6983,7 +6997,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6983
6997
 
6984
6998
  // Session Data Access
6985
6999
  sessionData: sessionData,
6986
- siteId: SITE_ID,
7000
+ siteId: getCurrentSiteId(),
6987
7001
  getSessionData: function() {
6988
7002
  return sessionData;
6989
7003
  },
package/lib/esm/index.js CHANGED
@@ -112,7 +112,18 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
112
112
 
113
113
  // Get Site ID from script tag attribute
114
114
  const analyticsScript = document.currentScript || document.querySelector('script[src*="script.js"]') || document.querySelector('script[src*="cryptique"]');
115
- const SITE_ID = analyticsScript ? analyticsScript.getAttribute("site-id") : null;
115
+ let SITE_ID = analyticsScript ? analyticsScript.getAttribute("site-id") : null;
116
+
117
+ // Fallback: Check window.Cryptique.siteId or global variable (for npm usage)
118
+ if (!SITE_ID) {
119
+ SITE_ID = window.Cryptique?.siteId || window.__CRYPTIQUE_SITE_ID__ || null;
120
+ }
121
+
122
+ // Helper function to get current site ID (checks all sources dynamically)
123
+ // This allows site ID to be set via init() after SDK loads
124
+ function getCurrentSiteId() {
125
+ return SITE_ID || window.Cryptique?.siteId || window.__CRYPTIQUE_SITE_ID__ || null;
126
+ }
116
127
 
117
128
  // Parse auto events configuration from script tag attributes
118
129
  // Default: auto events disabled, empty disabled paths array
@@ -721,7 +732,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
721
732
  let sessionData = {
722
733
  // IDs (internal camelCase)
723
734
  sessionId: null, // Will be set by Session ID Management
724
- siteId: SITE_ID,
735
+ siteId: getCurrentSiteId(),
725
736
  teamId: null, // May be set externally or from backend
726
737
  userId: null, // Will be set from StorageManager
727
738
 
@@ -1676,7 +1687,9 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
1676
1687
  initialize() {
1677
1688
  // Ensure all required fields exist (some may already be set)
1678
1689
  if (!sessionData.sessionId) sessionData.sessionId = null;
1679
- if (!sessionData.siteId) sessionData.siteId = SITE_ID;
1690
+ // Get current SITE_ID (may have been set via init() after SDK loaded)
1691
+ const currentSiteId = SITE_ID || window.Cryptique?.siteId || window.__CRYPTIQUE_SITE_ID__ || null;
1692
+ if (!sessionData.siteId) sessionData.siteId = currentSiteId;
1680
1693
  if (!sessionData.teamId) sessionData.teamId = null;
1681
1694
  if (!sessionData.userId) sessionData.userId = null;
1682
1695
 
@@ -3784,7 +3797,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
3784
3797
  const transformed = {
3785
3798
  // IDs - only session_id (snake_case), no id (PostgreSQL auto-generates it)
3786
3799
  session_id: sourceData.session_id || sourceData.sessionId,
3787
- site_id: sourceData.site_id || sourceData.siteId || SITE_ID,
3800
+ site_id: sourceData.site_id || sourceData.siteId || getCurrentSiteId() || null,
3788
3801
  team_id: sourceData.team_id || sourceData.teamId || null,
3789
3802
  user_id: sourceData.user_id || sourceData.userId || null,
3790
3803
 
@@ -4104,7 +4117,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4104
4117
  const country = sessionData.locationData?.country || null;
4105
4118
 
4106
4119
  const utmEventPayload = {
4107
- siteId: SITE_ID,
4120
+ siteId: getCurrentSiteId(),
4108
4121
  sessionId: sessionData.sessionId,
4109
4122
  userId: sessionData.userId,
4110
4123
  utm_source: utmData.utm_source,
@@ -5721,7 +5734,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5721
5734
  method: 'POST',
5722
5735
  headers: {
5723
5736
  'Content-Type': 'application/json',
5724
- 'X-Cryptique-Site-Id': SITE_ID
5737
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
5725
5738
  },
5726
5739
  body: JSON.stringify(eventData)
5727
5740
  });
@@ -5856,7 +5869,8 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5856
5869
  return { success: false, error: 'No user ID' };
5857
5870
  }
5858
5871
 
5859
- if (!SITE_ID) {
5872
+ const currentSiteId = getCurrentSiteId();
5873
+ if (!currentSiteId) {
5860
5874
  console.error('❌ [Identity] Site ID not found');
5861
5875
  return { success: false, error: 'Site ID not found' };
5862
5876
  }
@@ -5867,10 +5881,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5867
5881
  method: 'POST',
5868
5882
  headers: {
5869
5883
  'Content-Type': 'application/json',
5870
- 'X-Cryptique-Site-Id': SITE_ID
5884
+ 'X-Cryptique-Site-Id': currentSiteId
5871
5885
  },
5872
5886
  body: JSON.stringify({
5873
- siteId: SITE_ID,
5887
+ siteId: getCurrentSiteId(),
5874
5888
  sessionId: session.id,
5875
5889
  userId: currentUserId,
5876
5890
  identifyId: identifyId.trim()
@@ -5966,10 +5980,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
5966
5980
  method: 'POST',
5967
5981
  headers: {
5968
5982
  'Content-Type': 'application/json',
5969
- 'X-Cryptique-Site-Id': SITE_ID
5983
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
5970
5984
  },
5971
5985
  body: JSON.stringify({
5972
- siteId: SITE_ID,
5986
+ siteId: getCurrentSiteId(),
5973
5987
  sessionId: session.id,
5974
5988
  userId: currentUserId,
5975
5989
  walletAddress: trimmedWalletAddress
@@ -6440,10 +6454,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6440
6454
  method: 'POST',
6441
6455
  headers: {
6442
6456
  'Content-Type': 'application/json',
6443
- 'X-Cryptique-Site-Id': SITE_ID
6457
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6444
6458
  },
6445
6459
  body: JSON.stringify({
6446
- siteId: SITE_ID,
6460
+ siteId: getCurrentSiteId(),
6447
6461
  userId: currentUserId,
6448
6462
  properties: properties
6449
6463
  })
@@ -6490,10 +6504,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6490
6504
  method: 'POST',
6491
6505
  headers: {
6492
6506
  'Content-Type': 'application/json',
6493
- 'X-Cryptique-Site-Id': SITE_ID
6507
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6494
6508
  },
6495
6509
  body: JSON.stringify({
6496
- siteId: SITE_ID,
6510
+ siteId: getCurrentSiteId(),
6497
6511
  userId: currentUserId,
6498
6512
  properties: properties
6499
6513
  })
@@ -6540,10 +6554,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6540
6554
  method: 'POST',
6541
6555
  headers: {
6542
6556
  'Content-Type': 'application/json',
6543
- 'X-Cryptique-Site-Id': SITE_ID
6557
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6544
6558
  },
6545
6559
  body: JSON.stringify({
6546
- siteId: SITE_ID,
6560
+ siteId: getCurrentSiteId(),
6547
6561
  userId: currentUserId,
6548
6562
  keys: keys
6549
6563
  })
@@ -6596,10 +6610,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6596
6610
  method: 'POST',
6597
6611
  headers: {
6598
6612
  'Content-Type': 'application/json',
6599
- 'X-Cryptique-Site-Id': SITE_ID
6613
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6600
6614
  },
6601
6615
  body: JSON.stringify({
6602
- siteId: SITE_ID,
6616
+ siteId: getCurrentSiteId(),
6603
6617
  userId: currentUserId,
6604
6618
  key: key,
6605
6619
  amount: amount
@@ -6653,10 +6667,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6653
6667
  method: 'POST',
6654
6668
  headers: {
6655
6669
  'Content-Type': 'application/json',
6656
- 'X-Cryptique-Site-Id': SITE_ID
6670
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6657
6671
  },
6658
6672
  body: JSON.stringify({
6659
- siteId: SITE_ID,
6673
+ siteId: getCurrentSiteId(),
6660
6674
  userId: currentUserId,
6661
6675
  key: key,
6662
6676
  values: values
@@ -6710,10 +6724,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6710
6724
  method: 'POST',
6711
6725
  headers: {
6712
6726
  'Content-Type': 'application/json',
6713
- 'X-Cryptique-Site-Id': SITE_ID
6727
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6714
6728
  },
6715
6729
  body: JSON.stringify({
6716
- siteId: SITE_ID,
6730
+ siteId: getCurrentSiteId(),
6717
6731
  userId: currentUserId,
6718
6732
  key: key,
6719
6733
  values: values
@@ -6767,10 +6781,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6767
6781
  method: 'POST',
6768
6782
  headers: {
6769
6783
  'Content-Type': 'application/json',
6770
- 'X-Cryptique-Site-Id': SITE_ID
6784
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6771
6785
  },
6772
6786
  body: JSON.stringify({
6773
- siteId: SITE_ID,
6787
+ siteId: getCurrentSiteId(),
6774
6788
  userId: currentUserId,
6775
6789
  key: key,
6776
6790
  values: values
@@ -6819,10 +6833,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6819
6833
  method: 'POST',
6820
6834
  headers: {
6821
6835
  'Content-Type': 'application/json',
6822
- 'X-Cryptique-Site-Id': SITE_ID
6836
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6823
6837
  },
6824
6838
  body: JSON.stringify({
6825
- siteId: SITE_ID,
6839
+ siteId: getCurrentSiteId(),
6826
6840
  userId: currentUserId,
6827
6841
  amount: amount,
6828
6842
  properties: properties
@@ -6864,10 +6878,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6864
6878
  method: 'POST',
6865
6879
  headers: {
6866
6880
  'Content-Type': 'application/json',
6867
- 'X-Cryptique-Site-Id': SITE_ID
6881
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6868
6882
  },
6869
6883
  body: JSON.stringify({
6870
- siteId: SITE_ID,
6884
+ siteId: getCurrentSiteId(),
6871
6885
  userId: currentUserId
6872
6886
  })
6873
6887
  });
@@ -6907,10 +6921,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6907
6921
  method: 'POST',
6908
6922
  headers: {
6909
6923
  'Content-Type': 'application/json',
6910
- 'X-Cryptique-Site-Id': SITE_ID
6924
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6911
6925
  },
6912
6926
  body: JSON.stringify({
6913
- siteId: SITE_ID,
6927
+ siteId: getCurrentSiteId(),
6914
6928
  userId: currentUserId
6915
6929
  })
6916
6930
  });
@@ -6981,7 +6995,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
6981
6995
 
6982
6996
  // Session Data Access
6983
6997
  sessionData: sessionData,
6984
- siteId: SITE_ID,
6998
+ siteId: getCurrentSiteId(),
6985
6999
  getSessionData: function() {
6986
7000
  return sessionData;
6987
7001
  },
package/lib/umd/index.js CHANGED
@@ -118,7 +118,18 @@
118
118
 
119
119
  // Get Site ID from script tag attribute
120
120
  const analyticsScript = document.currentScript || document.querySelector('script[src*="script.js"]') || document.querySelector('script[src*="cryptique"]');
121
- const SITE_ID = analyticsScript ? analyticsScript.getAttribute("site-id") : null;
121
+ let SITE_ID = analyticsScript ? analyticsScript.getAttribute("site-id") : null;
122
+
123
+ // Fallback: Check window.Cryptique.siteId or global variable (for npm usage)
124
+ if (!SITE_ID) {
125
+ SITE_ID = window.Cryptique?.siteId || window.__CRYPTIQUE_SITE_ID__ || null;
126
+ }
127
+
128
+ // Helper function to get current site ID (checks all sources dynamically)
129
+ // This allows site ID to be set via init() after SDK loads
130
+ function getCurrentSiteId() {
131
+ return SITE_ID || window.Cryptique?.siteId || window.__CRYPTIQUE_SITE_ID__ || null;
132
+ }
122
133
 
123
134
  // Parse auto events configuration from script tag attributes
124
135
  // Default: auto events disabled, empty disabled paths array
@@ -727,7 +738,7 @@
727
738
  let sessionData = {
728
739
  // IDs (internal camelCase)
729
740
  sessionId: null, // Will be set by Session ID Management
730
- siteId: SITE_ID,
741
+ siteId: getCurrentSiteId(),
731
742
  teamId: null, // May be set externally or from backend
732
743
  userId: null, // Will be set from StorageManager
733
744
 
@@ -1682,7 +1693,9 @@
1682
1693
  initialize() {
1683
1694
  // Ensure all required fields exist (some may already be set)
1684
1695
  if (!sessionData.sessionId) sessionData.sessionId = null;
1685
- if (!sessionData.siteId) sessionData.siteId = SITE_ID;
1696
+ // Get current SITE_ID (may have been set via init() after SDK loaded)
1697
+ const currentSiteId = SITE_ID || window.Cryptique?.siteId || window.__CRYPTIQUE_SITE_ID__ || null;
1698
+ if (!sessionData.siteId) sessionData.siteId = currentSiteId;
1686
1699
  if (!sessionData.teamId) sessionData.teamId = null;
1687
1700
  if (!sessionData.userId) sessionData.userId = null;
1688
1701
 
@@ -3790,7 +3803,7 @@
3790
3803
  const transformed = {
3791
3804
  // IDs - only session_id (snake_case), no id (PostgreSQL auto-generates it)
3792
3805
  session_id: sourceData.session_id || sourceData.sessionId,
3793
- site_id: sourceData.site_id || sourceData.siteId || SITE_ID,
3806
+ site_id: sourceData.site_id || sourceData.siteId || getCurrentSiteId() || null,
3794
3807
  team_id: sourceData.team_id || sourceData.teamId || null,
3795
3808
  user_id: sourceData.user_id || sourceData.userId || null,
3796
3809
 
@@ -4110,7 +4123,7 @@
4110
4123
  const country = sessionData.locationData?.country || null;
4111
4124
 
4112
4125
  const utmEventPayload = {
4113
- siteId: SITE_ID,
4126
+ siteId: getCurrentSiteId(),
4114
4127
  sessionId: sessionData.sessionId,
4115
4128
  userId: sessionData.userId,
4116
4129
  utm_source: utmData.utm_source,
@@ -5727,7 +5740,7 @@
5727
5740
  method: 'POST',
5728
5741
  headers: {
5729
5742
  'Content-Type': 'application/json',
5730
- 'X-Cryptique-Site-Id': SITE_ID
5743
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
5731
5744
  },
5732
5745
  body: JSON.stringify(eventData)
5733
5746
  });
@@ -5862,7 +5875,8 @@
5862
5875
  return { success: false, error: 'No user ID' };
5863
5876
  }
5864
5877
 
5865
- if (!SITE_ID) {
5878
+ const currentSiteId = getCurrentSiteId();
5879
+ if (!currentSiteId) {
5866
5880
  console.error('❌ [Identity] Site ID not found');
5867
5881
  return { success: false, error: 'Site ID not found' };
5868
5882
  }
@@ -5873,10 +5887,10 @@
5873
5887
  method: 'POST',
5874
5888
  headers: {
5875
5889
  'Content-Type': 'application/json',
5876
- 'X-Cryptique-Site-Id': SITE_ID
5890
+ 'X-Cryptique-Site-Id': currentSiteId
5877
5891
  },
5878
5892
  body: JSON.stringify({
5879
- siteId: SITE_ID,
5893
+ siteId: getCurrentSiteId(),
5880
5894
  sessionId: session.id,
5881
5895
  userId: currentUserId,
5882
5896
  identifyId: identifyId.trim()
@@ -5972,10 +5986,10 @@
5972
5986
  method: 'POST',
5973
5987
  headers: {
5974
5988
  'Content-Type': 'application/json',
5975
- 'X-Cryptique-Site-Id': SITE_ID
5989
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
5976
5990
  },
5977
5991
  body: JSON.stringify({
5978
- siteId: SITE_ID,
5992
+ siteId: getCurrentSiteId(),
5979
5993
  sessionId: session.id,
5980
5994
  userId: currentUserId,
5981
5995
  walletAddress: trimmedWalletAddress
@@ -6446,10 +6460,10 @@
6446
6460
  method: 'POST',
6447
6461
  headers: {
6448
6462
  'Content-Type': 'application/json',
6449
- 'X-Cryptique-Site-Id': SITE_ID
6463
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6450
6464
  },
6451
6465
  body: JSON.stringify({
6452
- siteId: SITE_ID,
6466
+ siteId: getCurrentSiteId(),
6453
6467
  userId: currentUserId,
6454
6468
  properties: properties
6455
6469
  })
@@ -6496,10 +6510,10 @@
6496
6510
  method: 'POST',
6497
6511
  headers: {
6498
6512
  'Content-Type': 'application/json',
6499
- 'X-Cryptique-Site-Id': SITE_ID
6513
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6500
6514
  },
6501
6515
  body: JSON.stringify({
6502
- siteId: SITE_ID,
6516
+ siteId: getCurrentSiteId(),
6503
6517
  userId: currentUserId,
6504
6518
  properties: properties
6505
6519
  })
@@ -6546,10 +6560,10 @@
6546
6560
  method: 'POST',
6547
6561
  headers: {
6548
6562
  'Content-Type': 'application/json',
6549
- 'X-Cryptique-Site-Id': SITE_ID
6563
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6550
6564
  },
6551
6565
  body: JSON.stringify({
6552
- siteId: SITE_ID,
6566
+ siteId: getCurrentSiteId(),
6553
6567
  userId: currentUserId,
6554
6568
  keys: keys
6555
6569
  })
@@ -6602,10 +6616,10 @@
6602
6616
  method: 'POST',
6603
6617
  headers: {
6604
6618
  'Content-Type': 'application/json',
6605
- 'X-Cryptique-Site-Id': SITE_ID
6619
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6606
6620
  },
6607
6621
  body: JSON.stringify({
6608
- siteId: SITE_ID,
6622
+ siteId: getCurrentSiteId(),
6609
6623
  userId: currentUserId,
6610
6624
  key: key,
6611
6625
  amount: amount
@@ -6659,10 +6673,10 @@
6659
6673
  method: 'POST',
6660
6674
  headers: {
6661
6675
  'Content-Type': 'application/json',
6662
- 'X-Cryptique-Site-Id': SITE_ID
6676
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6663
6677
  },
6664
6678
  body: JSON.stringify({
6665
- siteId: SITE_ID,
6679
+ siteId: getCurrentSiteId(),
6666
6680
  userId: currentUserId,
6667
6681
  key: key,
6668
6682
  values: values
@@ -6716,10 +6730,10 @@
6716
6730
  method: 'POST',
6717
6731
  headers: {
6718
6732
  'Content-Type': 'application/json',
6719
- 'X-Cryptique-Site-Id': SITE_ID
6733
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6720
6734
  },
6721
6735
  body: JSON.stringify({
6722
- siteId: SITE_ID,
6736
+ siteId: getCurrentSiteId(),
6723
6737
  userId: currentUserId,
6724
6738
  key: key,
6725
6739
  values: values
@@ -6773,10 +6787,10 @@
6773
6787
  method: 'POST',
6774
6788
  headers: {
6775
6789
  'Content-Type': 'application/json',
6776
- 'X-Cryptique-Site-Id': SITE_ID
6790
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6777
6791
  },
6778
6792
  body: JSON.stringify({
6779
- siteId: SITE_ID,
6793
+ siteId: getCurrentSiteId(),
6780
6794
  userId: currentUserId,
6781
6795
  key: key,
6782
6796
  values: values
@@ -6825,10 +6839,10 @@
6825
6839
  method: 'POST',
6826
6840
  headers: {
6827
6841
  'Content-Type': 'application/json',
6828
- 'X-Cryptique-Site-Id': SITE_ID
6842
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6829
6843
  },
6830
6844
  body: JSON.stringify({
6831
- siteId: SITE_ID,
6845
+ siteId: getCurrentSiteId(),
6832
6846
  userId: currentUserId,
6833
6847
  amount: amount,
6834
6848
  properties: properties
@@ -6870,10 +6884,10 @@
6870
6884
  method: 'POST',
6871
6885
  headers: {
6872
6886
  'Content-Type': 'application/json',
6873
- 'X-Cryptique-Site-Id': SITE_ID
6887
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6874
6888
  },
6875
6889
  body: JSON.stringify({
6876
- siteId: SITE_ID,
6890
+ siteId: getCurrentSiteId(),
6877
6891
  userId: currentUserId
6878
6892
  })
6879
6893
  });
@@ -6913,10 +6927,10 @@
6913
6927
  method: 'POST',
6914
6928
  headers: {
6915
6929
  'Content-Type': 'application/json',
6916
- 'X-Cryptique-Site-Id': SITE_ID
6930
+ 'X-Cryptique-Site-Id': getCurrentSiteId()
6917
6931
  },
6918
6932
  body: JSON.stringify({
6919
- siteId: SITE_ID,
6933
+ siteId: getCurrentSiteId(),
6920
6934
  userId: currentUserId
6921
6935
  })
6922
6936
  });
@@ -6987,7 +7001,7 @@
6987
7001
 
6988
7002
  // Session Data Access
6989
7003
  sessionData: sessionData,
6990
- siteId: SITE_ID,
7004
+ siteId: getCurrentSiteId(),
6991
7005
  getSessionData: function() {
6992
7006
  return sessionData;
6993
7007
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cryptique-sdk",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "description": "Cryptique Analytics SDK - Comprehensive web analytics and user tracking for modern web applications",
6
6
  "main": "lib/cjs/index.js",