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