@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.esm.js
CHANGED
|
@@ -425,9 +425,9 @@ const isNode = () => {
|
|
|
425
425
|
var _a;
|
|
426
426
|
return typeof process !== 'undefined' && !!((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node);
|
|
427
427
|
};
|
|
428
|
-
const
|
|
428
|
+
const fetchRemoteOptions = async (apiHost, publishableKey, fetchFn) => {
|
|
429
429
|
const endpoint = '/v1/configs';
|
|
430
|
-
const url = `${apiHost}${endpoint}?ingestion_key=${encodeURIComponent(
|
|
430
|
+
const url = `${apiHost}${endpoint}?ingestion_key=${encodeURIComponent(publishableKey)}`;
|
|
431
431
|
try {
|
|
432
432
|
let fetch = fetchFn;
|
|
433
433
|
if (!fetch) {
|
|
@@ -447,36 +447,43 @@ const fetchRemoteConfig = async (apiHost, token, fetchFn) => {
|
|
|
447
447
|
},
|
|
448
448
|
});
|
|
449
449
|
if (!response.ok) {
|
|
450
|
-
throw new Error(`
|
|
450
|
+
throw new Error(`Options fetch failed: ${response.status} ${response.statusText}`);
|
|
451
451
|
}
|
|
452
452
|
const data = await response.json();
|
|
453
453
|
return data;
|
|
454
454
|
}
|
|
455
455
|
catch (error) {
|
|
456
|
-
console.warn('Failed to fetch remote
|
|
456
|
+
console.warn('Failed to fetch remote options:', error);
|
|
457
457
|
return null;
|
|
458
458
|
}
|
|
459
459
|
};
|
|
460
|
-
const
|
|
461
|
-
if (!
|
|
462
|
-
return
|
|
460
|
+
const mergeOptions = (localOptions, remoteOptions) => {
|
|
461
|
+
if (!remoteOptions && !localOptions) {
|
|
462
|
+
return {};
|
|
463
463
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
464
|
+
if (!remoteOptions) {
|
|
465
|
+
return localOptions;
|
|
466
|
+
}
|
|
467
|
+
if (!localOptions) {
|
|
468
|
+
return remoteOptions;
|
|
469
|
+
}
|
|
470
|
+
// Deep merge local options into remote options
|
|
471
|
+
// Local options takes precedence over remote options
|
|
472
|
+
const merged = { ...remoteOptions };
|
|
467
473
|
// Handle primitive values
|
|
468
|
-
Object.keys(
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
474
|
+
Object.keys(localOptions).forEach(key => {
|
|
475
|
+
const localValue = localOptions[key];
|
|
476
|
+
if (localValue !== undefined && localValue !== null) {
|
|
477
|
+
if (typeof localValue === 'object' && !Array.isArray(localValue)) {
|
|
478
|
+
// Deep merge objects - local options overrides remote
|
|
472
479
|
merged[key] = {
|
|
473
480
|
...(merged[key] || {}),
|
|
474
|
-
...
|
|
481
|
+
...localValue
|
|
475
482
|
};
|
|
476
483
|
}
|
|
477
484
|
else {
|
|
478
|
-
// Override primitive values and arrays
|
|
479
|
-
merged[key] =
|
|
485
|
+
// Override primitive values and arrays with local options
|
|
486
|
+
merged[key] = localValue;
|
|
480
487
|
}
|
|
481
488
|
}
|
|
482
489
|
});
|
|
@@ -485,14 +492,14 @@ const mergeConfigs = (localConfig, remoteConfig) => {
|
|
|
485
492
|
|
|
486
493
|
const DEFAULT_SESSION_TIMEOUT = 30 * 60 * 1000; // 30 minutes in ms
|
|
487
494
|
class BrowserIdentityManager {
|
|
488
|
-
constructor(sessionTimeout,
|
|
495
|
+
constructor(sessionTimeout, publishableKey) {
|
|
489
496
|
this.identity = null;
|
|
490
497
|
this.sessionTimeout = DEFAULT_SESSION_TIMEOUT;
|
|
491
498
|
if (sessionTimeout) {
|
|
492
499
|
this.sessionTimeout = sessionTimeout;
|
|
493
500
|
}
|
|
494
|
-
// Generate storage key with
|
|
495
|
-
this.storageKey =
|
|
501
|
+
// Generate storage key with publishableKey pattern: jrnm_<publishableKey>_journium
|
|
502
|
+
this.storageKey = publishableKey ? `jrnm_${publishableKey}_journium` : '__journium_identity';
|
|
496
503
|
this.loadOrCreateIdentity();
|
|
497
504
|
}
|
|
498
505
|
loadOrCreateIdentity() {
|
|
@@ -664,132 +671,122 @@ class JourniumClient {
|
|
|
664
671
|
this.flushTimer = null;
|
|
665
672
|
this.initialized = false;
|
|
666
673
|
// Validate required configuration
|
|
667
|
-
if (!config.
|
|
668
|
-
console.error('Journium:
|
|
674
|
+
if (!config.publishableKey) {
|
|
675
|
+
console.error('Journium: publishableKey is required but not provided. SDK will not function.');
|
|
669
676
|
return;
|
|
670
677
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
678
|
+
// Set default apiHost if not provided
|
|
679
|
+
this.config = {
|
|
680
|
+
...config,
|
|
681
|
+
apiHost: config.apiHost || 'https://events.journium.app'
|
|
682
|
+
};
|
|
683
|
+
// Generate storage key for options caching
|
|
684
|
+
this.optionsStorageKey = `jrnm_${config.publishableKey}_options`;
|
|
685
|
+
// Generate default values
|
|
686
|
+
const defaultOptions = {
|
|
687
|
+
debug: false,
|
|
688
|
+
flushAt: 20,
|
|
689
|
+
flushInterval: 10000,
|
|
690
|
+
sessionTimeout: 30 * 60 * 1000, // 30 minutes
|
|
691
|
+
};
|
|
692
|
+
// Initialize effective options with local options taking precedence over defaults
|
|
693
|
+
this.effectiveOptions = { ...defaultOptions };
|
|
694
|
+
if (this.config.options) {
|
|
695
|
+
this.effectiveOptions = mergeOptions(defaultOptions, this.config.options);
|
|
674
696
|
}
|
|
675
|
-
this.config = config;
|
|
676
|
-
// Generate storage key for config caching
|
|
677
|
-
this.configStorageKey = `jrnm_${config.token}_config`;
|
|
678
697
|
// Initialize identity manager
|
|
679
|
-
this.identityManager = new BrowserIdentityManager(this.
|
|
698
|
+
this.identityManager = new BrowserIdentityManager(this.effectiveOptions.sessionTimeout, this.config.publishableKey);
|
|
680
699
|
// Initialize synchronously with cached config, fetch fresh config in background
|
|
681
700
|
this.initializeSync();
|
|
682
|
-
this.
|
|
701
|
+
this.fetchRemoteOptionsAsync();
|
|
683
702
|
}
|
|
684
|
-
|
|
703
|
+
loadCachedOptions() {
|
|
704
|
+
var _a;
|
|
685
705
|
if (typeof window === 'undefined' || !window.localStorage) {
|
|
686
706
|
return null;
|
|
687
707
|
}
|
|
688
708
|
try {
|
|
689
|
-
const cached = window.localStorage.getItem(this.
|
|
709
|
+
const cached = window.localStorage.getItem(this.optionsStorageKey);
|
|
690
710
|
return cached ? JSON.parse(cached) : null;
|
|
691
711
|
}
|
|
692
712
|
catch (error) {
|
|
693
|
-
if (this.
|
|
713
|
+
if ((_a = this.effectiveOptions) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
694
714
|
console.warn('Journium: Failed to load cached config:', error);
|
|
695
715
|
}
|
|
696
716
|
return null;
|
|
697
717
|
}
|
|
698
718
|
}
|
|
699
|
-
|
|
719
|
+
saveCachedOptions(options) {
|
|
720
|
+
var _a;
|
|
700
721
|
if (typeof window === 'undefined' || !window.localStorage) {
|
|
701
722
|
return;
|
|
702
723
|
}
|
|
703
724
|
try {
|
|
704
|
-
window.localStorage.setItem(this.
|
|
725
|
+
window.localStorage.setItem(this.optionsStorageKey, JSON.stringify(options));
|
|
705
726
|
}
|
|
706
727
|
catch (error) {
|
|
707
|
-
if (this.
|
|
728
|
+
if ((_a = this.effectiveOptions) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
708
729
|
console.warn('Journium: Failed to save config to cache:', error);
|
|
709
730
|
}
|
|
710
731
|
}
|
|
711
732
|
}
|
|
712
733
|
initializeSync() {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
};
|
|
721
|
-
if (cachedConfig) {
|
|
722
|
-
// Use cached remote config
|
|
723
|
-
this.config = {
|
|
724
|
-
...localOnlyConfig,
|
|
725
|
-
...cachedConfig,
|
|
726
|
-
};
|
|
727
|
-
if (this.config.debug) {
|
|
728
|
-
console.log('Journium: Using cached configuration:', cachedConfig);
|
|
734
|
+
// Step 1: Load cached remote options from localStorage (synchronous)
|
|
735
|
+
const cachedRemoteOptions = this.loadCachedOptions();
|
|
736
|
+
// Step 2: If no local options provided, use cached remote options
|
|
737
|
+
if (!this.config.options && cachedRemoteOptions) {
|
|
738
|
+
this.effectiveOptions = cachedRemoteOptions;
|
|
739
|
+
if (this.effectiveOptions.debug) {
|
|
740
|
+
console.log('Journium: Using cached remote options:', cachedRemoteOptions);
|
|
729
741
|
}
|
|
730
742
|
}
|
|
731
|
-
else {
|
|
732
|
-
// Use defaults for first-time initialization
|
|
733
|
-
this.config = {
|
|
734
|
-
...this.config,
|
|
735
|
-
debug: (_a = this.config.debug) !== null && _a !== void 0 ? _a : false,
|
|
736
|
-
flushAt: (_b = this.config.flushAt) !== null && _b !== void 0 ? _b : 20,
|
|
737
|
-
flushInterval: (_c = this.config.flushInterval) !== null && _c !== void 0 ? _c : 10000,
|
|
738
|
-
};
|
|
739
|
-
if (this.config.debug) {
|
|
740
|
-
console.log('Journium: No cached config found, using defaults');
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
// Update session timeout from config
|
|
744
|
-
if (this.config.sessionTimeout) {
|
|
745
|
-
this.identityManager.updateSessionTimeout(this.config.sessionTimeout);
|
|
746
|
-
}
|
|
747
743
|
// Step 3: Mark as initialized immediately - no need to wait for remote fetch
|
|
748
744
|
this.initialized = true;
|
|
749
745
|
// Step 4: Start flush timer immediately
|
|
750
|
-
if (this.
|
|
746
|
+
if (this.effectiveOptions.flushInterval && this.effectiveOptions.flushInterval > 0) {
|
|
751
747
|
this.startFlushTimer();
|
|
752
748
|
}
|
|
753
|
-
if (this.
|
|
754
|
-
console.log('Journium: Client initialized
|
|
749
|
+
if (this.effectiveOptions.debug) {
|
|
750
|
+
console.log('Journium: Client initialized with effective options:', this.effectiveOptions);
|
|
755
751
|
}
|
|
756
752
|
}
|
|
757
|
-
async
|
|
753
|
+
async fetchRemoteOptionsAsync() {
|
|
758
754
|
// Fetch fresh config in background
|
|
759
|
-
if (this.config.
|
|
760
|
-
await this.
|
|
755
|
+
if (this.config.publishableKey) {
|
|
756
|
+
await this.fetchAndCacheRemoteOptions();
|
|
761
757
|
}
|
|
762
758
|
}
|
|
763
|
-
async
|
|
759
|
+
async fetchAndCacheRemoteOptions() {
|
|
764
760
|
try {
|
|
765
|
-
if (this.
|
|
761
|
+
if (this.effectiveOptions.debug) {
|
|
766
762
|
console.log('Journium: Fetching remote configuration in background...');
|
|
767
763
|
}
|
|
768
|
-
const
|
|
769
|
-
if (
|
|
770
|
-
// Save to cache for next session
|
|
771
|
-
this.
|
|
772
|
-
//
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
};
|
|
781
|
-
// Update session timeout if provided in fresh config
|
|
782
|
-
if (remoteConfigResponse.config.sessionTimeout) {
|
|
783
|
-
this.identityManager.updateSessionTimeout(remoteConfigResponse.config.sessionTimeout);
|
|
764
|
+
const remoteOptionsResponse = await fetchRemoteOptions(this.config.apiHost, this.config.publishableKey);
|
|
765
|
+
if (remoteOptionsResponse && remoteOptionsResponse.success) {
|
|
766
|
+
// Save remote config to cache for next session
|
|
767
|
+
this.saveCachedOptions(remoteOptionsResponse.config);
|
|
768
|
+
// Update effective options: local options (if provided) overrides fresh remote options
|
|
769
|
+
if (!this.config.options) {
|
|
770
|
+
// No local options provided, use fresh remote options
|
|
771
|
+
this.effectiveOptions = remoteOptionsResponse.config;
|
|
772
|
+
}
|
|
773
|
+
else {
|
|
774
|
+
// Local options provided, merge it over fresh remote options
|
|
775
|
+
this.effectiveOptions = mergeOptions(remoteOptionsResponse.config, this.config.options);
|
|
784
776
|
}
|
|
785
|
-
if
|
|
786
|
-
|
|
777
|
+
// Update session timeout if provided in fresh effective options
|
|
778
|
+
if (this.effectiveOptions.sessionTimeout) {
|
|
779
|
+
this.identityManager.updateSessionTimeout(this.effectiveOptions.sessionTimeout);
|
|
780
|
+
}
|
|
781
|
+
if (this.effectiveOptions.debug) {
|
|
782
|
+
console.log('Journium: Background remote options applied:', remoteOptionsResponse.config);
|
|
783
|
+
console.log('Journium: New effective options:', this.effectiveOptions);
|
|
787
784
|
}
|
|
788
785
|
}
|
|
789
786
|
}
|
|
790
787
|
catch (error) {
|
|
791
|
-
if (this.
|
|
792
|
-
console.warn('Journium: Background remote
|
|
788
|
+
if (this.effectiveOptions.debug) {
|
|
789
|
+
console.warn('Journium: Background remote options fetch failed:', error);
|
|
793
790
|
}
|
|
794
791
|
}
|
|
795
792
|
}
|
|
@@ -800,7 +797,7 @@ class JourniumClient {
|
|
|
800
797
|
// Use universal setInterval (works in both browser and Node.js)
|
|
801
798
|
this.flushTimer = setInterval(() => {
|
|
802
799
|
this.flush();
|
|
803
|
-
}, this.
|
|
800
|
+
}, this.effectiveOptions.flushInterval);
|
|
804
801
|
}
|
|
805
802
|
async sendEvents(events) {
|
|
806
803
|
if (!events.length)
|
|
@@ -810,7 +807,7 @@ class JourniumClient {
|
|
|
810
807
|
method: 'POST',
|
|
811
808
|
headers: {
|
|
812
809
|
'Content-Type': 'application/json',
|
|
813
|
-
'Authorization': `Bearer ${this.config.
|
|
810
|
+
'Authorization': `Bearer ${this.config.publishableKey}`,
|
|
814
811
|
},
|
|
815
812
|
body: JSON.stringify({
|
|
816
813
|
events,
|
|
@@ -819,12 +816,12 @@ class JourniumClient {
|
|
|
819
816
|
if (!response.ok) {
|
|
820
817
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
821
818
|
}
|
|
822
|
-
if (this.
|
|
819
|
+
if (this.effectiveOptions.debug) {
|
|
823
820
|
console.log('Journium: Successfully sent events', events);
|
|
824
821
|
}
|
|
825
822
|
}
|
|
826
823
|
catch (error) {
|
|
827
|
-
if (this.
|
|
824
|
+
if (this.effectiveOptions.debug) {
|
|
828
825
|
console.error('Journium: Failed to send events', error);
|
|
829
826
|
}
|
|
830
827
|
throw error;
|
|
@@ -833,8 +830,8 @@ class JourniumClient {
|
|
|
833
830
|
identify(distinctId, attributes = {}) {
|
|
834
831
|
var _a;
|
|
835
832
|
// Don't identify if SDK is not properly configured
|
|
836
|
-
if (!this.config || !this.config.
|
|
837
|
-
if ((_a = this.
|
|
833
|
+
if (!this.config || !this.config.publishableKey || !this.initialized) {
|
|
834
|
+
if ((_a = this.effectiveOptions) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
838
835
|
console.warn('Journium: identify() call rejected - SDK not ready');
|
|
839
836
|
}
|
|
840
837
|
return;
|
|
@@ -847,30 +844,30 @@ class JourniumClient {
|
|
|
847
844
|
$anon_distinct_id: previousDistinctId,
|
|
848
845
|
};
|
|
849
846
|
this.track('$identify', identifyProperties);
|
|
850
|
-
if (this.
|
|
847
|
+
if (this.effectiveOptions.debug) {
|
|
851
848
|
console.log('Journium: User identified', { distinctId, attributes, previousDistinctId });
|
|
852
849
|
}
|
|
853
850
|
}
|
|
854
851
|
reset() {
|
|
855
852
|
var _a;
|
|
856
853
|
// Don't reset if SDK is not properly configured
|
|
857
|
-
if (!this.config || !this.config.
|
|
858
|
-
if ((_a = this.
|
|
854
|
+
if (!this.config || !this.config.publishableKey || !this.initialized) {
|
|
855
|
+
if ((_a = this.effectiveOptions) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
859
856
|
console.warn('Journium: reset() call rejected - SDK not ready');
|
|
860
857
|
}
|
|
861
858
|
return;
|
|
862
859
|
}
|
|
863
860
|
// Reset identity in identity manager
|
|
864
861
|
this.identityManager.reset();
|
|
865
|
-
if (this.
|
|
862
|
+
if (this.effectiveOptions.debug) {
|
|
866
863
|
console.log('Journium: User identity reset');
|
|
867
864
|
}
|
|
868
865
|
}
|
|
869
866
|
track(event, properties = {}) {
|
|
870
867
|
var _a;
|
|
871
868
|
// Don't track if SDK is not properly configured
|
|
872
|
-
if (!this.config || !this.config.
|
|
873
|
-
if ((_a = this.
|
|
869
|
+
if (!this.config || !this.config.publishableKey || !this.initialized) {
|
|
870
|
+
if ((_a = this.effectiveOptions) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
874
871
|
console.warn('Journium: track() call rejected - SDK not ready');
|
|
875
872
|
}
|
|
876
873
|
return;
|
|
@@ -892,22 +889,22 @@ class JourniumClient {
|
|
|
892
889
|
};
|
|
893
890
|
const journiumEvent = {
|
|
894
891
|
uuid: generateUuidv7(),
|
|
895
|
-
ingestion_key: this.config.
|
|
892
|
+
ingestion_key: this.config.publishableKey,
|
|
896
893
|
client_timestamp: getCurrentTimestamp(),
|
|
897
894
|
event,
|
|
898
895
|
properties: eventProperties,
|
|
899
896
|
};
|
|
900
897
|
this.queue.push(journiumEvent);
|
|
901
|
-
if (this.
|
|
898
|
+
if (this.effectiveOptions.debug) {
|
|
902
899
|
console.log('Journium: Event tracked', journiumEvent);
|
|
903
900
|
}
|
|
904
|
-
if (this.queue.length >= this.
|
|
901
|
+
if (this.queue.length >= this.effectiveOptions.flushAt) {
|
|
905
902
|
this.flush();
|
|
906
903
|
}
|
|
907
904
|
}
|
|
908
905
|
async flush() {
|
|
909
906
|
// Don't flush if SDK is not properly configured
|
|
910
|
-
if (!this.config || !this.config.
|
|
907
|
+
if (!this.config || !this.config.publishableKey) {
|
|
911
908
|
return;
|
|
912
909
|
}
|
|
913
910
|
if (this.queue.length === 0)
|
|
@@ -929,6 +926,9 @@ class JourniumClient {
|
|
|
929
926
|
}
|
|
930
927
|
this.flush();
|
|
931
928
|
}
|
|
929
|
+
getEffectiveOptions() {
|
|
930
|
+
return this.effectiveOptions;
|
|
931
|
+
}
|
|
932
932
|
}
|
|
933
933
|
|
|
934
934
|
class PageviewTracker {
|
|
@@ -954,7 +954,7 @@ class PageviewTracker {
|
|
|
954
954
|
this.client.track('$pageview', properties);
|
|
955
955
|
this.lastUrl = currentUrl;
|
|
956
956
|
}
|
|
957
|
-
|
|
957
|
+
startAutocapture() {
|
|
958
958
|
this.capturePageview();
|
|
959
959
|
if (typeof window !== 'undefined') {
|
|
960
960
|
// Store original methods for cleanup
|
|
@@ -974,7 +974,7 @@ class PageviewTracker {
|
|
|
974
974
|
window.addEventListener('popstate', this.popStateHandler);
|
|
975
975
|
}
|
|
976
976
|
}
|
|
977
|
-
|
|
977
|
+
stopAutocapture() {
|
|
978
978
|
if (typeof window !== 'undefined') {
|
|
979
979
|
// Restore original methods
|
|
980
980
|
if (this.originalPushState) {
|
|
@@ -994,11 +994,11 @@ class PageviewTracker {
|
|
|
994
994
|
}
|
|
995
995
|
|
|
996
996
|
class AutocaptureTracker {
|
|
997
|
-
constructor(client,
|
|
997
|
+
constructor(client, options = {}) {
|
|
998
998
|
this.listeners = new Map();
|
|
999
999
|
this.isActive = false;
|
|
1000
1000
|
this.client = client;
|
|
1001
|
-
this.
|
|
1001
|
+
this.options = {
|
|
1002
1002
|
captureClicks: true,
|
|
1003
1003
|
captureFormSubmits: true,
|
|
1004
1004
|
captureFormChanges: true,
|
|
@@ -1006,7 +1006,7 @@ class AutocaptureTracker {
|
|
|
1006
1006
|
ignoreClasses: ['journium-ignore'],
|
|
1007
1007
|
ignoreElements: ['script', 'style', 'noscript'],
|
|
1008
1008
|
captureContentText: true,
|
|
1009
|
-
...
|
|
1009
|
+
...options,
|
|
1010
1010
|
};
|
|
1011
1011
|
}
|
|
1012
1012
|
start() {
|
|
@@ -1014,16 +1014,16 @@ class AutocaptureTracker {
|
|
|
1014
1014
|
return;
|
|
1015
1015
|
}
|
|
1016
1016
|
this.isActive = true;
|
|
1017
|
-
if (this.
|
|
1017
|
+
if (this.options.captureClicks) {
|
|
1018
1018
|
this.addClickListener();
|
|
1019
1019
|
}
|
|
1020
|
-
if (this.
|
|
1020
|
+
if (this.options.captureFormSubmits) {
|
|
1021
1021
|
this.addFormSubmitListener();
|
|
1022
1022
|
}
|
|
1023
|
-
if (this.
|
|
1023
|
+
if (this.options.captureFormChanges) {
|
|
1024
1024
|
this.addFormChangeListener();
|
|
1025
1025
|
}
|
|
1026
|
-
if (this.
|
|
1026
|
+
if (this.options.captureTextSelection) {
|
|
1027
1027
|
this.addTextSelectionListener();
|
|
1028
1028
|
}
|
|
1029
1029
|
}
|
|
@@ -1107,17 +1107,17 @@ class AutocaptureTracker {
|
|
|
1107
1107
|
return true;
|
|
1108
1108
|
}
|
|
1109
1109
|
// Check if element should be ignored by tag name
|
|
1110
|
-
if ((_a = this.
|
|
1110
|
+
if ((_a = this.options.ignoreElements) === null || _a === void 0 ? void 0 : _a.includes(element.tagName.toLowerCase())) {
|
|
1111
1111
|
return true;
|
|
1112
1112
|
}
|
|
1113
1113
|
// Check if element has ignore classes
|
|
1114
|
-
if ((_b = this.
|
|
1114
|
+
if ((_b = this.options.ignoreClasses) === null || _b === void 0 ? void 0 : _b.some(cls => element.classList.contains(cls))) {
|
|
1115
1115
|
return true;
|
|
1116
1116
|
}
|
|
1117
1117
|
// Check parent elements for ignore classes
|
|
1118
1118
|
let parent = element.parentElement;
|
|
1119
1119
|
while (parent) {
|
|
1120
|
-
if ((_c = this.
|
|
1120
|
+
if ((_c = this.options.ignoreClasses) === null || _c === void 0 ? void 0 : _c.some(cls => parent.classList.contains(cls))) {
|
|
1121
1121
|
return true;
|
|
1122
1122
|
}
|
|
1123
1123
|
parent = parent.parentElement;
|
|
@@ -1149,7 +1149,7 @@ class AutocaptureTracker {
|
|
|
1149
1149
|
}
|
|
1150
1150
|
});
|
|
1151
1151
|
// Element content
|
|
1152
|
-
if (this.
|
|
1152
|
+
if (this.options.captureContentText) {
|
|
1153
1153
|
const text = this.getElementText(element);
|
|
1154
1154
|
if (text) {
|
|
1155
1155
|
properties.$element_text = text.substring(0, 200); // Limit text length
|
|
@@ -1336,17 +1336,18 @@ class AutocaptureTracker {
|
|
|
1336
1336
|
}
|
|
1337
1337
|
}
|
|
1338
1338
|
|
|
1339
|
-
class
|
|
1339
|
+
class JourniumAnalytics {
|
|
1340
1340
|
constructor(config) {
|
|
1341
|
+
var _a, _b;
|
|
1341
1342
|
this.config = config;
|
|
1342
1343
|
this.client = new JourniumClient(config);
|
|
1343
1344
|
this.pageviewTracker = new PageviewTracker(this.client);
|
|
1344
|
-
const
|
|
1345
|
-
this.autocaptureTracker = new AutocaptureTracker(this.client,
|
|
1346
|
-
// Store resolved autocapture state for
|
|
1347
|
-
this.autocaptureEnabled = config.autocapture !== false;
|
|
1345
|
+
const autocaptureOptions = this.resolveAutocaptureOptions((_a = config.options) === null || _a === void 0 ? void 0 : _a.autocapture);
|
|
1346
|
+
this.autocaptureTracker = new AutocaptureTracker(this.client, autocaptureOptions);
|
|
1347
|
+
// Store resolved autocapture state for startAutocapture method
|
|
1348
|
+
this.autocaptureEnabled = ((_b = config.options) === null || _b === void 0 ? void 0 : _b.autocapture) !== false;
|
|
1348
1349
|
}
|
|
1349
|
-
|
|
1350
|
+
resolveAutocaptureOptions(autocapture) {
|
|
1350
1351
|
if (autocapture === false) {
|
|
1351
1352
|
return {
|
|
1352
1353
|
captureClicks: false,
|
|
@@ -1372,37 +1373,36 @@ class Journium {
|
|
|
1372
1373
|
capturePageview(properties) {
|
|
1373
1374
|
this.pageviewTracker.capturePageview(properties);
|
|
1374
1375
|
}
|
|
1375
|
-
|
|
1376
|
-
|
|
1376
|
+
startAutocapture() {
|
|
1377
|
+
// Check if automatic pageview tracking is enabled (defaults to true)
|
|
1378
|
+
const effectiveOptions = this.client.getEffectiveOptions();
|
|
1379
|
+
const autoTrackPageviews = effectiveOptions.autoTrackPageviews !== false;
|
|
1380
|
+
if (autoTrackPageviews) {
|
|
1381
|
+
this.pageviewTracker.startAutocapture();
|
|
1382
|
+
}
|
|
1377
1383
|
if (this.autocaptureEnabled) {
|
|
1378
1384
|
this.autocaptureTracker.start();
|
|
1379
1385
|
}
|
|
1380
1386
|
}
|
|
1381
|
-
stopAutoCapture() {
|
|
1382
|
-
this.pageviewTracker.stopAutoCapture();
|
|
1383
|
-
this.autocaptureTracker.stop();
|
|
1384
|
-
}
|
|
1385
|
-
// Aliases for consistency (deprecated - use startAutoCapture)
|
|
1386
|
-
/** @deprecated Use startAutoCapture() instead */
|
|
1387
|
-
startAutocapture() {
|
|
1388
|
-
this.startAutoCapture();
|
|
1389
|
-
}
|
|
1390
|
-
/** @deprecated Use stopAutoCapture() instead */
|
|
1391
1387
|
stopAutocapture() {
|
|
1392
|
-
this.
|
|
1388
|
+
this.pageviewTracker.stopAutocapture();
|
|
1389
|
+
this.autocaptureTracker.stop();
|
|
1393
1390
|
}
|
|
1394
1391
|
async flush() {
|
|
1395
1392
|
return this.client.flush();
|
|
1396
1393
|
}
|
|
1394
|
+
getEffectiveOptions() {
|
|
1395
|
+
return this.client.getEffectiveOptions();
|
|
1396
|
+
}
|
|
1397
1397
|
destroy() {
|
|
1398
|
-
this.pageviewTracker.
|
|
1398
|
+
this.pageviewTracker.stopAutocapture();
|
|
1399
1399
|
this.autocaptureTracker.stop();
|
|
1400
1400
|
this.client.destroy();
|
|
1401
1401
|
}
|
|
1402
1402
|
}
|
|
1403
1403
|
const init = (config) => {
|
|
1404
|
-
return new
|
|
1404
|
+
return new JourniumAnalytics(config);
|
|
1405
1405
|
};
|
|
1406
1406
|
|
|
1407
|
-
export { AutocaptureTracker, BrowserIdentityManager,
|
|
1407
|
+
export { AutocaptureTracker, BrowserIdentityManager, JourniumAnalytics, JourniumClient, PageviewTracker, fetchRemoteOptions, generateId, generateUuidv7, getCurrentTimestamp, getCurrentUrl, getPageTitle, getReferrer, init, isBrowser, isNode, mergeOptions };
|
|
1408
1408
|
//# sourceMappingURL=index.esm.js.map
|