cryptique-sdk 1.2.23 → 1.2.24

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/esm/index.js CHANGED
@@ -8170,6 +8170,12 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
8170
8170
  },
8171
8171
  delete() {
8172
8172
  return mgr._profileCall('delete', groupKey, groupId, {});
8173
+ },
8174
+ increment(property, value = 1) {
8175
+ return mgr._profileCall('increment', groupKey, groupId, { property, value });
8176
+ },
8177
+ append(property, value) {
8178
+ return mgr._profileCall('append', groupKey, groupId, { property, value });
8173
8179
  }
8174
8180
  };
8175
8181
  },
@@ -8472,620 +8478,624 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
8472
8478
 
8473
8479
  }
8474
8480
 
8475
- /**
8476
- * Cryptique Analytics SDK - NPM Module Entry Point
8477
- *
8478
- * This is a thin wrapper around script/script.js that exports the SDK
8479
- * as a module for npm usage. All functionality remains in script.js.
8480
- *
8481
- * The script.js file is inlined during the build process by Rollup.
8482
- */
8483
-
8484
-
8485
- // Create a wrapper that provides programmatic initialization
8486
- const CryptiqueSDK = {
8487
- /**
8488
- * Initialize the SDK programmatically
8489
- * @param {Object} options - Configuration options
8490
- * @param {string} options.siteId - Site ID (required)
8491
- * @param {boolean} [options.autoEvents] - Enable auto events (default: false)
8492
- * @param {string[]} [options.disabledPaths] - Paths to disable auto events
8493
- * @param {string[]} [options.disabledEvents] - Auto events to disable
8494
- */
8495
- init(options = {}) {
8496
- if (typeof window === 'undefined') {
8497
- console.warn('Cryptique SDK requires a browser environment');
8498
- return Promise.resolve(null);
8499
- }
8500
-
8501
- if (!options.siteId) {
8502
- throw new Error('siteId is required');
8503
- }
8504
-
8505
- // Wait for SDK to be available on window
8506
- const checkSDK = () => {
8507
- if (window.Cryptique) {
8508
- // Set site ID
8509
- window.Cryptique.siteId = options.siteId;
8510
-
8511
- // Configure auto events if provided
8512
- if (options.autoEvents !== undefined) {
8513
- if (options.autoEvents) {
8514
- window.Cryptique.enableAutoEvents();
8515
- } else {
8516
- window.Cryptique.disableAutoEvents();
8517
- }
8518
- }
8519
-
8520
- // Set disabled paths if provided
8521
- if (options.disabledPaths) {
8522
- if (window.Cryptique.setAutoEventsDisabledPaths) {
8523
- window.Cryptique.setAutoEventsDisabledPaths(options.disabledPaths);
8524
- }
8525
- }
8526
-
8527
- // Set disabled events if provided
8528
- if (options.disabledEvents) {
8529
- if (window.Cryptique.setAutoEventsDisabledEvents) {
8530
- window.Cryptique.setAutoEventsDisabledEvents(options.disabledEvents);
8531
- }
8532
- }
8533
-
8534
- return window.Cryptique;
8535
- }
8536
- return null;
8537
- };
8538
-
8539
- // If SDK is already loaded, configure and return ready promise
8540
- if (window.Cryptique) {
8541
- checkSDK();
8542
- // Return ready() so await Cryptique.init() waits for full initialization
8543
- return window.Cryptique.ready ? window.Cryptique.ready() : Promise.resolve(window.Cryptique);
8544
- }
8545
-
8546
- // Otherwise, wait for SDK to load then configure and wait for ready
8547
- return new Promise((resolve) => {
8548
- const maxAttempts = 50;
8549
- let attempts = 0;
8550
- const interval = setInterval(() => {
8551
- attempts++;
8552
- const sdk = checkSDK();
8553
- if (sdk) {
8554
- clearInterval(interval);
8555
- // Wait for full initialization
8556
- const readyPromise = sdk.ready ? sdk.ready() : Promise.resolve(sdk);
8557
- resolve(readyPromise);
8558
- } else if (attempts >= maxAttempts) {
8559
- clearInterval(interval);
8560
- resolve(null);
8561
- }
8562
- }, 100);
8563
- });
8564
- },
8565
-
8566
- /**
8567
- * Get the SDK instance
8568
- * Returns window.Cryptique if available
8569
- */
8570
- getInstance() {
8571
- if (typeof window !== 'undefined' && window.Cryptique) {
8572
- return window.Cryptique;
8573
- }
8574
- return null;
8575
- },
8576
-
8577
- /**
8578
- * Wait for SDK to be fully initialized
8579
- * Returns a Promise that resolves when initialization is complete
8580
- * @returns {Promise<void>}
8581
- */
8582
- ready() {
8583
- const instance = this.getInstance();
8584
- if (instance && instance.ready) {
8585
- return instance.ready();
8586
- }
8587
- return Promise.resolve();
8588
- },
8589
-
8590
- /**
8591
- * Identify a user with a unique identifier
8592
- *
8593
- * When called, checks if this identify_id exists for another user.
8594
- * If found, merges the current user_id with the existing user_id.
8595
- *
8596
- * @param {string} identifyId - Unique identifier for the user
8597
- * @returns {Promise<Object>} Result object with merged status and new userId
8598
- */
8599
- async identify(identifyId) {
8600
- const instance = this.getInstance();
8601
- if (instance && instance.identify) {
8602
- return await instance.identify(identifyId);
8603
- }
8604
- throw new Error('SDK not initialized. Call init() first.');
8605
- },
8606
-
8607
- /**
8608
- * Set wallet address for current user
8609
- *
8610
- * If wallet address already exists for another user, merges identities.
8611
- * Otherwise, sets wallet address for current user.
8612
- *
8613
- * @param {string} walletAddress - Wallet address to set
8614
- * @returns {Promise<Object>} Result object with merged status and new userId
8615
- */
8616
- async walletAddress(walletAddress) {
8617
- const instance = this.getInstance();
8618
- if (instance && instance.walletAddress) {
8619
- return await instance.walletAddress(walletAddress);
8620
- }
8621
- throw new Error('SDK not initialized. Call init() first.');
8622
- },
8623
-
8624
- /**
8625
- * Reset user identity to anonymous
8626
- *
8627
- * Generates a new anonymous distinct_id and clears identification.
8628
- * Useful for privacy/GDPR compliance when user wants to reset their identity.
8629
- *
8630
- * @returns {Promise<Object>} Result object with success status and new distinctId
8631
- */
8632
- async reset() {
8633
- const instance = this.getInstance();
8634
- if (instance && instance.reset) {
8635
- return await instance.reset();
8636
- }
8637
- throw new Error('SDK not initialized. Call init() first.');
8638
- },
8639
-
8640
- /**
8641
- * Track a custom event
8642
- * @param {string} eventName - Name of the event
8643
- * @param {Object} [properties] - Event properties
8644
- * @param {Object} [options] - Event options
8645
- * @returns {Promise<void>}
8646
- */
8647
- async track(eventName, properties, options) {
8648
- const instance = this.getInstance();
8649
- if (instance && instance.track) {
8650
- return await instance.track(eventName, properties, options);
8651
- }
8652
- throw new Error('SDK not initialized. Call init() first.');
8653
- },
8654
-
8655
- /**
8656
- * Track a custom event (alias for track)
8657
- * @param {string} eventName - Name of the event
8658
- * @param {Object} [properties] - Event properties
8659
- * @param {Object} [options] - Event options
8660
- * @returns {Promise<void>}
8661
- */
8662
- async trackEvent(eventName, properties, options) {
8663
- const instance = this.getInstance();
8664
- if (instance && instance.trackEvent) {
8665
- return await instance.trackEvent(eventName, properties, options);
8666
- }
8667
- throw new Error('SDK not initialized. Call init() first.');
8668
- },
8669
-
8670
- /**
8671
- * Track an auto event
8672
- * @param {string} eventName - Name of the auto event
8673
- * @param {Object} [autoEventData] - Auto event data
8674
- * @param {Object} [elementData] - Element data
8675
- * @returns {Promise<void>}
8676
- */
8677
- async trackAutoEvent(eventName, autoEventData, elementData) {
8678
- const instance = this.getInstance();
8679
- if (instance && instance.trackAutoEvent) {
8680
- return await instance.trackAutoEvent(eventName, autoEventData, elementData);
8681
- }
8682
- throw new Error('SDK not initialized. Call init() first.');
8683
- },
8684
-
8685
- /**
8686
- * Connect wallet
8687
- * @returns {Promise<string|null>} Wallet address or null
8688
- */
8689
- async connectWallet() {
8690
- const instance = this.getInstance();
8691
- if (instance && instance.connectWallet) {
8692
- return await instance.connectWallet();
8693
- }
8694
- throw new Error('SDK not initialized. Call init() first.');
8695
- },
8696
-
8697
- /**
8698
- * Check if wallet is connected
8699
- * @returns {Promise<boolean>}
8700
- */
8701
- async isWalletConnected() {
8702
- const instance = this.getInstance();
8703
- if (instance && instance.isWalletConnected) {
8704
- return await instance.isWalletConnected();
8705
- }
8706
- throw new Error('SDK not initialized. Call init() first.');
8707
- },
8708
-
8709
- /**
8710
- * Update wallet info
8711
- * @returns {Promise<any>}
8712
- */
8713
- async updateWalletInfo() {
8714
- const instance = this.getInstance();
8715
- if (instance && instance.updateWalletInfo) {
8716
- return await instance.updateWalletInfo();
8717
- }
8718
- throw new Error('SDK not initialized. Call init() first.');
8719
- },
8720
-
8721
- /**
8722
- * Set tracking consent
8723
- * @param {boolean} consent - Consent value
8724
- */
8725
- setTrackingConsent(consent) {
8726
- const instance = this.getInstance();
8727
- if (instance && instance.setTrackingConsent) {
8728
- return instance.setTrackingConsent(consent);
8729
- }
8730
- throw new Error('SDK not initialized. Call init() first.');
8731
- },
8732
-
8733
- /**
8734
- * Get tracking consent
8735
- * @returns {boolean}
8736
- */
8737
- getTrackingConsent() {
8738
- const instance = this.getInstance();
8739
- if (instance && instance.getTrackingConsent) {
8740
- return instance.getTrackingConsent();
8741
- }
8742
- return false;
8743
- },
8744
-
8745
- /**
8746
- * Get session data
8747
- * @returns {Object}
8748
- */
8749
- getSessionData() {
8750
- const instance = this.getInstance();
8751
- if (instance && instance.getSessionData) {
8752
- return instance.getSessionData();
8753
- }
8754
- return null;
8755
- },
8756
-
8757
- /**
8758
- * Get chronological interactions
8759
- * @returns {Array}
8760
- */
8761
- getChronologicalInteractions() {
8762
- const instance = this.getInstance();
8763
- if (instance && instance.getChronologicalInteractions) {
8764
- return instance.getChronologicalInteractions();
8765
- }
8766
- return [];
8767
- },
8768
-
8769
- /**
8770
- * Sort interactions chronologically (alias)
8771
- * @returns {Array}
8772
- */
8773
- sortInteractionsChronologically() {
8774
- const instance = this.getInstance();
8775
- if (instance && instance.sortInteractionsChronologically) {
8776
- return instance.sortInteractionsChronologically();
8777
- }
8778
- return [];
8779
- },
8780
-
8781
- /**
8782
- * Enable auto events
8783
- */
8784
- enableAutoEvents() {
8785
- const instance = this.getInstance();
8786
- if (instance && instance.enableAutoEvents) {
8787
- return instance.enableAutoEvents();
8788
- }
8789
- },
8790
-
8791
- /**
8792
- * Disable auto events
8793
- */
8794
- disableAutoEvents() {
8795
- const instance = this.getInstance();
8796
- if (instance && instance.disableAutoEvents) {
8797
- return instance.disableAutoEvents();
8798
- }
8799
- },
8800
-
8801
- /**
8802
- * Set auto events disabled paths
8803
- * @param {string|string[]} paths - Paths to disable
8804
- */
8805
- setAutoEventsDisabledPaths(paths) {
8806
- const instance = this.getInstance();
8807
- if (instance && instance.setAutoEventsDisabledPaths) {
8808
- return instance.setAutoEventsDisabledPaths(paths);
8809
- }
8810
- },
8811
-
8812
- /**
8813
- * Disable specific auto events
8814
- * @param {string|string[]} events - Event name(s) to disable
8815
- */
8816
- disableAutoEvent(events) {
8817
- const instance = this.getInstance();
8818
- if (instance && instance.disableAutoEvent) {
8819
- return instance.disableAutoEvent(events);
8820
- }
8821
- },
8822
-
8823
- /**
8824
- * Enable specific auto events
8825
- * @param {string|string[]} events - Event name(s) to enable
8826
- */
8827
- enableAutoEvent(events) {
8828
- const instance = this.getInstance();
8829
- if (instance && instance.enableAutoEvent) {
8830
- return instance.enableAutoEvent(events);
8831
- }
8832
- },
8833
-
8834
- /**
8835
- * Set auto events disabled events
8836
- * @param {string[]} events - Array of event names to disable
8837
- */
8838
- setAutoEventsDisabledEvents(events) {
8839
- const instance = this.getInstance();
8840
- if (instance && instance.setAutoEventsDisabledEvents) {
8841
- return instance.setAutoEventsDisabledEvents(events);
8842
- }
8843
- },
8844
-
8845
- /**
8846
- * Get available auto events
8847
- * @returns {string[]}
8848
- */
8849
- getAvailableAutoEvents() {
8850
- const instance = this.getInstance();
8851
- if (instance && instance.getAvailableAutoEvents) {
8852
- return instance.getAvailableAutoEvents();
8853
- }
8854
- return [];
8855
- },
8856
-
8857
- /**
8858
- * Get auto events configuration
8859
- * @returns {Object}
8860
- */
8861
- getAutoEventsConfig() {
8862
- const instance = this.getInstance();
8863
- if (instance && instance.getAutoEventsConfig) {
8864
- return instance.getAutoEventsConfig();
8865
- }
8866
- return null;
8867
- },
8868
-
8869
- /**
8870
- * People object for managing user properties
8871
- */
8872
- get people() {
8873
- const instance = this.getInstance();
8874
- if (instance && instance.people) {
8875
- return instance.people;
8876
- }
8877
- // Return a stub object that will work once SDK is initialized
8878
- return {
8879
- set: async (properties) => {
8880
- const inst = this.getInstance();
8881
- if (inst && inst.people && inst.people.set) {
8882
- return await inst.people.set(properties);
8883
- }
8884
- throw new Error('SDK not initialized. Call init() first.');
8885
- },
8886
- setOnce: async (properties) => {
8887
- const inst = this.getInstance();
8888
- if (inst && inst.people && inst.people.setOnce) {
8889
- return await inst.people.setOnce(properties);
8890
- }
8891
- throw new Error('SDK not initialized. Call init() first.');
8892
- },
8893
- unset: async (properties) => {
8894
- const inst = this.getInstance();
8895
- if (inst && inst.people && inst.people.unset) {
8896
- return await inst.people.unset(properties);
8897
- }
8898
- throw new Error('SDK not initialized. Call init() first.');
8899
- },
8900
- increment: async (properties) => {
8901
- const inst = this.getInstance();
8902
- if (inst && inst.people && inst.people.increment) {
8903
- return await inst.people.increment(properties);
8904
- }
8905
- throw new Error('SDK not initialized. Call init() first.');
8906
- },
8907
- append: async (properties) => {
8908
- const inst = this.getInstance();
8909
- if (inst && inst.people && inst.people.append) {
8910
- return await inst.people.append(properties);
8911
- }
8912
- throw new Error('SDK not initialized. Call init() first.');
8913
- },
8914
- union: async (properties) => {
8915
- const inst = this.getInstance();
8916
- if (inst && inst.people && inst.people.union) {
8917
- return await inst.people.union(properties);
8918
- }
8919
- throw new Error('SDK not initialized. Call init() first.');
8920
- },
8921
- remove: async (properties) => {
8922
- const inst = this.getInstance();
8923
- if (inst && inst.people && inst.people.remove) {
8924
- return await inst.people.remove(properties);
8925
- }
8926
- throw new Error('SDK not initialized. Call init() first.');
8927
- },
8928
- trackCharge: async (amount, properties) => {
8929
- const inst = this.getInstance();
8930
- if (inst && inst.people && inst.people.trackCharge) {
8931
- return await inst.people.trackCharge(amount, properties);
8932
- }
8933
- throw new Error('SDK not initialized. Call init() first.');
8934
- },
8935
- clearCharges: async () => {
8936
- const inst = this.getInstance();
8937
- if (inst && inst.people && inst.people.clearCharges) {
8938
- return await inst.people.clearCharges();
8939
- }
8940
- throw new Error('SDK not initialized. Call init() first.');
8941
- },
8942
- deleteUser: async () => {
8943
- const inst = this.getInstance();
8944
- if (inst && inst.people && inst.people.deleteUser) {
8945
- return await inst.people.deleteUser();
8946
- }
8947
- throw new Error('SDK not initialized. Call init() first.');
8948
- }
8949
- };
8950
- },
8951
-
8952
- // -------------------------------------------------------------------------
8953
- // Group Methods
8954
- // -------------------------------------------------------------------------
8955
-
8956
- /**
8957
- * Set (overwrite) the user's group membership for a given key.
8958
- * @param {string} groupKey - The group type key (e.g. 'company_id')
8959
- * @param {string|string[]} groupId - The group ID(s) to assign
8960
- * @returns {Promise<Object>}
8961
- */
8962
- async set_group(groupKey, groupId) {
8963
- const instance = this.getInstance();
8964
- if (instance && instance.set_group) {
8965
- return await instance.set_group(groupKey, groupId);
8966
- }
8967
- throw new Error('SDK not initialized. Call init() first.');
8968
- },
8969
-
8970
- /**
8971
- * Add a group ID to an existing group key without removing current memberships.
8972
- * @param {string} groupKey - The group type key (e.g. 'company_id')
8973
- * @param {string} groupId - The single group ID to add
8974
- * @returns {Promise<Object>}
8975
- */
8976
- async add_group(groupKey, groupId) {
8977
- const instance = this.getInstance();
8978
- if (instance && instance.add_group) {
8979
- return await instance.add_group(groupKey, groupId);
8980
- }
8981
- throw new Error('SDK not initialized. Call init() first.');
8982
- },
8983
-
8984
- /**
8985
- * Remove a specific group ID from the user's group membership.
8986
- * @param {string} groupKey - The group type key (e.g. 'company_id')
8987
- * @param {string} groupId - The group ID to remove
8988
- * @returns {Promise<Object>}
8989
- */
8990
- async remove_group(groupKey, groupId) {
8991
- const instance = this.getInstance();
8992
- if (instance && instance.remove_group) {
8993
- return await instance.remove_group(groupKey, groupId);
8994
- }
8995
- throw new Error('SDK not initialized. Call init() first.');
8996
- },
8997
-
8998
- /**
8999
- * Get a group profile reference object for performing profile operations.
9000
- *
9001
- * Returns a synchronous object with the following methods:
9002
- * .set(properties) – Set group profile properties
9003
- * .set_once(properties) – Set properties only if not already set
9004
- * .union(listName, values) – Add values to a list property (no duplicates)
9005
- * .remove(listName, value) – Remove a value from a list property
9006
- * .unset(property) – Remove a property from the group profile
9007
- * .delete() Delete the entire group profile
9008
- *
9009
- * @param {string} groupKey - The group type key (e.g. 'company_id')
9010
- * @param {string} groupId - The specific group ID
9011
- * @returns {Object} Group profile reference object
9012
- *
9013
- * @example
9014
- * const group = Cryptique.get_group('company', 'acme-corp');
9015
- * await group.set({ plan: 'enterprise', employees: 500 });
9016
- * await group.set_once({ created_at: new Date().toISOString() });
9017
- * await group.union('tags', ['b2b', 'saas']);
9018
- * await group.unset('old_property');
9019
- * await group.delete();
9020
- */
9021
- get_group(groupKey, groupId) {
9022
- const instance = this.getInstance();
9023
- if (instance && instance.get_group) {
9024
- return instance.get_group(groupKey, groupId);
9025
- }
9026
- // Return a stub whose methods all throw if SDK not yet ready
9027
- const notReady = () => { throw new Error('SDK not initialized. Call init() first.'); };
9028
- return {
9029
- set: notReady,
9030
- set_once: notReady,
9031
- union: notReady,
9032
- remove: notReady,
9033
- unset: notReady,
9034
- delete: notReady
9035
- };
9036
- }
9037
- };
9038
-
9039
- // Proxy all methods from window.Cryptique to our export
9040
- // This will be populated after script.js loads
9041
- // Also sync properties that might not be methods
9042
- const syncMethods = () => {
9043
- if (typeof window !== 'undefined' && window.Cryptique) {
9044
- Object.keys(window.Cryptique).forEach(key => {
9045
- // Skip if we already have a custom implementation
9046
- if (['people', 'set_group', 'add_group', 'remove_group', 'get_group'].includes(key) || CryptiqueSDK.hasOwnProperty(key)) {
9047
- return;
9048
- }
9049
-
9050
- if (typeof window.Cryptique[key] === 'function') {
9051
- CryptiqueSDK[key] = window.Cryptique[key].bind(window.Cryptique);
9052
- } else {
9053
- CryptiqueSDK[key] = window.Cryptique[key];
9054
- }
9055
- });
9056
-
9057
- // Sync version and siteId properties
9058
- if (window.Cryptique.version) {
9059
- CryptiqueSDK.version = window.Cryptique.version;
9060
- }
9061
- if (window.Cryptique.siteId) {
9062
- CryptiqueSDK.siteId = window.Cryptique.siteId;
9063
- }
9064
- if (window.Cryptique.sessionData) {
9065
- CryptiqueSDK.sessionData = window.Cryptique.sessionData;
9066
- }
9067
- }
9068
- };
9069
-
9070
- // Try to sync immediately if SDK is already loaded
9071
- if (typeof window !== 'undefined') {
9072
- syncMethods();
9073
-
9074
- // Also sync after DOM loads (in case script loads async)
9075
- if (window.addEventListener) {
9076
- window.addEventListener('load', syncMethods);
9077
- if (document.readyState === 'loading') {
9078
- document.addEventListener('DOMContentLoaded', syncMethods);
9079
- } else {
9080
- syncMethods();
9081
- }
9082
- }
9083
- }
9084
-
9085
- // Export for CommonJS
9086
- if (typeof module !== 'undefined' && module.exports) {
9087
- module.exports = CryptiqueSDK;
9088
- module.exports.default = CryptiqueSDK;
8481
+ /**
8482
+ * Cryptique Analytics SDK - NPM Module Entry Point
8483
+ *
8484
+ * This is a thin wrapper around script/script.js that exports the SDK
8485
+ * as a module for npm usage. All functionality remains in script.js.
8486
+ *
8487
+ * The script.js file is inlined during the build process by Rollup.
8488
+ */
8489
+
8490
+
8491
+ // Create a wrapper that provides programmatic initialization
8492
+ const CryptiqueSDK = {
8493
+ /**
8494
+ * Initialize the SDK programmatically
8495
+ * @param {Object} options - Configuration options
8496
+ * @param {string} options.siteId - Site ID (required)
8497
+ * @param {boolean} [options.autoEvents] - Enable auto events (default: false)
8498
+ * @param {string[]} [options.disabledPaths] - Paths to disable auto events
8499
+ * @param {string[]} [options.disabledEvents] - Auto events to disable
8500
+ */
8501
+ init(options = {}) {
8502
+ if (typeof window === 'undefined') {
8503
+ console.warn('Cryptique SDK requires a browser environment');
8504
+ return Promise.resolve(null);
8505
+ }
8506
+
8507
+ if (!options.siteId) {
8508
+ throw new Error('siteId is required');
8509
+ }
8510
+
8511
+ // Wait for SDK to be available on window
8512
+ const checkSDK = () => {
8513
+ if (window.Cryptique) {
8514
+ // Set site ID
8515
+ window.Cryptique.siteId = options.siteId;
8516
+
8517
+ // Configure auto events if provided
8518
+ if (options.autoEvents !== undefined) {
8519
+ if (options.autoEvents) {
8520
+ window.Cryptique.enableAutoEvents();
8521
+ } else {
8522
+ window.Cryptique.disableAutoEvents();
8523
+ }
8524
+ }
8525
+
8526
+ // Set disabled paths if provided
8527
+ if (options.disabledPaths) {
8528
+ if (window.Cryptique.setAutoEventsDisabledPaths) {
8529
+ window.Cryptique.setAutoEventsDisabledPaths(options.disabledPaths);
8530
+ }
8531
+ }
8532
+
8533
+ // Set disabled events if provided
8534
+ if (options.disabledEvents) {
8535
+ if (window.Cryptique.setAutoEventsDisabledEvents) {
8536
+ window.Cryptique.setAutoEventsDisabledEvents(options.disabledEvents);
8537
+ }
8538
+ }
8539
+
8540
+ return window.Cryptique;
8541
+ }
8542
+ return null;
8543
+ };
8544
+
8545
+ // If SDK is already loaded, configure and return ready promise
8546
+ if (window.Cryptique) {
8547
+ checkSDK();
8548
+ // Return ready() so await Cryptique.init() waits for full initialization
8549
+ return window.Cryptique.ready ? window.Cryptique.ready() : Promise.resolve(window.Cryptique);
8550
+ }
8551
+
8552
+ // Otherwise, wait for SDK to load then configure and wait for ready
8553
+ return new Promise((resolve) => {
8554
+ const maxAttempts = 50;
8555
+ let attempts = 0;
8556
+ const interval = setInterval(() => {
8557
+ attempts++;
8558
+ const sdk = checkSDK();
8559
+ if (sdk) {
8560
+ clearInterval(interval);
8561
+ // Wait for full initialization
8562
+ const readyPromise = sdk.ready ? sdk.ready() : Promise.resolve(sdk);
8563
+ resolve(readyPromise);
8564
+ } else if (attempts >= maxAttempts) {
8565
+ clearInterval(interval);
8566
+ resolve(null);
8567
+ }
8568
+ }, 100);
8569
+ });
8570
+ },
8571
+
8572
+ /**
8573
+ * Get the SDK instance
8574
+ * Returns window.Cryptique if available
8575
+ */
8576
+ getInstance() {
8577
+ if (typeof window !== 'undefined' && window.Cryptique) {
8578
+ return window.Cryptique;
8579
+ }
8580
+ return null;
8581
+ },
8582
+
8583
+ /**
8584
+ * Wait for SDK to be fully initialized
8585
+ * Returns a Promise that resolves when initialization is complete
8586
+ * @returns {Promise<void>}
8587
+ */
8588
+ ready() {
8589
+ const instance = this.getInstance();
8590
+ if (instance && instance.ready) {
8591
+ return instance.ready();
8592
+ }
8593
+ return Promise.resolve();
8594
+ },
8595
+
8596
+ /**
8597
+ * Identify a user with a unique identifier
8598
+ *
8599
+ * When called, checks if this identify_id exists for another user.
8600
+ * If found, merges the current user_id with the existing user_id.
8601
+ *
8602
+ * @param {string} identifyId - Unique identifier for the user
8603
+ * @returns {Promise<Object>} Result object with merged status and new userId
8604
+ */
8605
+ async identify(identifyId) {
8606
+ const instance = this.getInstance();
8607
+ if (instance && instance.identify) {
8608
+ return await instance.identify(identifyId);
8609
+ }
8610
+ throw new Error('SDK not initialized. Call init() first.');
8611
+ },
8612
+
8613
+ /**
8614
+ * Set wallet address for current user
8615
+ *
8616
+ * If wallet address already exists for another user, merges identities.
8617
+ * Otherwise, sets wallet address for current user.
8618
+ *
8619
+ * @param {string} walletAddress - Wallet address to set
8620
+ * @returns {Promise<Object>} Result object with merged status and new userId
8621
+ */
8622
+ async walletAddress(walletAddress) {
8623
+ const instance = this.getInstance();
8624
+ if (instance && instance.walletAddress) {
8625
+ return await instance.walletAddress(walletAddress);
8626
+ }
8627
+ throw new Error('SDK not initialized. Call init() first.');
8628
+ },
8629
+
8630
+ /**
8631
+ * Reset user identity to anonymous
8632
+ *
8633
+ * Generates a new anonymous distinct_id and clears identification.
8634
+ * Useful for privacy/GDPR compliance when user wants to reset their identity.
8635
+ *
8636
+ * @returns {Promise<Object>} Result object with success status and new distinctId
8637
+ */
8638
+ async reset() {
8639
+ const instance = this.getInstance();
8640
+ if (instance && instance.reset) {
8641
+ return await instance.reset();
8642
+ }
8643
+ throw new Error('SDK not initialized. Call init() first.');
8644
+ },
8645
+
8646
+ /**
8647
+ * Track a custom event
8648
+ * @param {string} eventName - Name of the event
8649
+ * @param {Object} [properties] - Event properties
8650
+ * @param {Object} [options] - Event options
8651
+ * @returns {Promise<void>}
8652
+ */
8653
+ async track(eventName, properties, options) {
8654
+ const instance = this.getInstance();
8655
+ if (instance && instance.track) {
8656
+ return await instance.track(eventName, properties, options);
8657
+ }
8658
+ throw new Error('SDK not initialized. Call init() first.');
8659
+ },
8660
+
8661
+ /**
8662
+ * Track a custom event (alias for track)
8663
+ * @param {string} eventName - Name of the event
8664
+ * @param {Object} [properties] - Event properties
8665
+ * @param {Object} [options] - Event options
8666
+ * @returns {Promise<void>}
8667
+ */
8668
+ async trackEvent(eventName, properties, options) {
8669
+ const instance = this.getInstance();
8670
+ if (instance && instance.trackEvent) {
8671
+ return await instance.trackEvent(eventName, properties, options);
8672
+ }
8673
+ throw new Error('SDK not initialized. Call init() first.');
8674
+ },
8675
+
8676
+ /**
8677
+ * Track an auto event
8678
+ * @param {string} eventName - Name of the auto event
8679
+ * @param {Object} [autoEventData] - Auto event data
8680
+ * @param {Object} [elementData] - Element data
8681
+ * @returns {Promise<void>}
8682
+ */
8683
+ async trackAutoEvent(eventName, autoEventData, elementData) {
8684
+ const instance = this.getInstance();
8685
+ if (instance && instance.trackAutoEvent) {
8686
+ return await instance.trackAutoEvent(eventName, autoEventData, elementData);
8687
+ }
8688
+ throw new Error('SDK not initialized. Call init() first.');
8689
+ },
8690
+
8691
+ /**
8692
+ * Connect wallet
8693
+ * @returns {Promise<string|null>} Wallet address or null
8694
+ */
8695
+ async connectWallet() {
8696
+ const instance = this.getInstance();
8697
+ if (instance && instance.connectWallet) {
8698
+ return await instance.connectWallet();
8699
+ }
8700
+ throw new Error('SDK not initialized. Call init() first.');
8701
+ },
8702
+
8703
+ /**
8704
+ * Check if wallet is connected
8705
+ * @returns {Promise<boolean>}
8706
+ */
8707
+ async isWalletConnected() {
8708
+ const instance = this.getInstance();
8709
+ if (instance && instance.isWalletConnected) {
8710
+ return await instance.isWalletConnected();
8711
+ }
8712
+ throw new Error('SDK not initialized. Call init() first.');
8713
+ },
8714
+
8715
+ /**
8716
+ * Update wallet info
8717
+ * @returns {Promise<any>}
8718
+ */
8719
+ async updateWalletInfo() {
8720
+ const instance = this.getInstance();
8721
+ if (instance && instance.updateWalletInfo) {
8722
+ return await instance.updateWalletInfo();
8723
+ }
8724
+ throw new Error('SDK not initialized. Call init() first.');
8725
+ },
8726
+
8727
+ /**
8728
+ * Set tracking consent
8729
+ * @param {boolean} consent - Consent value
8730
+ */
8731
+ setTrackingConsent(consent) {
8732
+ const instance = this.getInstance();
8733
+ if (instance && instance.setTrackingConsent) {
8734
+ return instance.setTrackingConsent(consent);
8735
+ }
8736
+ throw new Error('SDK not initialized. Call init() first.');
8737
+ },
8738
+
8739
+ /**
8740
+ * Get tracking consent
8741
+ * @returns {boolean}
8742
+ */
8743
+ getTrackingConsent() {
8744
+ const instance = this.getInstance();
8745
+ if (instance && instance.getTrackingConsent) {
8746
+ return instance.getTrackingConsent();
8747
+ }
8748
+ return false;
8749
+ },
8750
+
8751
+ /**
8752
+ * Get session data
8753
+ * @returns {Object}
8754
+ */
8755
+ getSessionData() {
8756
+ const instance = this.getInstance();
8757
+ if (instance && instance.getSessionData) {
8758
+ return instance.getSessionData();
8759
+ }
8760
+ return null;
8761
+ },
8762
+
8763
+ /**
8764
+ * Get chronological interactions
8765
+ * @returns {Array}
8766
+ */
8767
+ getChronologicalInteractions() {
8768
+ const instance = this.getInstance();
8769
+ if (instance && instance.getChronologicalInteractions) {
8770
+ return instance.getChronologicalInteractions();
8771
+ }
8772
+ return [];
8773
+ },
8774
+
8775
+ /**
8776
+ * Sort interactions chronologically (alias)
8777
+ * @returns {Array}
8778
+ */
8779
+ sortInteractionsChronologically() {
8780
+ const instance = this.getInstance();
8781
+ if (instance && instance.sortInteractionsChronologically) {
8782
+ return instance.sortInteractionsChronologically();
8783
+ }
8784
+ return [];
8785
+ },
8786
+
8787
+ /**
8788
+ * Enable auto events
8789
+ */
8790
+ enableAutoEvents() {
8791
+ const instance = this.getInstance();
8792
+ if (instance && instance.enableAutoEvents) {
8793
+ return instance.enableAutoEvents();
8794
+ }
8795
+ },
8796
+
8797
+ /**
8798
+ * Disable auto events
8799
+ */
8800
+ disableAutoEvents() {
8801
+ const instance = this.getInstance();
8802
+ if (instance && instance.disableAutoEvents) {
8803
+ return instance.disableAutoEvents();
8804
+ }
8805
+ },
8806
+
8807
+ /**
8808
+ * Set auto events disabled paths
8809
+ * @param {string|string[]} paths - Paths to disable
8810
+ */
8811
+ setAutoEventsDisabledPaths(paths) {
8812
+ const instance = this.getInstance();
8813
+ if (instance && instance.setAutoEventsDisabledPaths) {
8814
+ return instance.setAutoEventsDisabledPaths(paths);
8815
+ }
8816
+ },
8817
+
8818
+ /**
8819
+ * Disable specific auto events
8820
+ * @param {string|string[]} events - Event name(s) to disable
8821
+ */
8822
+ disableAutoEvent(events) {
8823
+ const instance = this.getInstance();
8824
+ if (instance && instance.disableAutoEvent) {
8825
+ return instance.disableAutoEvent(events);
8826
+ }
8827
+ },
8828
+
8829
+ /**
8830
+ * Enable specific auto events
8831
+ * @param {string|string[]} events - Event name(s) to enable
8832
+ */
8833
+ enableAutoEvent(events) {
8834
+ const instance = this.getInstance();
8835
+ if (instance && instance.enableAutoEvent) {
8836
+ return instance.enableAutoEvent(events);
8837
+ }
8838
+ },
8839
+
8840
+ /**
8841
+ * Set auto events disabled events
8842
+ * @param {string[]} events - Array of event names to disable
8843
+ */
8844
+ setAutoEventsDisabledEvents(events) {
8845
+ const instance = this.getInstance();
8846
+ if (instance && instance.setAutoEventsDisabledEvents) {
8847
+ return instance.setAutoEventsDisabledEvents(events);
8848
+ }
8849
+ },
8850
+
8851
+ /**
8852
+ * Get available auto events
8853
+ * @returns {string[]}
8854
+ */
8855
+ getAvailableAutoEvents() {
8856
+ const instance = this.getInstance();
8857
+ if (instance && instance.getAvailableAutoEvents) {
8858
+ return instance.getAvailableAutoEvents();
8859
+ }
8860
+ return [];
8861
+ },
8862
+
8863
+ /**
8864
+ * Get auto events configuration
8865
+ * @returns {Object}
8866
+ */
8867
+ getAutoEventsConfig() {
8868
+ const instance = this.getInstance();
8869
+ if (instance && instance.getAutoEventsConfig) {
8870
+ return instance.getAutoEventsConfig();
8871
+ }
8872
+ return null;
8873
+ },
8874
+
8875
+ /**
8876
+ * People object for managing user properties
8877
+ */
8878
+ get people() {
8879
+ const instance = this.getInstance();
8880
+ if (instance && instance.people) {
8881
+ return instance.people;
8882
+ }
8883
+ // Return a stub object that will work once SDK is initialized
8884
+ return {
8885
+ set: async (properties) => {
8886
+ const inst = this.getInstance();
8887
+ if (inst && inst.people && inst.people.set) {
8888
+ return await inst.people.set(properties);
8889
+ }
8890
+ throw new Error('SDK not initialized. Call init() first.');
8891
+ },
8892
+ setOnce: async (properties) => {
8893
+ const inst = this.getInstance();
8894
+ if (inst && inst.people && inst.people.setOnce) {
8895
+ return await inst.people.setOnce(properties);
8896
+ }
8897
+ throw new Error('SDK not initialized. Call init() first.');
8898
+ },
8899
+ unset: async (properties) => {
8900
+ const inst = this.getInstance();
8901
+ if (inst && inst.people && inst.people.unset) {
8902
+ return await inst.people.unset(properties);
8903
+ }
8904
+ throw new Error('SDK not initialized. Call init() first.');
8905
+ },
8906
+ increment: async (key, amount) => {
8907
+ const inst = this.getInstance();
8908
+ if (inst && inst.people && inst.people.increment) {
8909
+ return await inst.people.increment(key, amount);
8910
+ }
8911
+ throw new Error('SDK not initialized. Call init() first.');
8912
+ },
8913
+ append: async (key, values) => {
8914
+ const inst = this.getInstance();
8915
+ if (inst && inst.people && inst.people.append) {
8916
+ return await inst.people.append(key, values);
8917
+ }
8918
+ throw new Error('SDK not initialized. Call init() first.');
8919
+ },
8920
+ union: async (key, values) => {
8921
+ const inst = this.getInstance();
8922
+ if (inst && inst.people && inst.people.union) {
8923
+ return await inst.people.union(key, values);
8924
+ }
8925
+ throw new Error('SDK not initialized. Call init() first.');
8926
+ },
8927
+ remove: async (key, values) => {
8928
+ const inst = this.getInstance();
8929
+ if (inst && inst.people && inst.people.remove) {
8930
+ return await inst.people.remove(key, values);
8931
+ }
8932
+ throw new Error('SDK not initialized. Call init() first.');
8933
+ },
8934
+ trackCharge: async (amount, properties) => {
8935
+ const inst = this.getInstance();
8936
+ if (inst && inst.people && inst.people.trackCharge) {
8937
+ return await inst.people.trackCharge(amount, properties);
8938
+ }
8939
+ throw new Error('SDK not initialized. Call init() first.');
8940
+ },
8941
+ clearCharges: async () => {
8942
+ const inst = this.getInstance();
8943
+ if (inst && inst.people && inst.people.clearCharges) {
8944
+ return await inst.people.clearCharges();
8945
+ }
8946
+ throw new Error('SDK not initialized. Call init() first.');
8947
+ },
8948
+ deleteUser: async () => {
8949
+ const inst = this.getInstance();
8950
+ if (inst && inst.people && inst.people.deleteUser) {
8951
+ return await inst.people.deleteUser();
8952
+ }
8953
+ throw new Error('SDK not initialized. Call init() first.');
8954
+ }
8955
+ };
8956
+ },
8957
+
8958
+ // -------------------------------------------------------------------------
8959
+ // Group Methods
8960
+ // -------------------------------------------------------------------------
8961
+
8962
+ /**
8963
+ * Set (overwrite) the user's group membership for a given key.
8964
+ * @param {string} groupKey - The group type key (e.g. 'company_id')
8965
+ * @param {string|string[]} groupId - The group ID(s) to assign
8966
+ * @returns {Promise<Object>}
8967
+ */
8968
+ async set_group(groupKey, groupId) {
8969
+ const instance = this.getInstance();
8970
+ if (instance && instance.set_group) {
8971
+ return await instance.set_group(groupKey, groupId);
8972
+ }
8973
+ throw new Error('SDK not initialized. Call init() first.');
8974
+ },
8975
+
8976
+ /**
8977
+ * Add a group ID to an existing group key without removing current memberships.
8978
+ * @param {string} groupKey - The group type key (e.g. 'company_id')
8979
+ * @param {string} groupId - The single group ID to add
8980
+ * @returns {Promise<Object>}
8981
+ */
8982
+ async add_group(groupKey, groupId) {
8983
+ const instance = this.getInstance();
8984
+ if (instance && instance.add_group) {
8985
+ return await instance.add_group(groupKey, groupId);
8986
+ }
8987
+ throw new Error('SDK not initialized. Call init() first.');
8988
+ },
8989
+
8990
+ /**
8991
+ * Remove a specific group ID from the user's group membership.
8992
+ * @param {string} groupKey - The group type key (e.g. 'company_id')
8993
+ * @param {string} groupId - The group ID to remove
8994
+ * @returns {Promise<Object>}
8995
+ */
8996
+ async remove_group(groupKey, groupId) {
8997
+ const instance = this.getInstance();
8998
+ if (instance && instance.remove_group) {
8999
+ return await instance.remove_group(groupKey, groupId);
9000
+ }
9001
+ throw new Error('SDK not initialized. Call init() first.');
9002
+ },
9003
+
9004
+ /**
9005
+ * Get a group profile reference object for performing profile operations.
9006
+ *
9007
+ * Returns a synchronous object with the following methods:
9008
+ * .set(properties) – Set group profile properties
9009
+ * .set_once(properties) – Set properties only if not already set
9010
+ * .union(listName, values) – Add values to a list property (no duplicates)
9011
+ * .remove(listName, value) – Remove a value from a list property
9012
+ * .unset(property) – Remove a property from the group profile
9013
+ * .increment(property, value) Increment a numeric group property (default +1)
9014
+ * .append(property, value) – Append a value to a list property on the group
9015
+ * .delete() – Delete the entire group profile
9016
+ *
9017
+ * @param {string} groupKey - The group type key (e.g. 'company_id')
9018
+ * @param {string} groupId - The specific group ID
9019
+ * @returns {Object} Group profile reference object
9020
+ *
9021
+ * @example
9022
+ * const group = Cryptique.get_group('company', 'acme-corp');
9023
+ * await group.set({ plan: 'enterprise', employees: 500 });
9024
+ * await group.set_once({ created_at: new Date().toISOString() });
9025
+ * await group.union('tags', ['b2b', 'saas']);
9026
+ * await group.unset('old_property');
9027
+ * await group.delete();
9028
+ */
9029
+ get_group(groupKey, groupId) {
9030
+ const instance = this.getInstance();
9031
+ if (instance && instance.get_group) {
9032
+ return instance.get_group(groupKey, groupId);
9033
+ }
9034
+ // Return a stub whose methods all throw if SDK not yet ready
9035
+ const notReady = () => { throw new Error('SDK not initialized. Call init() first.'); };
9036
+ return {
9037
+ set: notReady,
9038
+ set_once: notReady,
9039
+ union: notReady,
9040
+ remove: notReady,
9041
+ unset: notReady,
9042
+ increment: notReady,
9043
+ append: notReady,
9044
+ delete: notReady
9045
+ };
9046
+ }
9047
+ };
9048
+
9049
+ // Proxy all methods from window.Cryptique to our export
9050
+ // This will be populated after script.js loads
9051
+ // Also sync properties that might not be methods
9052
+ const syncMethods = () => {
9053
+ if (typeof window !== 'undefined' && window.Cryptique) {
9054
+ Object.keys(window.Cryptique).forEach(key => {
9055
+ // Skip if we already have a custom implementation
9056
+ if (['people', 'set_group', 'add_group', 'remove_group', 'get_group'].includes(key) || CryptiqueSDK.hasOwnProperty(key)) {
9057
+ return;
9058
+ }
9059
+
9060
+ if (typeof window.Cryptique[key] === 'function') {
9061
+ CryptiqueSDK[key] = window.Cryptique[key].bind(window.Cryptique);
9062
+ } else {
9063
+ CryptiqueSDK[key] = window.Cryptique[key];
9064
+ }
9065
+ });
9066
+
9067
+ // Sync version and siteId properties
9068
+ if (window.Cryptique.version) {
9069
+ CryptiqueSDK.version = window.Cryptique.version;
9070
+ }
9071
+ if (window.Cryptique.siteId) {
9072
+ CryptiqueSDK.siteId = window.Cryptique.siteId;
9073
+ }
9074
+ if (window.Cryptique.sessionData) {
9075
+ CryptiqueSDK.sessionData = window.Cryptique.sessionData;
9076
+ }
9077
+ }
9078
+ };
9079
+
9080
+ // Try to sync immediately if SDK is already loaded
9081
+ if (typeof window !== 'undefined') {
9082
+ syncMethods();
9083
+
9084
+ // Also sync after DOM loads (in case script loads async)
9085
+ if (window.addEventListener) {
9086
+ window.addEventListener('load', syncMethods);
9087
+ if (document.readyState === 'loading') {
9088
+ document.addEventListener('DOMContentLoaded', syncMethods);
9089
+ } else {
9090
+ syncMethods();
9091
+ }
9092
+ }
9093
+ }
9094
+
9095
+ // Export for CommonJS
9096
+ if (typeof module !== 'undefined' && module.exports) {
9097
+ module.exports = CryptiqueSDK;
9098
+ module.exports.default = CryptiqueSDK;
9089
9099
  }
9090
9100
 
9091
9101
  export { CryptiqueSDK as default };