@journium/react 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/context.d.ts +5 -3
- package/dist/context.d.ts.map +1 -1
- package/dist/hooks.d.ts +4 -4
- package/dist/hooks.d.ts.map +1 -1
- package/dist/{index.js → index.cjs} +181 -143
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +9 -7
- package/dist/{index.esm.js → index.mjs} +146 -133
- package/dist/index.mjs.map +1 -0
- package/package.json +32 -25
- package/readme.md +181 -124
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* uuidv7: A JavaScript implementation of UUID version 7
|
|
@@ -427,7 +429,7 @@ const isNode = () => {
|
|
|
427
429
|
var _a;
|
|
428
430
|
return typeof process !== 'undefined' && !!((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node);
|
|
429
431
|
};
|
|
430
|
-
const
|
|
432
|
+
const fetchRemoteOptions = async (apiHost, publishableKey, fetchFn) => {
|
|
431
433
|
const endpoint = '/v1/configs';
|
|
432
434
|
const url = `${apiHost}${endpoint}?ingestion_key=${encodeURIComponent(publishableKey)}`;
|
|
433
435
|
try {
|
|
@@ -449,42 +451,43 @@ const fetchRemoteConfig = async (apiHost, publishableKey, fetchFn) => {
|
|
|
449
451
|
},
|
|
450
452
|
});
|
|
451
453
|
if (!response.ok) {
|
|
452
|
-
throw new Error(`
|
|
454
|
+
throw new Error(`Options fetch failed: ${response.status} ${response.statusText}`);
|
|
453
455
|
}
|
|
454
456
|
const data = await response.json();
|
|
455
457
|
return data;
|
|
456
458
|
}
|
|
457
459
|
catch (error) {
|
|
458
|
-
console.warn('Failed to fetch remote
|
|
460
|
+
console.warn('Failed to fetch remote options:', error);
|
|
459
461
|
return null;
|
|
460
462
|
}
|
|
461
463
|
};
|
|
462
|
-
const
|
|
463
|
-
if (!
|
|
464
|
+
const mergeOptions = (localOptions, remoteOptions) => {
|
|
465
|
+
if (!remoteOptions && !localOptions) {
|
|
464
466
|
return {};
|
|
465
467
|
}
|
|
466
|
-
if (!
|
|
467
|
-
return
|
|
468
|
+
if (!remoteOptions) {
|
|
469
|
+
return localOptions;
|
|
468
470
|
}
|
|
469
|
-
if (!
|
|
470
|
-
return
|
|
471
|
+
if (!localOptions) {
|
|
472
|
+
return remoteOptions;
|
|
471
473
|
}
|
|
472
|
-
// Deep merge local
|
|
473
|
-
// Local
|
|
474
|
-
const merged = { ...
|
|
474
|
+
// Deep merge local options into remote options
|
|
475
|
+
// Local options takes precedence over remote options
|
|
476
|
+
const merged = { ...remoteOptions };
|
|
475
477
|
// Handle primitive values
|
|
476
|
-
Object.keys(
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
478
|
+
Object.keys(localOptions).forEach(key => {
|
|
479
|
+
const localValue = localOptions[key];
|
|
480
|
+
if (localValue !== undefined && localValue !== null) {
|
|
481
|
+
if (typeof localValue === 'object' && !Array.isArray(localValue)) {
|
|
482
|
+
// Deep merge objects - local options overrides remote
|
|
480
483
|
merged[key] = {
|
|
481
484
|
...(merged[key] || {}),
|
|
482
|
-
...
|
|
485
|
+
...localValue
|
|
483
486
|
};
|
|
484
487
|
}
|
|
485
488
|
else {
|
|
486
|
-
// Override primitive values and arrays with local
|
|
487
|
-
merged[key] =
|
|
489
|
+
// Override primitive values and arrays with local options
|
|
490
|
+
merged[key] = localValue;
|
|
488
491
|
}
|
|
489
492
|
}
|
|
490
493
|
});
|
|
@@ -588,7 +591,7 @@ class BrowserIdentityManager {
|
|
|
588
591
|
};
|
|
589
592
|
this.saveIdentity();
|
|
590
593
|
}
|
|
591
|
-
identify(distinctId,
|
|
594
|
+
identify(distinctId, _attributes = {}) {
|
|
592
595
|
if (!this.identity)
|
|
593
596
|
return { previousDistinctId: null };
|
|
594
597
|
const previousDistinctId = this.identity.distinct_id;
|
|
@@ -681,113 +684,113 @@ class JourniumClient {
|
|
|
681
684
|
...config,
|
|
682
685
|
apiHost: config.apiHost || 'https://events.journium.app'
|
|
683
686
|
};
|
|
684
|
-
// Generate storage key for
|
|
685
|
-
this.
|
|
687
|
+
// Generate storage key for options caching
|
|
688
|
+
this.optionsStorageKey = `jrnm_${config.publishableKey}_options`;
|
|
686
689
|
// Generate default values
|
|
687
|
-
const
|
|
690
|
+
const defaultOptions = {
|
|
688
691
|
debug: false,
|
|
689
692
|
flushAt: 20,
|
|
690
693
|
flushInterval: 10000,
|
|
691
694
|
sessionTimeout: 30 * 60 * 1000, // 30 minutes
|
|
692
695
|
};
|
|
693
|
-
// Initialize effective
|
|
694
|
-
this.
|
|
695
|
-
if (this.config.
|
|
696
|
-
this.
|
|
696
|
+
// Initialize effective options with local options taking precedence over defaults
|
|
697
|
+
this.effectiveOptions = { ...defaultOptions };
|
|
698
|
+
if (this.config.options) {
|
|
699
|
+
this.effectiveOptions = mergeOptions(defaultOptions, this.config.options);
|
|
697
700
|
}
|
|
698
701
|
// Initialize identity manager
|
|
699
|
-
this.identityManager = new BrowserIdentityManager(this.
|
|
702
|
+
this.identityManager = new BrowserIdentityManager(this.effectiveOptions.sessionTimeout, this.config.publishableKey);
|
|
700
703
|
// Initialize synchronously with cached config, fetch fresh config in background
|
|
701
704
|
this.initializeSync();
|
|
702
|
-
this.
|
|
705
|
+
this.fetchRemoteOptionsAsync();
|
|
703
706
|
}
|
|
704
|
-
|
|
707
|
+
loadCachedOptions() {
|
|
705
708
|
var _a;
|
|
706
709
|
if (typeof window === 'undefined' || !window.localStorage) {
|
|
707
710
|
return null;
|
|
708
711
|
}
|
|
709
712
|
try {
|
|
710
|
-
const cached = window.localStorage.getItem(this.
|
|
713
|
+
const cached = window.localStorage.getItem(this.optionsStorageKey);
|
|
711
714
|
return cached ? JSON.parse(cached) : null;
|
|
712
715
|
}
|
|
713
716
|
catch (error) {
|
|
714
|
-
if ((_a = this.
|
|
717
|
+
if ((_a = this.effectiveOptions) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
715
718
|
console.warn('Journium: Failed to load cached config:', error);
|
|
716
719
|
}
|
|
717
720
|
return null;
|
|
718
721
|
}
|
|
719
722
|
}
|
|
720
|
-
|
|
723
|
+
saveCachedOptions(options) {
|
|
721
724
|
var _a;
|
|
722
725
|
if (typeof window === 'undefined' || !window.localStorage) {
|
|
723
726
|
return;
|
|
724
727
|
}
|
|
725
728
|
try {
|
|
726
|
-
window.localStorage.setItem(this.
|
|
729
|
+
window.localStorage.setItem(this.optionsStorageKey, JSON.stringify(options));
|
|
727
730
|
}
|
|
728
731
|
catch (error) {
|
|
729
|
-
if ((_a = this.
|
|
732
|
+
if ((_a = this.effectiveOptions) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
730
733
|
console.warn('Journium: Failed to save config to cache:', error);
|
|
731
734
|
}
|
|
732
735
|
}
|
|
733
736
|
}
|
|
734
737
|
initializeSync() {
|
|
735
|
-
// Step 1: Load cached remote
|
|
736
|
-
const
|
|
737
|
-
// Step 2: If no local
|
|
738
|
-
if (!this.config.
|
|
739
|
-
this.
|
|
740
|
-
if (this.
|
|
741
|
-
console.log('Journium: Using cached remote
|
|
738
|
+
// Step 1: Load cached remote options from localStorage (synchronous)
|
|
739
|
+
const cachedRemoteOptions = this.loadCachedOptions();
|
|
740
|
+
// Step 2: If no local options provided, use cached remote options
|
|
741
|
+
if (!this.config.options && cachedRemoteOptions) {
|
|
742
|
+
this.effectiveOptions = cachedRemoteOptions;
|
|
743
|
+
if (this.effectiveOptions.debug) {
|
|
744
|
+
console.log('Journium: Using cached remote options:', cachedRemoteOptions);
|
|
742
745
|
}
|
|
743
746
|
}
|
|
744
747
|
// Step 3: Mark as initialized immediately - no need to wait for remote fetch
|
|
745
748
|
this.initialized = true;
|
|
746
749
|
// Step 4: Start flush timer immediately
|
|
747
|
-
if (this.
|
|
750
|
+
if (this.effectiveOptions.flushInterval && this.effectiveOptions.flushInterval > 0) {
|
|
748
751
|
this.startFlushTimer();
|
|
749
752
|
}
|
|
750
|
-
if (this.
|
|
751
|
-
console.log('Journium: Client initialized with effective
|
|
753
|
+
if (this.effectiveOptions.debug) {
|
|
754
|
+
console.log('Journium: Client initialized with effective options:', this.effectiveOptions);
|
|
752
755
|
}
|
|
753
756
|
}
|
|
754
|
-
async
|
|
757
|
+
async fetchRemoteOptionsAsync() {
|
|
755
758
|
// Fetch fresh config in background
|
|
756
759
|
if (this.config.publishableKey) {
|
|
757
|
-
await this.
|
|
760
|
+
await this.fetchAndCacheRemoteOptions();
|
|
758
761
|
}
|
|
759
762
|
}
|
|
760
|
-
async
|
|
763
|
+
async fetchAndCacheRemoteOptions() {
|
|
761
764
|
try {
|
|
762
|
-
if (this.
|
|
765
|
+
if (this.effectiveOptions.debug) {
|
|
763
766
|
console.log('Journium: Fetching remote configuration in background...');
|
|
764
767
|
}
|
|
765
|
-
const
|
|
766
|
-
if (
|
|
768
|
+
const remoteOptionsResponse = await fetchRemoteOptions(this.config.apiHost, this.config.publishableKey);
|
|
769
|
+
if (remoteOptionsResponse && remoteOptionsResponse.success) {
|
|
767
770
|
// Save remote config to cache for next session
|
|
768
|
-
this.
|
|
769
|
-
// Update effective
|
|
770
|
-
if (!this.config.
|
|
771
|
-
// No local
|
|
772
|
-
this.
|
|
771
|
+
this.saveCachedOptions(remoteOptionsResponse.config);
|
|
772
|
+
// Update effective options: local options (if provided) overrides fresh remote options
|
|
773
|
+
if (!this.config.options) {
|
|
774
|
+
// No local options provided, use fresh remote options
|
|
775
|
+
this.effectiveOptions = remoteOptionsResponse.config;
|
|
773
776
|
}
|
|
774
777
|
else {
|
|
775
|
-
// Local
|
|
776
|
-
this.
|
|
778
|
+
// Local options provided, merge it over fresh remote options
|
|
779
|
+
this.effectiveOptions = mergeOptions(remoteOptionsResponse.config, this.config.options);
|
|
777
780
|
}
|
|
778
|
-
// Update session timeout if provided in fresh effective
|
|
779
|
-
if (this.
|
|
780
|
-
this.identityManager.updateSessionTimeout(this.
|
|
781
|
+
// Update session timeout if provided in fresh effective options
|
|
782
|
+
if (this.effectiveOptions.sessionTimeout) {
|
|
783
|
+
this.identityManager.updateSessionTimeout(this.effectiveOptions.sessionTimeout);
|
|
781
784
|
}
|
|
782
|
-
if (this.
|
|
783
|
-
console.log('Journium: Background remote
|
|
784
|
-
console.log('Journium: New effective
|
|
785
|
+
if (this.effectiveOptions.debug) {
|
|
786
|
+
console.log('Journium: Background remote options applied:', remoteOptionsResponse.config);
|
|
787
|
+
console.log('Journium: New effective options:', this.effectiveOptions);
|
|
785
788
|
}
|
|
786
789
|
}
|
|
787
790
|
}
|
|
788
791
|
catch (error) {
|
|
789
|
-
if (this.
|
|
790
|
-
console.warn('Journium: Background remote
|
|
792
|
+
if (this.effectiveOptions.debug) {
|
|
793
|
+
console.warn('Journium: Background remote options fetch failed:', error);
|
|
791
794
|
}
|
|
792
795
|
}
|
|
793
796
|
}
|
|
@@ -798,7 +801,7 @@ class JourniumClient {
|
|
|
798
801
|
// Use universal setInterval (works in both browser and Node.js)
|
|
799
802
|
this.flushTimer = setInterval(() => {
|
|
800
803
|
this.flush();
|
|
801
|
-
}, this.
|
|
804
|
+
}, this.effectiveOptions.flushInterval);
|
|
802
805
|
}
|
|
803
806
|
async sendEvents(events) {
|
|
804
807
|
if (!events.length)
|
|
@@ -817,12 +820,12 @@ class JourniumClient {
|
|
|
817
820
|
if (!response.ok) {
|
|
818
821
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
819
822
|
}
|
|
820
|
-
if (this.
|
|
823
|
+
if (this.effectiveOptions.debug) {
|
|
821
824
|
console.log('Journium: Successfully sent events', events);
|
|
822
825
|
}
|
|
823
826
|
}
|
|
824
827
|
catch (error) {
|
|
825
|
-
if (this.
|
|
828
|
+
if (this.effectiveOptions.debug) {
|
|
826
829
|
console.error('Journium: Failed to send events', error);
|
|
827
830
|
}
|
|
828
831
|
throw error;
|
|
@@ -832,7 +835,7 @@ class JourniumClient {
|
|
|
832
835
|
var _a;
|
|
833
836
|
// Don't identify if SDK is not properly configured
|
|
834
837
|
if (!this.config || !this.config.publishableKey || !this.initialized) {
|
|
835
|
-
if ((_a = this.
|
|
838
|
+
if ((_a = this.effectiveOptions) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
836
839
|
console.warn('Journium: identify() call rejected - SDK not ready');
|
|
837
840
|
}
|
|
838
841
|
return;
|
|
@@ -845,7 +848,7 @@ class JourniumClient {
|
|
|
845
848
|
$anon_distinct_id: previousDistinctId,
|
|
846
849
|
};
|
|
847
850
|
this.track('$identify', identifyProperties);
|
|
848
|
-
if (this.
|
|
851
|
+
if (this.effectiveOptions.debug) {
|
|
849
852
|
console.log('Journium: User identified', { distinctId, attributes, previousDistinctId });
|
|
850
853
|
}
|
|
851
854
|
}
|
|
@@ -853,14 +856,14 @@ class JourniumClient {
|
|
|
853
856
|
var _a;
|
|
854
857
|
// Don't reset if SDK is not properly configured
|
|
855
858
|
if (!this.config || !this.config.publishableKey || !this.initialized) {
|
|
856
|
-
if ((_a = this.
|
|
859
|
+
if ((_a = this.effectiveOptions) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
857
860
|
console.warn('Journium: reset() call rejected - SDK not ready');
|
|
858
861
|
}
|
|
859
862
|
return;
|
|
860
863
|
}
|
|
861
864
|
// Reset identity in identity manager
|
|
862
865
|
this.identityManager.reset();
|
|
863
|
-
if (this.
|
|
866
|
+
if (this.effectiveOptions.debug) {
|
|
864
867
|
console.log('Journium: User identity reset');
|
|
865
868
|
}
|
|
866
869
|
}
|
|
@@ -868,7 +871,7 @@ class JourniumClient {
|
|
|
868
871
|
var _a;
|
|
869
872
|
// Don't track if SDK is not properly configured
|
|
870
873
|
if (!this.config || !this.config.publishableKey || !this.initialized) {
|
|
871
|
-
if ((_a = this.
|
|
874
|
+
if ((_a = this.effectiveOptions) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
872
875
|
console.warn('Journium: track() call rejected - SDK not ready');
|
|
873
876
|
}
|
|
874
877
|
return;
|
|
@@ -896,10 +899,10 @@ class JourniumClient {
|
|
|
896
899
|
properties: eventProperties,
|
|
897
900
|
};
|
|
898
901
|
this.queue.push(journiumEvent);
|
|
899
|
-
if (this.
|
|
902
|
+
if (this.effectiveOptions.debug) {
|
|
900
903
|
console.log('Journium: Event tracked', journiumEvent);
|
|
901
904
|
}
|
|
902
|
-
if (this.queue.length >= this.
|
|
905
|
+
if (this.queue.length >= this.effectiveOptions.flushAt) {
|
|
903
906
|
this.flush();
|
|
904
907
|
}
|
|
905
908
|
}
|
|
@@ -927,6 +930,9 @@ class JourniumClient {
|
|
|
927
930
|
}
|
|
928
931
|
this.flush();
|
|
929
932
|
}
|
|
933
|
+
getEffectiveOptions() {
|
|
934
|
+
return this.effectiveOptions;
|
|
935
|
+
}
|
|
930
936
|
}
|
|
931
937
|
|
|
932
938
|
class PageviewTracker {
|
|
@@ -992,11 +998,11 @@ class PageviewTracker {
|
|
|
992
998
|
}
|
|
993
999
|
|
|
994
1000
|
class AutocaptureTracker {
|
|
995
|
-
constructor(client,
|
|
1001
|
+
constructor(client, options = {}) {
|
|
996
1002
|
this.listeners = new Map();
|
|
997
1003
|
this.isActive = false;
|
|
998
1004
|
this.client = client;
|
|
999
|
-
this.
|
|
1005
|
+
this.options = {
|
|
1000
1006
|
captureClicks: true,
|
|
1001
1007
|
captureFormSubmits: true,
|
|
1002
1008
|
captureFormChanges: true,
|
|
@@ -1004,7 +1010,7 @@ class AutocaptureTracker {
|
|
|
1004
1010
|
ignoreClasses: ['journium-ignore'],
|
|
1005
1011
|
ignoreElements: ['script', 'style', 'noscript'],
|
|
1006
1012
|
captureContentText: true,
|
|
1007
|
-
...
|
|
1013
|
+
...options,
|
|
1008
1014
|
};
|
|
1009
1015
|
}
|
|
1010
1016
|
start() {
|
|
@@ -1012,16 +1018,16 @@ class AutocaptureTracker {
|
|
|
1012
1018
|
return;
|
|
1013
1019
|
}
|
|
1014
1020
|
this.isActive = true;
|
|
1015
|
-
if (this.
|
|
1021
|
+
if (this.options.captureClicks) {
|
|
1016
1022
|
this.addClickListener();
|
|
1017
1023
|
}
|
|
1018
|
-
if (this.
|
|
1024
|
+
if (this.options.captureFormSubmits) {
|
|
1019
1025
|
this.addFormSubmitListener();
|
|
1020
1026
|
}
|
|
1021
|
-
if (this.
|
|
1027
|
+
if (this.options.captureFormChanges) {
|
|
1022
1028
|
this.addFormChangeListener();
|
|
1023
1029
|
}
|
|
1024
|
-
if (this.
|
|
1030
|
+
if (this.options.captureTextSelection) {
|
|
1025
1031
|
this.addTextSelectionListener();
|
|
1026
1032
|
}
|
|
1027
1033
|
}
|
|
@@ -1105,17 +1111,17 @@ class AutocaptureTracker {
|
|
|
1105
1111
|
return true;
|
|
1106
1112
|
}
|
|
1107
1113
|
// Check if element should be ignored by tag name
|
|
1108
|
-
if ((_a = this.
|
|
1114
|
+
if ((_a = this.options.ignoreElements) === null || _a === void 0 ? void 0 : _a.includes(element.tagName.toLowerCase())) {
|
|
1109
1115
|
return true;
|
|
1110
1116
|
}
|
|
1111
1117
|
// Check if element has ignore classes
|
|
1112
|
-
if ((_b = this.
|
|
1118
|
+
if ((_b = this.options.ignoreClasses) === null || _b === void 0 ? void 0 : _b.some(cls => element.classList.contains(cls))) {
|
|
1113
1119
|
return true;
|
|
1114
1120
|
}
|
|
1115
1121
|
// Check parent elements for ignore classes
|
|
1116
1122
|
let parent = element.parentElement;
|
|
1117
1123
|
while (parent) {
|
|
1118
|
-
if ((_c = this.
|
|
1124
|
+
if ((_c = this.options.ignoreClasses) === null || _c === void 0 ? void 0 : _c.some(cls => parent.classList.contains(cls))) {
|
|
1119
1125
|
return true;
|
|
1120
1126
|
}
|
|
1121
1127
|
parent = parent.parentElement;
|
|
@@ -1147,7 +1153,7 @@ class AutocaptureTracker {
|
|
|
1147
1153
|
}
|
|
1148
1154
|
});
|
|
1149
1155
|
// Element content
|
|
1150
|
-
if (this.
|
|
1156
|
+
if (this.options.captureContentText) {
|
|
1151
1157
|
const text = this.getElementText(element);
|
|
1152
1158
|
if (text) {
|
|
1153
1159
|
properties.$element_text = text.substring(0, 200); // Limit text length
|
|
@@ -1334,18 +1340,18 @@ class AutocaptureTracker {
|
|
|
1334
1340
|
}
|
|
1335
1341
|
}
|
|
1336
1342
|
|
|
1337
|
-
class
|
|
1343
|
+
class JourniumAnalytics {
|
|
1338
1344
|
constructor(config) {
|
|
1339
1345
|
var _a, _b;
|
|
1340
1346
|
this.config = config;
|
|
1341
1347
|
this.client = new JourniumClient(config);
|
|
1342
1348
|
this.pageviewTracker = new PageviewTracker(this.client);
|
|
1343
|
-
const
|
|
1344
|
-
this.autocaptureTracker = new AutocaptureTracker(this.client,
|
|
1349
|
+
const autocaptureOptions = this.resolveAutocaptureOptions((_a = config.options) === null || _a === void 0 ? void 0 : _a.autocapture);
|
|
1350
|
+
this.autocaptureTracker = new AutocaptureTracker(this.client, autocaptureOptions);
|
|
1345
1351
|
// Store resolved autocapture state for startAutocapture method
|
|
1346
|
-
this.autocaptureEnabled = ((_b = config.
|
|
1352
|
+
this.autocaptureEnabled = ((_b = config.options) === null || _b === void 0 ? void 0 : _b.autocapture) !== false;
|
|
1347
1353
|
}
|
|
1348
|
-
|
|
1354
|
+
resolveAutocaptureOptions(autocapture) {
|
|
1349
1355
|
if (autocapture === false) {
|
|
1350
1356
|
return {
|
|
1351
1357
|
captureClicks: false,
|
|
@@ -1372,7 +1378,12 @@ class Journium {
|
|
|
1372
1378
|
this.pageviewTracker.capturePageview(properties);
|
|
1373
1379
|
}
|
|
1374
1380
|
startAutocapture() {
|
|
1375
|
-
|
|
1381
|
+
// Check if automatic pageview tracking is enabled (defaults to true)
|
|
1382
|
+
const effectiveOptions = this.client.getEffectiveOptions();
|
|
1383
|
+
const autoTrackPageviews = effectiveOptions.autoTrackPageviews !== false;
|
|
1384
|
+
if (autoTrackPageviews) {
|
|
1385
|
+
this.pageviewTracker.startAutocapture();
|
|
1386
|
+
}
|
|
1376
1387
|
if (this.autocaptureEnabled) {
|
|
1377
1388
|
this.autocaptureTracker.start();
|
|
1378
1389
|
}
|
|
@@ -1384,6 +1395,9 @@ class Journium {
|
|
|
1384
1395
|
async flush() {
|
|
1385
1396
|
return this.client.flush();
|
|
1386
1397
|
}
|
|
1398
|
+
getEffectiveOptions() {
|
|
1399
|
+
return this.client.getEffectiveOptions();
|
|
1400
|
+
}
|
|
1387
1401
|
destroy() {
|
|
1388
1402
|
this.pageviewTracker.stopAutocapture();
|
|
1389
1403
|
this.autocaptureTracker.stop();
|
|
@@ -1391,32 +1405,33 @@ class Journium {
|
|
|
1391
1405
|
}
|
|
1392
1406
|
}
|
|
1393
1407
|
const init = (config) => {
|
|
1394
|
-
return new
|
|
1408
|
+
return new JourniumAnalytics(config);
|
|
1395
1409
|
};
|
|
1396
1410
|
|
|
1397
|
-
const JourniumContext = createContext({
|
|
1411
|
+
const JourniumContext = React.createContext({ analytics: null, config: null, effectiveOptions: null });
|
|
1398
1412
|
const JourniumProvider = ({ children, config, }) => {
|
|
1399
|
-
const [
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
const
|
|
1403
|
-
//
|
|
1404
|
-
const
|
|
1413
|
+
const [analytics, setAnalytics] = React.useState(null);
|
|
1414
|
+
const [effectiveOptions, setEffectiveOptions] = React.useState(null);
|
|
1415
|
+
React.useEffect(() => {
|
|
1416
|
+
const analyticsInstance = new JourniumAnalytics(config);
|
|
1417
|
+
// Get effective options and check if autocapture is enabled
|
|
1418
|
+
const effective = analyticsInstance.getEffectiveOptions();
|
|
1419
|
+
setEffectiveOptions(effective);
|
|
1420
|
+
const autocaptureEnabled = effective.autocapture !== false;
|
|
1405
1421
|
if (autocaptureEnabled) {
|
|
1406
|
-
|
|
1422
|
+
analyticsInstance.startAutocapture();
|
|
1407
1423
|
}
|
|
1408
|
-
|
|
1424
|
+
setAnalytics(analyticsInstance);
|
|
1409
1425
|
return () => {
|
|
1410
|
-
|
|
1411
|
-
|
|
1426
|
+
analyticsInstance.destroy();
|
|
1427
|
+
setAnalytics(null);
|
|
1428
|
+
setEffectiveOptions(null);
|
|
1412
1429
|
};
|
|
1413
1430
|
}, [config]);
|
|
1414
|
-
|
|
1415
|
-
// When autocapture=false, users should call capturePageview() manually as needed
|
|
1416
|
-
return (React.createElement(JourniumContext.Provider, { value: { journium } }, children));
|
|
1431
|
+
return (React.createElement(JourniumContext.Provider, { value: { analytics, config, effectiveOptions } }, children));
|
|
1417
1432
|
};
|
|
1418
1433
|
const useJournium = () => {
|
|
1419
|
-
const context = useContext(JourniumContext);
|
|
1434
|
+
const context = React.useContext(JourniumContext);
|
|
1420
1435
|
if (!context) {
|
|
1421
1436
|
throw new Error('useJournium must be used within a JourniumProvider');
|
|
1422
1437
|
}
|
|
@@ -1424,57 +1439,80 @@ const useJournium = () => {
|
|
|
1424
1439
|
};
|
|
1425
1440
|
|
|
1426
1441
|
const useTrackEvent = () => {
|
|
1427
|
-
const {
|
|
1428
|
-
return useCallback((event, properties) => {
|
|
1429
|
-
if (
|
|
1430
|
-
|
|
1442
|
+
const { analytics } = useJournium();
|
|
1443
|
+
return React.useCallback((event, properties) => {
|
|
1444
|
+
if (analytics) {
|
|
1445
|
+
analytics.track(event, properties);
|
|
1431
1446
|
}
|
|
1432
|
-
}, [
|
|
1447
|
+
}, [analytics]);
|
|
1433
1448
|
};
|
|
1434
1449
|
const useIdentify = () => {
|
|
1435
|
-
const {
|
|
1436
|
-
return useCallback((distinctId, attributes) => {
|
|
1437
|
-
if (
|
|
1438
|
-
|
|
1450
|
+
const { analytics } = useJournium();
|
|
1451
|
+
return React.useCallback((distinctId, attributes) => {
|
|
1452
|
+
if (analytics) {
|
|
1453
|
+
analytics.identify(distinctId, attributes);
|
|
1439
1454
|
}
|
|
1440
|
-
}, [
|
|
1455
|
+
}, [analytics]);
|
|
1441
1456
|
};
|
|
1442
1457
|
const useReset = () => {
|
|
1443
|
-
const {
|
|
1444
|
-
return useCallback(() => {
|
|
1445
|
-
if (
|
|
1446
|
-
|
|
1458
|
+
const { analytics } = useJournium();
|
|
1459
|
+
return React.useCallback(() => {
|
|
1460
|
+
if (analytics) {
|
|
1461
|
+
analytics.reset();
|
|
1447
1462
|
}
|
|
1448
|
-
}, [
|
|
1463
|
+
}, [analytics]);
|
|
1449
1464
|
};
|
|
1450
1465
|
const useTrackPageview = () => {
|
|
1451
|
-
const {
|
|
1452
|
-
return useCallback((properties) => {
|
|
1453
|
-
if (
|
|
1454
|
-
|
|
1466
|
+
const { analytics } = useJournium();
|
|
1467
|
+
return React.useCallback((properties) => {
|
|
1468
|
+
if (analytics) {
|
|
1469
|
+
analytics.capturePageview(properties);
|
|
1455
1470
|
}
|
|
1456
|
-
}, [
|
|
1471
|
+
}, [analytics]);
|
|
1457
1472
|
};
|
|
1458
1473
|
const useAutoTrackPageview = (dependencies = [], properties) => {
|
|
1459
1474
|
const trackPageview = useTrackPageview();
|
|
1460
|
-
useEffect(() => {
|
|
1475
|
+
React.useEffect(() => {
|
|
1461
1476
|
trackPageview(properties);
|
|
1462
|
-
}, dependencies);
|
|
1477
|
+
}, [trackPageview, properties, ...dependencies]);
|
|
1463
1478
|
};
|
|
1464
1479
|
const useAutocapture = () => {
|
|
1465
|
-
const {
|
|
1466
|
-
const startAutocapture = useCallback(() => {
|
|
1467
|
-
if (
|
|
1468
|
-
|
|
1480
|
+
const { analytics } = useJournium();
|
|
1481
|
+
const startAutocapture = React.useCallback(() => {
|
|
1482
|
+
if (analytics) {
|
|
1483
|
+
analytics.startAutocapture();
|
|
1469
1484
|
}
|
|
1470
|
-
}, [
|
|
1471
|
-
const stopAutocapture = useCallback(() => {
|
|
1472
|
-
if (
|
|
1473
|
-
|
|
1485
|
+
}, [analytics]);
|
|
1486
|
+
const stopAutocapture = React.useCallback(() => {
|
|
1487
|
+
if (analytics) {
|
|
1488
|
+
analytics.stopAutocapture();
|
|
1474
1489
|
}
|
|
1475
|
-
}, [
|
|
1490
|
+
}, [analytics]);
|
|
1476
1491
|
return { startAutocapture, stopAutocapture };
|
|
1477
1492
|
};
|
|
1478
1493
|
|
|
1479
|
-
|
|
1480
|
-
|
|
1494
|
+
exports.AutocaptureTracker = AutocaptureTracker;
|
|
1495
|
+
exports.BrowserIdentityManager = BrowserIdentityManager;
|
|
1496
|
+
exports.JourniumAnalytics = JourniumAnalytics;
|
|
1497
|
+
exports.JourniumClient = JourniumClient;
|
|
1498
|
+
exports.JourniumProvider = JourniumProvider;
|
|
1499
|
+
exports.PageviewTracker = PageviewTracker;
|
|
1500
|
+
exports.fetchRemoteOptions = fetchRemoteOptions;
|
|
1501
|
+
exports.generateId = generateId;
|
|
1502
|
+
exports.generateUuidv7 = generateUuidv7;
|
|
1503
|
+
exports.getCurrentTimestamp = getCurrentTimestamp;
|
|
1504
|
+
exports.getCurrentUrl = getCurrentUrl;
|
|
1505
|
+
exports.getPageTitle = getPageTitle;
|
|
1506
|
+
exports.getReferrer = getReferrer;
|
|
1507
|
+
exports.init = init;
|
|
1508
|
+
exports.isBrowser = isBrowser;
|
|
1509
|
+
exports.isNode = isNode;
|
|
1510
|
+
exports.mergeOptions = mergeOptions;
|
|
1511
|
+
exports.useAutoTrackPageview = useAutoTrackPageview;
|
|
1512
|
+
exports.useAutocapture = useAutocapture;
|
|
1513
|
+
exports.useIdentify = useIdentify;
|
|
1514
|
+
exports.useJournium = useJournium;
|
|
1515
|
+
exports.useReset = useReset;
|
|
1516
|
+
exports.useTrackEvent = useTrackEvent;
|
|
1517
|
+
exports.useTrackPageview = useTrackPageview;
|
|
1518
|
+
//# sourceMappingURL=index.cjs.map
|