@journium/js 1.2.1 → 1.2.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/README.md +1 -0
- package/dist/JourniumAnalytics.d.ts +15 -0
- package/dist/JourniumAnalytics.d.ts.map +1 -1
- package/dist/PageviewTracker.d.ts +3 -1
- package/dist/PageviewTracker.d.ts.map +1 -1
- package/dist/index.cjs +59 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +18 -1
- package/dist/index.mjs +59 -27
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +59 -27
- package/dist/index.umd.js.map +1 -1
- package/dist/journium.js +59 -27
- package/dist/journium.js.map +1 -1
- package/dist/journium.min.js +1 -1
- package/dist/journium.min.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -91,6 +91,7 @@ journium.identify('user123', {
|
|
|
91
91
|
|
|
92
92
|
- [@journium/nextjs](https://www.npmjs.com/package/@journium/nextjs) - Next.js SDK
|
|
93
93
|
- [@journium/react](https://www.npmjs.com/package/@journium/react) - React SDK
|
|
94
|
+
- [@journium/angular](https://www.npmjs.com/package/@journium/angular) - Angular SDK
|
|
94
95
|
|
|
95
96
|
## Support
|
|
96
97
|
|
|
@@ -7,12 +7,23 @@ export declare class JourniumAnalytics {
|
|
|
7
7
|
private autocaptureStarted;
|
|
8
8
|
private unsubscribeOptionsChange?;
|
|
9
9
|
constructor(config: JourniumConfig);
|
|
10
|
+
private resolvePageviewOptions;
|
|
10
11
|
private resolveAutocaptureOptions;
|
|
12
|
+
/** Track a custom event with optional properties. */
|
|
11
13
|
track(event: string, properties?: Record<string, unknown>): void;
|
|
14
|
+
/** Associate the current session with a known user identity and optional attributes. */
|
|
12
15
|
identify(distinctId: string, attributes?: Record<string, unknown>): void;
|
|
16
|
+
/** Clear the current identity, starting a new anonymous session. */
|
|
13
17
|
reset(): void;
|
|
18
|
+
/** Manually capture a $pageview event with optional custom properties. */
|
|
14
19
|
capturePageview(properties?: Record<string, unknown>): void;
|
|
20
|
+
/**
|
|
21
|
+
* Manually start autocapture (pageview tracking + DOM event capture).
|
|
22
|
+
* Under normal usage this is not needed — the SDK starts automatically on init.
|
|
23
|
+
* Useful only if autocapture was explicitly stopped and needs to be restarted.
|
|
24
|
+
*/
|
|
15
25
|
startAutocapture(): void;
|
|
26
|
+
/** Stop autocapture — pauses pageview tracking and DOM event capture. */
|
|
16
27
|
stopAutocapture(): void;
|
|
17
28
|
/**
|
|
18
29
|
* Automatically start autocapture if enabled in options
|
|
@@ -23,14 +34,18 @@ export declare class JourniumAnalytics {
|
|
|
23
34
|
* Handle effective options change (e.g., when remote options are fetched)
|
|
24
35
|
*/
|
|
25
36
|
private handleOptionsChange;
|
|
37
|
+
/** Flush all queued events to the ingestion endpoint immediately. */
|
|
26
38
|
flush(): Promise<void>;
|
|
39
|
+
/** Return the currently active options (merged local + remote config). */
|
|
27
40
|
getEffectiveOptions(): JourniumLocalOptions;
|
|
28
41
|
/**
|
|
29
42
|
* Register a callback to be notified when effective options change
|
|
30
43
|
*/
|
|
31
44
|
onOptionsChange(callback: (options: JourniumLocalOptions) => void): () => void;
|
|
45
|
+
/** Tear down the analytics instance: stop all tracking, flush pending events, and release resources. */
|
|
32
46
|
destroy(): void;
|
|
33
47
|
}
|
|
48
|
+
/** Create and return a new JourniumAnalytics instance for the given config. */
|
|
34
49
|
export declare const init: (config: JourniumConfig) => JourniumAnalytics;
|
|
35
50
|
declare const _default: {
|
|
36
51
|
init: (config: JourniumConfig) => JourniumAnalytics;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JourniumAnalytics.d.ts","sourceRoot":"","sources":["../src/JourniumAnalytics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"JourniumAnalytics.d.ts","sourceRoot":"","sources":["../src/JourniumAnalytics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAiD,oBAAoB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iBAAiB;;AAI/D,wBAAwB"}
|
|
@@ -11,8 +11,10 @@ export declare class PageviewTracker {
|
|
|
11
11
|
* Start automatic autocapture for pageviews
|
|
12
12
|
* @param captureInitialPageview - whether to fire a $pageview immediately on start (default: true).
|
|
13
13
|
* Pass false when restarting after a remote options update to avoid a spurious pageview.
|
|
14
|
+
* @param patchHistory - whether to monkey-patch pushState/replaceState/popstate (default: true).
|
|
15
|
+
* Pass false when a framework-native router tracker (e.g. Next.js) owns SPA pageviews.
|
|
14
16
|
*/
|
|
15
|
-
startAutoPageviewTracking(captureInitialPageview?: boolean): void;
|
|
17
|
+
startAutoPageviewTracking(captureInitialPageview?: boolean, patchHistory?: boolean): void;
|
|
16
18
|
/**
|
|
17
19
|
* Stop automatic autocapture for pageviews
|
|
18
20
|
* @returns void
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PageviewTracker.d.ts","sourceRoot":"","sources":["../src/PageviewTracker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,iBAAiB,CAAgD;IACzE,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,eAAe,CAA6B;gBAExC,MAAM,EAAE,cAAc;IAIlC,eAAe,CAAC,gBAAgB,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,IAAI;IAkBrE
|
|
1
|
+
{"version":3,"file":"PageviewTracker.d.ts","sourceRoot":"","sources":["../src/PageviewTracker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,iBAAiB,CAAgD;IACzE,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,eAAe,CAA6B;gBAExC,MAAM,EAAE,cAAc;IAIlC,eAAe,CAAC,gBAAgB,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,IAAI;IAkBrE;;;;;;OAMG;IACH,yBAAyB,CAAC,sBAAsB,GAAE,OAAc,EAAE,YAAY,GAAE,OAAc,GAAG,IAAI;IA8BrG;;;OAGG;IACH,eAAe,IAAI,IAAI;CAmBxB"}
|
package/dist/index.cjs
CHANGED
|
@@ -1102,28 +1102,31 @@ class PageviewTracker {
|
|
|
1102
1102
|
* Start automatic autocapture for pageviews
|
|
1103
1103
|
* @param captureInitialPageview - whether to fire a $pageview immediately on start (default: true).
|
|
1104
1104
|
* Pass false when restarting after a remote options update to avoid a spurious pageview.
|
|
1105
|
+
* @param patchHistory - whether to monkey-patch pushState/replaceState/popstate (default: true).
|
|
1106
|
+
* Pass false when a framework-native router tracker (e.g. Next.js) owns SPA pageviews.
|
|
1105
1107
|
*/
|
|
1106
|
-
startAutoPageviewTracking(captureInitialPageview = true) {
|
|
1108
|
+
startAutoPageviewTracking(captureInitialPageview = true, patchHistory = true) {
|
|
1107
1109
|
if (captureInitialPageview) {
|
|
1108
1110
|
this.capturePageview();
|
|
1109
1111
|
}
|
|
1110
|
-
if (typeof window
|
|
1111
|
-
|
|
1112
|
-
this.originalPushState = window.history.pushState;
|
|
1113
|
-
this.originalReplaceState = window.history.replaceState;
|
|
1114
|
-
window.history.pushState = (...args) => {
|
|
1115
|
-
this.originalPushState.apply(window.history, args);
|
|
1116
|
-
setTimeout(() => this.capturePageview(), 0);
|
|
1117
|
-
};
|
|
1118
|
-
window.history.replaceState = (...args) => {
|
|
1119
|
-
this.originalReplaceState.apply(window.history, args);
|
|
1120
|
-
setTimeout(() => this.capturePageview(), 0);
|
|
1121
|
-
};
|
|
1122
|
-
this.popStateHandler = () => {
|
|
1123
|
-
setTimeout(() => this.capturePageview(), 0);
|
|
1124
|
-
};
|
|
1125
|
-
window.addEventListener('popstate', this.popStateHandler);
|
|
1112
|
+
if (!patchHistory || typeof window === 'undefined') {
|
|
1113
|
+
return;
|
|
1126
1114
|
}
|
|
1115
|
+
// Store original methods for cleanup
|
|
1116
|
+
this.originalPushState = window.history.pushState;
|
|
1117
|
+
this.originalReplaceState = window.history.replaceState;
|
|
1118
|
+
window.history.pushState = (...args) => {
|
|
1119
|
+
this.originalPushState.apply(window.history, args);
|
|
1120
|
+
setTimeout(() => this.capturePageview(), 0);
|
|
1121
|
+
};
|
|
1122
|
+
window.history.replaceState = (...args) => {
|
|
1123
|
+
this.originalReplaceState.apply(window.history, args);
|
|
1124
|
+
setTimeout(() => this.capturePageview(), 0);
|
|
1125
|
+
};
|
|
1126
|
+
this.popStateHandler = () => {
|
|
1127
|
+
setTimeout(() => this.capturePageview(), 0);
|
|
1128
|
+
};
|
|
1129
|
+
window.addEventListener('popstate', this.popStateHandler);
|
|
1127
1130
|
}
|
|
1128
1131
|
/**
|
|
1129
1132
|
* Stop automatic autocapture for pageviews
|
|
@@ -1538,6 +1541,20 @@ class JourniumAnalytics {
|
|
|
1538
1541
|
// This handles cached remote options or local options with autocapture enabled
|
|
1539
1542
|
this.startAutocaptureIfEnabled(initialEffectiveOptions);
|
|
1540
1543
|
}
|
|
1544
|
+
resolvePageviewOptions(autoTrackPageviews, frameworkHandlesPageviews) {
|
|
1545
|
+
if (autoTrackPageviews === false || frameworkHandlesPageviews) {
|
|
1546
|
+
return { enabled: false, trackSpaPageviews: false, captureInitialPageview: false };
|
|
1547
|
+
}
|
|
1548
|
+
if (autoTrackPageviews === true || autoTrackPageviews === undefined) {
|
|
1549
|
+
return { enabled: true, trackSpaPageviews: true, captureInitialPageview: true };
|
|
1550
|
+
}
|
|
1551
|
+
// object form implies enabled
|
|
1552
|
+
return {
|
|
1553
|
+
enabled: true,
|
|
1554
|
+
trackSpaPageviews: autoTrackPageviews.trackSpaPageviews !== false,
|
|
1555
|
+
captureInitialPageview: autoTrackPageviews.trackInitialPageview !== false,
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1541
1558
|
resolveAutocaptureOptions(autocapture) {
|
|
1542
1559
|
if (autocapture === false) {
|
|
1543
1560
|
return {
|
|
@@ -1552,39 +1569,50 @@ class JourniumAnalytics {
|
|
|
1552
1569
|
}
|
|
1553
1570
|
return autocapture;
|
|
1554
1571
|
}
|
|
1572
|
+
/** Track a custom event with optional properties. */
|
|
1555
1573
|
track(event, properties) {
|
|
1556
1574
|
this.client.track(event, properties);
|
|
1557
1575
|
}
|
|
1576
|
+
/** Associate the current session with a known user identity and optional attributes. */
|
|
1558
1577
|
identify(distinctId, attributes) {
|
|
1559
1578
|
this.client.identify(distinctId, attributes);
|
|
1560
1579
|
}
|
|
1580
|
+
/** Clear the current identity, starting a new anonymous session. */
|
|
1561
1581
|
reset() {
|
|
1562
1582
|
this.client.reset();
|
|
1563
1583
|
}
|
|
1584
|
+
/** Manually capture a $pageview event with optional custom properties. */
|
|
1564
1585
|
capturePageview(properties) {
|
|
1565
1586
|
this.pageviewTracker.capturePageview(properties);
|
|
1566
1587
|
}
|
|
1588
|
+
/**
|
|
1589
|
+
* Manually start autocapture (pageview tracking + DOM event capture).
|
|
1590
|
+
* Under normal usage this is not needed — the SDK starts automatically on init.
|
|
1591
|
+
* Useful only if autocapture was explicitly stopped and needs to be restarted.
|
|
1592
|
+
*/
|
|
1567
1593
|
startAutocapture() {
|
|
1568
1594
|
// Always check effective options (which may include remote options)
|
|
1569
1595
|
const effectiveOptions = this.client.getEffectiveOptions();
|
|
1570
|
-
// Only
|
|
1571
|
-
const
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1596
|
+
// Only start if effectiveOptions are actually loaded (non-empty)
|
|
1597
|
+
const hasOptions = effectiveOptions && Object.keys(effectiveOptions).length > 0;
|
|
1598
|
+
const { enabled: autoTrackPageviews, trackSpaPageviews, captureInitialPageview } = hasOptions
|
|
1599
|
+
? this.resolvePageviewOptions(effectiveOptions.autoTrackPageviews, effectiveOptions._frameworkHandlesPageviews)
|
|
1600
|
+
: { enabled: false, trackSpaPageviews: false, captureInitialPageview: false };
|
|
1601
|
+
const autocaptureEnabled = hasOptions
|
|
1575
1602
|
? effectiveOptions.autocapture !== false
|
|
1576
1603
|
: false;
|
|
1577
1604
|
// Update autocapture tracker options if they've changed
|
|
1578
1605
|
const autocaptureOptions = this.resolveAutocaptureOptions(effectiveOptions.autocapture);
|
|
1579
1606
|
this.autocaptureTracker.updateOptions(autocaptureOptions);
|
|
1580
1607
|
if (autoTrackPageviews) {
|
|
1581
|
-
this.pageviewTracker.startAutoPageviewTracking();
|
|
1608
|
+
this.pageviewTracker.startAutoPageviewTracking(captureInitialPageview, trackSpaPageviews);
|
|
1582
1609
|
}
|
|
1583
1610
|
if (autocaptureEnabled) {
|
|
1584
1611
|
this.autocaptureTracker.start();
|
|
1585
1612
|
}
|
|
1586
1613
|
this.autocaptureStarted = true;
|
|
1587
1614
|
}
|
|
1615
|
+
/** Stop autocapture — pauses pageview tracking and DOM event capture. */
|
|
1588
1616
|
stopAutocapture() {
|
|
1589
1617
|
this.pageviewTracker.stopAutocapture();
|
|
1590
1618
|
this.autocaptureTracker.stop();
|
|
@@ -1604,13 +1632,13 @@ class JourniumAnalytics {
|
|
|
1604
1632
|
const hasActualOptions = effectiveOptions && Object.keys(effectiveOptions).length > 0;
|
|
1605
1633
|
if (hasActualOptions) {
|
|
1606
1634
|
// Use same logic as manual startAutocapture() but only start automatically
|
|
1607
|
-
const autoTrackPageviews = effectiveOptions.autoTrackPageviews
|
|
1635
|
+
const { enabled: autoTrackPageviews, trackSpaPageviews, captureInitialPageview } = this.resolvePageviewOptions(effectiveOptions.autoTrackPageviews, effectiveOptions._frameworkHandlesPageviews);
|
|
1608
1636
|
const autocaptureEnabled = effectiveOptions.autocapture !== false;
|
|
1609
1637
|
// Update autocapture tracker options
|
|
1610
1638
|
const autocaptureOptions = this.resolveAutocaptureOptions(effectiveOptions.autocapture);
|
|
1611
1639
|
this.autocaptureTracker.updateOptions(autocaptureOptions);
|
|
1612
1640
|
if (autoTrackPageviews) {
|
|
1613
|
-
this.pageviewTracker.startAutoPageviewTracking();
|
|
1641
|
+
this.pageviewTracker.startAutoPageviewTracking(captureInitialPageview, trackSpaPageviews);
|
|
1614
1642
|
}
|
|
1615
1643
|
if (autocaptureEnabled) {
|
|
1616
1644
|
this.autocaptureTracker.start();
|
|
@@ -1635,21 +1663,23 @@ class JourniumAnalytics {
|
|
|
1635
1663
|
this.autocaptureTracker.stop();
|
|
1636
1664
|
this.autocaptureStarted = false;
|
|
1637
1665
|
}
|
|
1638
|
-
const autoTrackPageviews = effectiveOptions.autoTrackPageviews
|
|
1666
|
+
const { enabled: autoTrackPageviews, trackSpaPageviews, captureInitialPageview } = this.resolvePageviewOptions(effectiveOptions.autoTrackPageviews, effectiveOptions._frameworkHandlesPageviews);
|
|
1639
1667
|
const autocaptureEnabled = effectiveOptions.autocapture !== false;
|
|
1640
1668
|
const autocaptureOptions = this.resolveAutocaptureOptions(effectiveOptions.autocapture);
|
|
1641
1669
|
this.autocaptureTracker.updateOptions(autocaptureOptions);
|
|
1642
1670
|
if (autoTrackPageviews) {
|
|
1643
|
-
this.pageviewTracker.startAutoPageviewTracking(isFirstStart);
|
|
1671
|
+
this.pageviewTracker.startAutoPageviewTracking(isFirstStart && captureInitialPageview, trackSpaPageviews);
|
|
1644
1672
|
}
|
|
1645
1673
|
if (autocaptureEnabled) {
|
|
1646
1674
|
this.autocaptureTracker.start();
|
|
1647
1675
|
}
|
|
1648
1676
|
this.autocaptureStarted = autoTrackPageviews || autocaptureEnabled;
|
|
1649
1677
|
}
|
|
1678
|
+
/** Flush all queued events to the ingestion endpoint immediately. */
|
|
1650
1679
|
async flush() {
|
|
1651
1680
|
return this.client.flush();
|
|
1652
1681
|
}
|
|
1682
|
+
/** Return the currently active options (merged local + remote config). */
|
|
1653
1683
|
getEffectiveOptions() {
|
|
1654
1684
|
return this.client.getEffectiveOptions();
|
|
1655
1685
|
}
|
|
@@ -1659,6 +1689,7 @@ class JourniumAnalytics {
|
|
|
1659
1689
|
onOptionsChange(callback) {
|
|
1660
1690
|
return this.client.onOptionsChange(callback);
|
|
1661
1691
|
}
|
|
1692
|
+
/** Tear down the analytics instance: stop all tracking, flush pending events, and release resources. */
|
|
1662
1693
|
destroy() {
|
|
1663
1694
|
this.pageviewTracker.stopAutocapture();
|
|
1664
1695
|
this.autocaptureTracker.stop();
|
|
@@ -1668,6 +1699,7 @@ class JourniumAnalytics {
|
|
|
1668
1699
|
this.client.destroy();
|
|
1669
1700
|
}
|
|
1670
1701
|
}
|
|
1702
|
+
/** Create and return a new JourniumAnalytics instance for the given config. */
|
|
1671
1703
|
const init = (config) => {
|
|
1672
1704
|
return new JourniumAnalytics(config);
|
|
1673
1705
|
};
|