@journium/js 1.0.0 → 1.0.2
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/README.md +154 -274
- package/dist/JourniumAnalytics.d.ts +26 -0
- package/dist/JourniumAnalytics.d.ts.map +1 -0
- package/dist/JourniumClient.d.ts +25 -0
- package/dist/JourniumClient.d.ts.map +1 -0
- package/dist/autocapture.d.ts +4 -16
- package/dist/autocapture.d.ts.map +1 -1
- package/dist/client.d.ts +10 -8
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +149 -149
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +24 -33
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +147 -147
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +150 -150
- package/dist/index.umd.js.map +1 -1
- package/dist/journium.d.ts +9 -12
- package/dist/journium.d.ts.map +1 -1
- package/dist/pageview.d.ts +4 -4
- package/dist/pageview.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.umd.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JourniumAnalytics = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -431,9 +431,9 @@
|
|
|
431
431
|
var _a;
|
|
432
432
|
return typeof process !== 'undefined' && !!((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node);
|
|
433
433
|
};
|
|
434
|
-
const
|
|
434
|
+
const fetchRemoteOptions = async (apiHost, publishableKey, fetchFn) => {
|
|
435
435
|
const endpoint = '/v1/configs';
|
|
436
|
-
const url = `${apiHost}${endpoint}?ingestion_key=${encodeURIComponent(
|
|
436
|
+
const url = `${apiHost}${endpoint}?ingestion_key=${encodeURIComponent(publishableKey)}`;
|
|
437
437
|
try {
|
|
438
438
|
let fetch = fetchFn;
|
|
439
439
|
if (!fetch) {
|
|
@@ -453,36 +453,43 @@
|
|
|
453
453
|
},
|
|
454
454
|
});
|
|
455
455
|
if (!response.ok) {
|
|
456
|
-
throw new Error(`
|
|
456
|
+
throw new Error(`Options fetch failed: ${response.status} ${response.statusText}`);
|
|
457
457
|
}
|
|
458
458
|
const data = await response.json();
|
|
459
459
|
return data;
|
|
460
460
|
}
|
|
461
461
|
catch (error) {
|
|
462
|
-
console.warn('Failed to fetch remote
|
|
462
|
+
console.warn('Failed to fetch remote options:', error);
|
|
463
463
|
return null;
|
|
464
464
|
}
|
|
465
465
|
};
|
|
466
|
-
const
|
|
467
|
-
if (!
|
|
468
|
-
return
|
|
466
|
+
const mergeOptions = (localOptions, remoteOptions) => {
|
|
467
|
+
if (!remoteOptions && !localOptions) {
|
|
468
|
+
return {};
|
|
469
469
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
470
|
+
if (!remoteOptions) {
|
|
471
|
+
return localOptions;
|
|
472
|
+
}
|
|
473
|
+
if (!localOptions) {
|
|
474
|
+
return remoteOptions;
|
|
475
|
+
}
|
|
476
|
+
// Deep merge local options into remote options
|
|
477
|
+
// Local options takes precedence over remote options
|
|
478
|
+
const merged = { ...remoteOptions };
|
|
473
479
|
// Handle primitive values
|
|
474
|
-
Object.keys(
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
480
|
+
Object.keys(localOptions).forEach(key => {
|
|
481
|
+
const localValue = localOptions[key];
|
|
482
|
+
if (localValue !== undefined && localValue !== null) {
|
|
483
|
+
if (typeof localValue === 'object' && !Array.isArray(localValue)) {
|
|
484
|
+
// Deep merge objects - local options overrides remote
|
|
478
485
|
merged[key] = {
|
|
479
486
|
...(merged[key] || {}),
|
|
480
|
-
...
|
|
487
|
+
...localValue
|
|
481
488
|
};
|
|
482
489
|
}
|
|
483
490
|
else {
|
|
484
|
-
// Override primitive values and arrays
|
|
485
|
-
merged[key] =
|
|
491
|
+
// Override primitive values and arrays with local options
|
|
492
|
+
merged[key] = localValue;
|
|
486
493
|
}
|
|
487
494
|
}
|
|
488
495
|
});
|
|
@@ -491,14 +498,14 @@
|
|
|
491
498
|
|
|
492
499
|
const DEFAULT_SESSION_TIMEOUT = 30 * 60 * 1000; // 30 minutes in ms
|
|
493
500
|
class BrowserIdentityManager {
|
|
494
|
-
constructor(sessionTimeout,
|
|
501
|
+
constructor(sessionTimeout, publishableKey) {
|
|
495
502
|
this.identity = null;
|
|
496
503
|
this.sessionTimeout = DEFAULT_SESSION_TIMEOUT;
|
|
497
504
|
if (sessionTimeout) {
|
|
498
505
|
this.sessionTimeout = sessionTimeout;
|
|
499
506
|
}
|
|
500
|
-
// Generate storage key with
|
|
501
|
-
this.storageKey =
|
|
507
|
+
// Generate storage key with publishableKey pattern: jrnm_<publishableKey>_journium
|
|
508
|
+
this.storageKey = publishableKey ? `jrnm_${publishableKey}_journium` : '__journium_identity';
|
|
502
509
|
this.loadOrCreateIdentity();
|
|
503
510
|
}
|
|
504
511
|
loadOrCreateIdentity() {
|
|
@@ -670,132 +677,122 @@
|
|
|
670
677
|
this.flushTimer = null;
|
|
671
678
|
this.initialized = false;
|
|
672
679
|
// Validate required configuration
|
|
673
|
-
if (!config.
|
|
674
|
-
console.error('Journium:
|
|
680
|
+
if (!config.publishableKey) {
|
|
681
|
+
console.error('Journium: publishableKey is required but not provided. SDK will not function.');
|
|
675
682
|
return;
|
|
676
683
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
684
|
+
// Set default apiHost if not provided
|
|
685
|
+
this.config = {
|
|
686
|
+
...config,
|
|
687
|
+
apiHost: config.apiHost || 'https://events.journium.app'
|
|
688
|
+
};
|
|
689
|
+
// Generate storage key for options caching
|
|
690
|
+
this.optionsStorageKey = `jrnm_${config.publishableKey}_options`;
|
|
691
|
+
// Generate default values
|
|
692
|
+
const defaultOptions = {
|
|
693
|
+
debug: false,
|
|
694
|
+
flushAt: 20,
|
|
695
|
+
flushInterval: 10000,
|
|
696
|
+
sessionTimeout: 30 * 60 * 1000, // 30 minutes
|
|
697
|
+
};
|
|
698
|
+
// Initialize effective options with local options taking precedence over defaults
|
|
699
|
+
this.effectiveOptions = { ...defaultOptions };
|
|
700
|
+
if (this.config.options) {
|
|
701
|
+
this.effectiveOptions = mergeOptions(defaultOptions, this.config.options);
|
|
680
702
|
}
|
|
681
|
-
this.config = config;
|
|
682
|
-
// Generate storage key for config caching
|
|
683
|
-
this.configStorageKey = `jrnm_${config.token}_config`;
|
|
684
703
|
// Initialize identity manager
|
|
685
|
-
this.identityManager = new BrowserIdentityManager(this.
|
|
704
|
+
this.identityManager = new BrowserIdentityManager(this.effectiveOptions.sessionTimeout, this.config.publishableKey);
|
|
686
705
|
// Initialize synchronously with cached config, fetch fresh config in background
|
|
687
706
|
this.initializeSync();
|
|
688
|
-
this.
|
|
707
|
+
this.fetchRemoteOptionsAsync();
|
|
689
708
|
}
|
|
690
|
-
|
|
709
|
+
loadCachedOptions() {
|
|
710
|
+
var _a;
|
|
691
711
|
if (typeof window === 'undefined' || !window.localStorage) {
|
|
692
712
|
return null;
|
|
693
713
|
}
|
|
694
714
|
try {
|
|
695
|
-
const cached = window.localStorage.getItem(this.
|
|
715
|
+
const cached = window.localStorage.getItem(this.optionsStorageKey);
|
|
696
716
|
return cached ? JSON.parse(cached) : null;
|
|
697
717
|
}
|
|
698
718
|
catch (error) {
|
|
699
|
-
if (this.
|
|
719
|
+
if ((_a = this.effectiveOptions) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
700
720
|
console.warn('Journium: Failed to load cached config:', error);
|
|
701
721
|
}
|
|
702
722
|
return null;
|
|
703
723
|
}
|
|
704
724
|
}
|
|
705
|
-
|
|
725
|
+
saveCachedOptions(options) {
|
|
726
|
+
var _a;
|
|
706
727
|
if (typeof window === 'undefined' || !window.localStorage) {
|
|
707
728
|
return;
|
|
708
729
|
}
|
|
709
730
|
try {
|
|
710
|
-
window.localStorage.setItem(this.
|
|
731
|
+
window.localStorage.setItem(this.optionsStorageKey, JSON.stringify(options));
|
|
711
732
|
}
|
|
712
733
|
catch (error) {
|
|
713
|
-
if (this.
|
|
734
|
+
if ((_a = this.effectiveOptions) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
714
735
|
console.warn('Journium: Failed to save config to cache:', error);
|
|
715
736
|
}
|
|
716
737
|
}
|
|
717
738
|
}
|
|
718
739
|
initializeSync() {
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
};
|
|
727
|
-
if (cachedConfig) {
|
|
728
|
-
// Use cached remote config
|
|
729
|
-
this.config = {
|
|
730
|
-
...localOnlyConfig,
|
|
731
|
-
...cachedConfig,
|
|
732
|
-
};
|
|
733
|
-
if (this.config.debug) {
|
|
734
|
-
console.log('Journium: Using cached configuration:', cachedConfig);
|
|
740
|
+
// Step 1: Load cached remote options from localStorage (synchronous)
|
|
741
|
+
const cachedRemoteOptions = this.loadCachedOptions();
|
|
742
|
+
// Step 2: If no local options provided, use cached remote options
|
|
743
|
+
if (!this.config.options && cachedRemoteOptions) {
|
|
744
|
+
this.effectiveOptions = cachedRemoteOptions;
|
|
745
|
+
if (this.effectiveOptions.debug) {
|
|
746
|
+
console.log('Journium: Using cached remote options:', cachedRemoteOptions);
|
|
735
747
|
}
|
|
736
748
|
}
|
|
737
|
-
else {
|
|
738
|
-
// Use defaults for first-time initialization
|
|
739
|
-
this.config = {
|
|
740
|
-
...this.config,
|
|
741
|
-
debug: (_a = this.config.debug) !== null && _a !== void 0 ? _a : false,
|
|
742
|
-
flushAt: (_b = this.config.flushAt) !== null && _b !== void 0 ? _b : 20,
|
|
743
|
-
flushInterval: (_c = this.config.flushInterval) !== null && _c !== void 0 ? _c : 10000,
|
|
744
|
-
};
|
|
745
|
-
if (this.config.debug) {
|
|
746
|
-
console.log('Journium: No cached config found, using defaults');
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
// Update session timeout from config
|
|
750
|
-
if (this.config.sessionTimeout) {
|
|
751
|
-
this.identityManager.updateSessionTimeout(this.config.sessionTimeout);
|
|
752
|
-
}
|
|
753
749
|
// Step 3: Mark as initialized immediately - no need to wait for remote fetch
|
|
754
750
|
this.initialized = true;
|
|
755
751
|
// Step 4: Start flush timer immediately
|
|
756
|
-
if (this.
|
|
752
|
+
if (this.effectiveOptions.flushInterval && this.effectiveOptions.flushInterval > 0) {
|
|
757
753
|
this.startFlushTimer();
|
|
758
754
|
}
|
|
759
|
-
if (this.
|
|
760
|
-
console.log('Journium: Client initialized
|
|
755
|
+
if (this.effectiveOptions.debug) {
|
|
756
|
+
console.log('Journium: Client initialized with effective options:', this.effectiveOptions);
|
|
761
757
|
}
|
|
762
758
|
}
|
|
763
|
-
async
|
|
759
|
+
async fetchRemoteOptionsAsync() {
|
|
764
760
|
// Fetch fresh config in background
|
|
765
|
-
if (this.config.
|
|
766
|
-
await this.
|
|
761
|
+
if (this.config.publishableKey) {
|
|
762
|
+
await this.fetchAndCacheRemoteOptions();
|
|
767
763
|
}
|
|
768
764
|
}
|
|
769
|
-
async
|
|
765
|
+
async fetchAndCacheRemoteOptions() {
|
|
770
766
|
try {
|
|
771
|
-
if (this.
|
|
767
|
+
if (this.effectiveOptions.debug) {
|
|
772
768
|
console.log('Journium: Fetching remote configuration in background...');
|
|
773
769
|
}
|
|
774
|
-
const
|
|
775
|
-
if (
|
|
776
|
-
// Save to cache for next session
|
|
777
|
-
this.
|
|
778
|
-
//
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
};
|
|
787
|
-
// Update session timeout if provided in fresh config
|
|
788
|
-
if (remoteConfigResponse.config.sessionTimeout) {
|
|
789
|
-
this.identityManager.updateSessionTimeout(remoteConfigResponse.config.sessionTimeout);
|
|
770
|
+
const remoteOptionsResponse = await fetchRemoteOptions(this.config.apiHost, this.config.publishableKey);
|
|
771
|
+
if (remoteOptionsResponse && remoteOptionsResponse.success) {
|
|
772
|
+
// Save remote config to cache for next session
|
|
773
|
+
this.saveCachedOptions(remoteOptionsResponse.config);
|
|
774
|
+
// Update effective options: local options (if provided) overrides fresh remote options
|
|
775
|
+
if (!this.config.options) {
|
|
776
|
+
// No local options provided, use fresh remote options
|
|
777
|
+
this.effectiveOptions = remoteOptionsResponse.config;
|
|
778
|
+
}
|
|
779
|
+
else {
|
|
780
|
+
// Local options provided, merge it over fresh remote options
|
|
781
|
+
this.effectiveOptions = mergeOptions(remoteOptionsResponse.config, this.config.options);
|
|
790
782
|
}
|
|
791
|
-
if
|
|
792
|
-
|
|
783
|
+
// Update session timeout if provided in fresh effective options
|
|
784
|
+
if (this.effectiveOptions.sessionTimeout) {
|
|
785
|
+
this.identityManager.updateSessionTimeout(this.effectiveOptions.sessionTimeout);
|
|
786
|
+
}
|
|
787
|
+
if (this.effectiveOptions.debug) {
|
|
788
|
+
console.log('Journium: Background remote options applied:', remoteOptionsResponse.config);
|
|
789
|
+
console.log('Journium: New effective options:', this.effectiveOptions);
|
|
793
790
|
}
|
|
794
791
|
}
|
|
795
792
|
}
|
|
796
793
|
catch (error) {
|
|
797
|
-
if (this.
|
|
798
|
-
console.warn('Journium: Background remote
|
|
794
|
+
if (this.effectiveOptions.debug) {
|
|
795
|
+
console.warn('Journium: Background remote options fetch failed:', error);
|
|
799
796
|
}
|
|
800
797
|
}
|
|
801
798
|
}
|
|
@@ -806,7 +803,7 @@
|
|
|
806
803
|
// Use universal setInterval (works in both browser and Node.js)
|
|
807
804
|
this.flushTimer = setInterval(() => {
|
|
808
805
|
this.flush();
|
|
809
|
-
}, this.
|
|
806
|
+
}, this.effectiveOptions.flushInterval);
|
|
810
807
|
}
|
|
811
808
|
async sendEvents(events) {
|
|
812
809
|
if (!events.length)
|
|
@@ -816,7 +813,7 @@
|
|
|
816
813
|
method: 'POST',
|
|
817
814
|
headers: {
|
|
818
815
|
'Content-Type': 'application/json',
|
|
819
|
-
'Authorization': `Bearer ${this.config.
|
|
816
|
+
'Authorization': `Bearer ${this.config.publishableKey}`,
|
|
820
817
|
},
|
|
821
818
|
body: JSON.stringify({
|
|
822
819
|
events,
|
|
@@ -825,12 +822,12 @@
|
|
|
825
822
|
if (!response.ok) {
|
|
826
823
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
827
824
|
}
|
|
828
|
-
if (this.
|
|
825
|
+
if (this.effectiveOptions.debug) {
|
|
829
826
|
console.log('Journium: Successfully sent events', events);
|
|
830
827
|
}
|
|
831
828
|
}
|
|
832
829
|
catch (error) {
|
|
833
|
-
if (this.
|
|
830
|
+
if (this.effectiveOptions.debug) {
|
|
834
831
|
console.error('Journium: Failed to send events', error);
|
|
835
832
|
}
|
|
836
833
|
throw error;
|
|
@@ -839,8 +836,8 @@
|
|
|
839
836
|
identify(distinctId, attributes = {}) {
|
|
840
837
|
var _a;
|
|
841
838
|
// Don't identify if SDK is not properly configured
|
|
842
|
-
if (!this.config || !this.config.
|
|
843
|
-
if ((_a = this.
|
|
839
|
+
if (!this.config || !this.config.publishableKey || !this.initialized) {
|
|
840
|
+
if ((_a = this.effectiveOptions) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
844
841
|
console.warn('Journium: identify() call rejected - SDK not ready');
|
|
845
842
|
}
|
|
846
843
|
return;
|
|
@@ -853,30 +850,30 @@
|
|
|
853
850
|
$anon_distinct_id: previousDistinctId,
|
|
854
851
|
};
|
|
855
852
|
this.track('$identify', identifyProperties);
|
|
856
|
-
if (this.
|
|
853
|
+
if (this.effectiveOptions.debug) {
|
|
857
854
|
console.log('Journium: User identified', { distinctId, attributes, previousDistinctId });
|
|
858
855
|
}
|
|
859
856
|
}
|
|
860
857
|
reset() {
|
|
861
858
|
var _a;
|
|
862
859
|
// Don't reset if SDK is not properly configured
|
|
863
|
-
if (!this.config || !this.config.
|
|
864
|
-
if ((_a = this.
|
|
860
|
+
if (!this.config || !this.config.publishableKey || !this.initialized) {
|
|
861
|
+
if ((_a = this.effectiveOptions) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
865
862
|
console.warn('Journium: reset() call rejected - SDK not ready');
|
|
866
863
|
}
|
|
867
864
|
return;
|
|
868
865
|
}
|
|
869
866
|
// Reset identity in identity manager
|
|
870
867
|
this.identityManager.reset();
|
|
871
|
-
if (this.
|
|
868
|
+
if (this.effectiveOptions.debug) {
|
|
872
869
|
console.log('Journium: User identity reset');
|
|
873
870
|
}
|
|
874
871
|
}
|
|
875
872
|
track(event, properties = {}) {
|
|
876
873
|
var _a;
|
|
877
874
|
// Don't track if SDK is not properly configured
|
|
878
|
-
if (!this.config || !this.config.
|
|
879
|
-
if ((_a = this.
|
|
875
|
+
if (!this.config || !this.config.publishableKey || !this.initialized) {
|
|
876
|
+
if ((_a = this.effectiveOptions) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
880
877
|
console.warn('Journium: track() call rejected - SDK not ready');
|
|
881
878
|
}
|
|
882
879
|
return;
|
|
@@ -898,22 +895,22 @@
|
|
|
898
895
|
};
|
|
899
896
|
const journiumEvent = {
|
|
900
897
|
uuid: generateUuidv7(),
|
|
901
|
-
ingestion_key: this.config.
|
|
898
|
+
ingestion_key: this.config.publishableKey,
|
|
902
899
|
client_timestamp: getCurrentTimestamp(),
|
|
903
900
|
event,
|
|
904
901
|
properties: eventProperties,
|
|
905
902
|
};
|
|
906
903
|
this.queue.push(journiumEvent);
|
|
907
|
-
if (this.
|
|
904
|
+
if (this.effectiveOptions.debug) {
|
|
908
905
|
console.log('Journium: Event tracked', journiumEvent);
|
|
909
906
|
}
|
|
910
|
-
if (this.queue.length >= this.
|
|
907
|
+
if (this.queue.length >= this.effectiveOptions.flushAt) {
|
|
911
908
|
this.flush();
|
|
912
909
|
}
|
|
913
910
|
}
|
|
914
911
|
async flush() {
|
|
915
912
|
// Don't flush if SDK is not properly configured
|
|
916
|
-
if (!this.config || !this.config.
|
|
913
|
+
if (!this.config || !this.config.publishableKey) {
|
|
917
914
|
return;
|
|
918
915
|
}
|
|
919
916
|
if (this.queue.length === 0)
|
|
@@ -935,6 +932,9 @@
|
|
|
935
932
|
}
|
|
936
933
|
this.flush();
|
|
937
934
|
}
|
|
935
|
+
getEffectiveOptions() {
|
|
936
|
+
return this.effectiveOptions;
|
|
937
|
+
}
|
|
938
938
|
}
|
|
939
939
|
|
|
940
940
|
class PageviewTracker {
|
|
@@ -960,7 +960,7 @@
|
|
|
960
960
|
this.client.track('$pageview', properties);
|
|
961
961
|
this.lastUrl = currentUrl;
|
|
962
962
|
}
|
|
963
|
-
|
|
963
|
+
startAutocapture() {
|
|
964
964
|
this.capturePageview();
|
|
965
965
|
if (typeof window !== 'undefined') {
|
|
966
966
|
// Store original methods for cleanup
|
|
@@ -980,7 +980,7 @@
|
|
|
980
980
|
window.addEventListener('popstate', this.popStateHandler);
|
|
981
981
|
}
|
|
982
982
|
}
|
|
983
|
-
|
|
983
|
+
stopAutocapture() {
|
|
984
984
|
if (typeof window !== 'undefined') {
|
|
985
985
|
// Restore original methods
|
|
986
986
|
if (this.originalPushState) {
|
|
@@ -1000,11 +1000,11 @@
|
|
|
1000
1000
|
}
|
|
1001
1001
|
|
|
1002
1002
|
class AutocaptureTracker {
|
|
1003
|
-
constructor(client,
|
|
1003
|
+
constructor(client, options = {}) {
|
|
1004
1004
|
this.listeners = new Map();
|
|
1005
1005
|
this.isActive = false;
|
|
1006
1006
|
this.client = client;
|
|
1007
|
-
this.
|
|
1007
|
+
this.options = {
|
|
1008
1008
|
captureClicks: true,
|
|
1009
1009
|
captureFormSubmits: true,
|
|
1010
1010
|
captureFormChanges: true,
|
|
@@ -1012,7 +1012,7 @@
|
|
|
1012
1012
|
ignoreClasses: ['journium-ignore'],
|
|
1013
1013
|
ignoreElements: ['script', 'style', 'noscript'],
|
|
1014
1014
|
captureContentText: true,
|
|
1015
|
-
...
|
|
1015
|
+
...options,
|
|
1016
1016
|
};
|
|
1017
1017
|
}
|
|
1018
1018
|
start() {
|
|
@@ -1020,16 +1020,16 @@
|
|
|
1020
1020
|
return;
|
|
1021
1021
|
}
|
|
1022
1022
|
this.isActive = true;
|
|
1023
|
-
if (this.
|
|
1023
|
+
if (this.options.captureClicks) {
|
|
1024
1024
|
this.addClickListener();
|
|
1025
1025
|
}
|
|
1026
|
-
if (this.
|
|
1026
|
+
if (this.options.captureFormSubmits) {
|
|
1027
1027
|
this.addFormSubmitListener();
|
|
1028
1028
|
}
|
|
1029
|
-
if (this.
|
|
1029
|
+
if (this.options.captureFormChanges) {
|
|
1030
1030
|
this.addFormChangeListener();
|
|
1031
1031
|
}
|
|
1032
|
-
if (this.
|
|
1032
|
+
if (this.options.captureTextSelection) {
|
|
1033
1033
|
this.addTextSelectionListener();
|
|
1034
1034
|
}
|
|
1035
1035
|
}
|
|
@@ -1113,17 +1113,17 @@
|
|
|
1113
1113
|
return true;
|
|
1114
1114
|
}
|
|
1115
1115
|
// Check if element should be ignored by tag name
|
|
1116
|
-
if ((_a = this.
|
|
1116
|
+
if ((_a = this.options.ignoreElements) === null || _a === void 0 ? void 0 : _a.includes(element.tagName.toLowerCase())) {
|
|
1117
1117
|
return true;
|
|
1118
1118
|
}
|
|
1119
1119
|
// Check if element has ignore classes
|
|
1120
|
-
if ((_b = this.
|
|
1120
|
+
if ((_b = this.options.ignoreClasses) === null || _b === void 0 ? void 0 : _b.some(cls => element.classList.contains(cls))) {
|
|
1121
1121
|
return true;
|
|
1122
1122
|
}
|
|
1123
1123
|
// Check parent elements for ignore classes
|
|
1124
1124
|
let parent = element.parentElement;
|
|
1125
1125
|
while (parent) {
|
|
1126
|
-
if ((_c = this.
|
|
1126
|
+
if ((_c = this.options.ignoreClasses) === null || _c === void 0 ? void 0 : _c.some(cls => parent.classList.contains(cls))) {
|
|
1127
1127
|
return true;
|
|
1128
1128
|
}
|
|
1129
1129
|
parent = parent.parentElement;
|
|
@@ -1155,7 +1155,7 @@
|
|
|
1155
1155
|
}
|
|
1156
1156
|
});
|
|
1157
1157
|
// Element content
|
|
1158
|
-
if (this.
|
|
1158
|
+
if (this.options.captureContentText) {
|
|
1159
1159
|
const text = this.getElementText(element);
|
|
1160
1160
|
if (text) {
|
|
1161
1161
|
properties.$element_text = text.substring(0, 200); // Limit text length
|
|
@@ -1342,17 +1342,18 @@
|
|
|
1342
1342
|
}
|
|
1343
1343
|
}
|
|
1344
1344
|
|
|
1345
|
-
class
|
|
1345
|
+
class JourniumAnalytics {
|
|
1346
1346
|
constructor(config) {
|
|
1347
|
+
var _a, _b;
|
|
1347
1348
|
this.config = config;
|
|
1348
1349
|
this.client = new JourniumClient(config);
|
|
1349
1350
|
this.pageviewTracker = new PageviewTracker(this.client);
|
|
1350
|
-
const
|
|
1351
|
-
this.autocaptureTracker = new AutocaptureTracker(this.client,
|
|
1352
|
-
// Store resolved autocapture state for
|
|
1353
|
-
this.autocaptureEnabled = config.autocapture !== false;
|
|
1351
|
+
const autocaptureOptions = this.resolveAutocaptureOptions((_a = config.options) === null || _a === void 0 ? void 0 : _a.autocapture);
|
|
1352
|
+
this.autocaptureTracker = new AutocaptureTracker(this.client, autocaptureOptions);
|
|
1353
|
+
// Store resolved autocapture state for startAutocapture method
|
|
1354
|
+
this.autocaptureEnabled = ((_b = config.options) === null || _b === void 0 ? void 0 : _b.autocapture) !== false;
|
|
1354
1355
|
}
|
|
1355
|
-
|
|
1356
|
+
resolveAutocaptureOptions(autocapture) {
|
|
1356
1357
|
if (autocapture === false) {
|
|
1357
1358
|
return {
|
|
1358
1359
|
captureClicks: false,
|
|
@@ -1378,44 +1379,43 @@
|
|
|
1378
1379
|
capturePageview(properties) {
|
|
1379
1380
|
this.pageviewTracker.capturePageview(properties);
|
|
1380
1381
|
}
|
|
1381
|
-
|
|
1382
|
-
|
|
1382
|
+
startAutocapture() {
|
|
1383
|
+
// Check if automatic pageview tracking is enabled (defaults to true)
|
|
1384
|
+
const effectiveOptions = this.client.getEffectiveOptions();
|
|
1385
|
+
const autoTrackPageviews = effectiveOptions.autoTrackPageviews !== false;
|
|
1386
|
+
if (autoTrackPageviews) {
|
|
1387
|
+
this.pageviewTracker.startAutocapture();
|
|
1388
|
+
}
|
|
1383
1389
|
if (this.autocaptureEnabled) {
|
|
1384
1390
|
this.autocaptureTracker.start();
|
|
1385
1391
|
}
|
|
1386
1392
|
}
|
|
1387
|
-
stopAutoCapture() {
|
|
1388
|
-
this.pageviewTracker.stopAutoCapture();
|
|
1389
|
-
this.autocaptureTracker.stop();
|
|
1390
|
-
}
|
|
1391
|
-
// Aliases for consistency (deprecated - use startAutoCapture)
|
|
1392
|
-
/** @deprecated Use startAutoCapture() instead */
|
|
1393
|
-
startAutocapture() {
|
|
1394
|
-
this.startAutoCapture();
|
|
1395
|
-
}
|
|
1396
|
-
/** @deprecated Use stopAutoCapture() instead */
|
|
1397
1393
|
stopAutocapture() {
|
|
1398
|
-
this.
|
|
1394
|
+
this.pageviewTracker.stopAutocapture();
|
|
1395
|
+
this.autocaptureTracker.stop();
|
|
1399
1396
|
}
|
|
1400
1397
|
async flush() {
|
|
1401
1398
|
return this.client.flush();
|
|
1402
1399
|
}
|
|
1400
|
+
getEffectiveOptions() {
|
|
1401
|
+
return this.client.getEffectiveOptions();
|
|
1402
|
+
}
|
|
1403
1403
|
destroy() {
|
|
1404
|
-
this.pageviewTracker.
|
|
1404
|
+
this.pageviewTracker.stopAutocapture();
|
|
1405
1405
|
this.autocaptureTracker.stop();
|
|
1406
1406
|
this.client.destroy();
|
|
1407
1407
|
}
|
|
1408
1408
|
}
|
|
1409
1409
|
const init = (config) => {
|
|
1410
|
-
return new
|
|
1410
|
+
return new JourniumAnalytics(config);
|
|
1411
1411
|
};
|
|
1412
1412
|
|
|
1413
1413
|
exports.AutocaptureTracker = AutocaptureTracker;
|
|
1414
1414
|
exports.BrowserIdentityManager = BrowserIdentityManager;
|
|
1415
|
-
exports.
|
|
1415
|
+
exports.JourniumAnalytics = JourniumAnalytics;
|
|
1416
1416
|
exports.JourniumClient = JourniumClient;
|
|
1417
1417
|
exports.PageviewTracker = PageviewTracker;
|
|
1418
|
-
exports.
|
|
1418
|
+
exports.fetchRemoteOptions = fetchRemoteOptions;
|
|
1419
1419
|
exports.generateId = generateId;
|
|
1420
1420
|
exports.generateUuidv7 = generateUuidv7;
|
|
1421
1421
|
exports.getCurrentTimestamp = getCurrentTimestamp;
|
|
@@ -1425,7 +1425,7 @@
|
|
|
1425
1425
|
exports.init = init;
|
|
1426
1426
|
exports.isBrowser = isBrowser;
|
|
1427
1427
|
exports.isNode = isNode;
|
|
1428
|
-
exports.
|
|
1428
|
+
exports.mergeOptions = mergeOptions;
|
|
1429
1429
|
|
|
1430
1430
|
}));
|
|
1431
1431
|
//# sourceMappingURL=index.umd.js.map
|