@kitbase/analytics 0.1.6 → 0.1.7
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 +3 -1
- package/dist/index.cjs +13 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/lite.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,6 +74,7 @@ const kitbase = new Kitbase({
|
|
|
74
74
|
|
|
75
75
|
analytics: {
|
|
76
76
|
autoTrackPageViews: true, // track route changes automatically
|
|
77
|
+
trackBfcacheRestore: true, // track pageview on bfcache restore (back/forward in MPAs)
|
|
77
78
|
autoTrackOutboundLinks: true, // track external link clicks
|
|
78
79
|
autoTrackClicks: true, // track button/link/input clicks + data-kb-track-click
|
|
79
80
|
autoTrackScrollDepth: true, // track max scroll depth per page
|
|
@@ -103,6 +104,7 @@ All enabled by default. The SDK automatically tracks:
|
|
|
103
104
|
| Event | Channel | Trigger | Config |
|
|
104
105
|
|-------|---------|---------|--------|
|
|
105
106
|
| `screen_view` | `__analytics` | Page navigation (init, pushState, popstate) | `autoTrackPageViews` (default `true`) |
|
|
107
|
+
| `screen_view` | `__analytics` | Page restored from bfcache (back/forward in MPAs) | `trackBfcacheRestore` (default `true`) |
|
|
106
108
|
| `outbound_link` | `__analytics` | Click on external link | `autoTrackOutboundLinks` (default `true`) |
|
|
107
109
|
| `click` | `__analytics` | Click on interactive element | `autoTrackClicks` (default `true`) |
|
|
108
110
|
| `scroll_depth` | `__analytics` | Navigation / unload (max depth per page) | `autoTrackScrollDepth` (default `true`) |
|
|
@@ -110,7 +112,7 @@ All enabled by default. The SDK automatically tracks:
|
|
|
110
112
|
| `dead_click` | `__analytics` | Click with no DOM change within 1s | `autoDetectFrustration` (default `true`) |
|
|
111
113
|
| `web_vitals` | `__analytics` | Once per page load | `autoTrackWebVitals` (default `false`) |
|
|
112
114
|
|
|
113
|
-
Page views, clicks, outbound links, scroll depth, and frustration signals are tracked automatically. The SDK intercepts `history.pushState`/`popstate` for SPA support — no framework router integration needed.
|
|
115
|
+
Page views, clicks, outbound links, scroll depth, and frustration signals are tracked automatically. The SDK intercepts `history.pushState`/`popstate` for SPA support — no framework router integration needed. For multi-page sites, the SDK also listens for bfcache restores (`pageshow` with `persisted`) so back/forward navigation is counted even when scripts don't re-execute.
|
|
114
116
|
|
|
115
117
|
## Data Attribute Events
|
|
116
118
|
|
package/dist/index.cjs
CHANGED
|
@@ -1514,6 +1514,7 @@ var PageViewPlugin = class {
|
|
|
1514
1514
|
ctx;
|
|
1515
1515
|
active = false;
|
|
1516
1516
|
popstateListener = null;
|
|
1517
|
+
pageshowListener = null;
|
|
1517
1518
|
setup(ctx) {
|
|
1518
1519
|
if (typeof window === "undefined") return false;
|
|
1519
1520
|
this.ctx = ctx;
|
|
@@ -1540,6 +1541,14 @@ var PageViewPlugin = class {
|
|
|
1540
1541
|
}
|
|
1541
1542
|
};
|
|
1542
1543
|
window.addEventListener("popstate", this.popstateListener);
|
|
1544
|
+
if (ctx.config.trackBfcacheRestore !== false) {
|
|
1545
|
+
this.pageshowListener = (e) => {
|
|
1546
|
+
if (e.persisted && this.active) {
|
|
1547
|
+
this.trackPageView().catch((err) => ctx.log("Failed to track page view (bfcache)", err));
|
|
1548
|
+
}
|
|
1549
|
+
};
|
|
1550
|
+
window.addEventListener("pageshow", this.pageshowListener);
|
|
1551
|
+
}
|
|
1543
1552
|
ctx.log("Auto page view tracking enabled");
|
|
1544
1553
|
}
|
|
1545
1554
|
teardown() {
|
|
@@ -1548,6 +1557,10 @@ var PageViewPlugin = class {
|
|
|
1548
1557
|
window.removeEventListener("popstate", this.popstateListener);
|
|
1549
1558
|
this.popstateListener = null;
|
|
1550
1559
|
}
|
|
1560
|
+
if (this.pageshowListener) {
|
|
1561
|
+
window.removeEventListener("pageshow", this.pageshowListener);
|
|
1562
|
+
this.pageshowListener = null;
|
|
1563
|
+
}
|
|
1551
1564
|
}
|
|
1552
1565
|
get methods() {
|
|
1553
1566
|
return {
|