@active-reach/web-sdk 1.1.0 → 1.2.1
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/dist/aegis.min.js +1 -1
- package/dist/aegis.min.js.map +1 -1
- package/dist/{analytics-pklAx2Nq.mjs → analytics-CNtfsb7E.mjs} +48 -1
- package/dist/{analytics-pklAx2Nq.mjs.map → analytics-CNtfsb7E.mjs.map} +1 -1
- package/dist/core/analytics.d.ts +10 -0
- package/dist/core/analytics.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/react.js +1 -1
- package/package.json +1 -1
|
@@ -1662,6 +1662,10 @@ class Aegis {
|
|
|
1662
1662
|
this.initPromise = null;
|
|
1663
1663
|
this.consent = null;
|
|
1664
1664
|
this._ecommerce = null;
|
|
1665
|
+
this._lastPageUrl = null;
|
|
1666
|
+
this._popstateHandler = null;
|
|
1667
|
+
this._originalPushState = null;
|
|
1668
|
+
this._originalReplaceState = null;
|
|
1665
1669
|
}
|
|
1666
1670
|
async init(writeKey, config) {
|
|
1667
1671
|
if (this.initPromise) {
|
|
@@ -1741,9 +1745,51 @@ class Aegis {
|
|
|
1741
1745
|
await this.initializePlugins();
|
|
1742
1746
|
if (this.config.auto_page_view) {
|
|
1743
1747
|
this.page();
|
|
1748
|
+
this.startSPATracking();
|
|
1744
1749
|
}
|
|
1745
1750
|
logger.info("Aegis SDK initialized successfully");
|
|
1746
1751
|
}
|
|
1752
|
+
/**
|
|
1753
|
+
* SPA navigation tracking — monkey-patches pushState/replaceState and
|
|
1754
|
+
* listens for popstate to fire page() on every client-side route change.
|
|
1755
|
+
*/
|
|
1756
|
+
startSPATracking() {
|
|
1757
|
+
this._lastPageUrl = window.location.href;
|
|
1758
|
+
const onRouteChange = () => {
|
|
1759
|
+
const currentUrl = window.location.href;
|
|
1760
|
+
if (currentUrl === this._lastPageUrl) return;
|
|
1761
|
+
this._lastPageUrl = currentUrl;
|
|
1762
|
+
setTimeout(() => {
|
|
1763
|
+
this.page();
|
|
1764
|
+
}, 50);
|
|
1765
|
+
};
|
|
1766
|
+
this._popstateHandler = onRouteChange;
|
|
1767
|
+
window.addEventListener("popstate", this._popstateHandler);
|
|
1768
|
+
this._originalPushState = history.pushState.bind(history);
|
|
1769
|
+
this._originalReplaceState = history.replaceState.bind(history);
|
|
1770
|
+
history.pushState = (...args) => {
|
|
1771
|
+
this._originalPushState(...args);
|
|
1772
|
+
onRouteChange();
|
|
1773
|
+
};
|
|
1774
|
+
history.replaceState = (...args) => {
|
|
1775
|
+
this._originalReplaceState(...args);
|
|
1776
|
+
onRouteChange();
|
|
1777
|
+
};
|
|
1778
|
+
}
|
|
1779
|
+
stopSPATracking() {
|
|
1780
|
+
if (this._popstateHandler) {
|
|
1781
|
+
window.removeEventListener("popstate", this._popstateHandler);
|
|
1782
|
+
this._popstateHandler = null;
|
|
1783
|
+
}
|
|
1784
|
+
if (this._originalPushState) {
|
|
1785
|
+
history.pushState = this._originalPushState;
|
|
1786
|
+
this._originalPushState = null;
|
|
1787
|
+
}
|
|
1788
|
+
if (this._originalReplaceState) {
|
|
1789
|
+
history.replaceState = this._originalReplaceState;
|
|
1790
|
+
this._originalReplaceState = null;
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1747
1793
|
buildConfig(writeKey, config) {
|
|
1748
1794
|
return {
|
|
1749
1795
|
...DEFAULT_CONFIG,
|
|
@@ -1998,6 +2044,7 @@ class Aegis {
|
|
|
1998
2044
|
return this._ecommerce;
|
|
1999
2045
|
}
|
|
2000
2046
|
destroy() {
|
|
2047
|
+
this.stopSPATracking();
|
|
2001
2048
|
if (this.queue) {
|
|
2002
2049
|
this.queue.destroy();
|
|
2003
2050
|
}
|
|
@@ -2016,4 +2063,4 @@ export {
|
|
|
2016
2063
|
EcommerceTracker as E,
|
|
2017
2064
|
logger as l
|
|
2018
2065
|
};
|
|
2019
|
-
//# sourceMappingURL=analytics-
|
|
2066
|
+
//# sourceMappingURL=analytics-CNtfsb7E.mjs.map
|