stat18ion 0.1.5 → 0.1.8
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/index.js +19 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -32,12 +32,19 @@ const sendEvent = (payload) => {
|
|
|
32
32
|
};
|
|
33
33
|
const isStaticAsset = (path) => {
|
|
34
34
|
const staticExtensions = [
|
|
35
|
-
'.js', '.css', '.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.woff', '.woff2', '.ttf', '.otf', '.json', '.map'
|
|
35
|
+
'.js', '.css', '.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.woff', '.woff2', '.ttf', '.otf', '.json', '.map', '.txt', '.xml', '.webp', '.avif', '.mp4', '.webm'
|
|
36
36
|
];
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
// Clean path (remove query params and hashes)
|
|
38
|
+
const cleanPath = path.split('?')[0].split('#')[0].toLowerCase();
|
|
39
|
+
return (staticExtensions.some(ext => cleanPath.endsWith(ext)) ||
|
|
40
|
+
cleanPath.includes('/_next/static/') ||
|
|
41
|
+
cleanPath.includes('/_next/image/') ||
|
|
42
|
+
cleanPath.includes('/api/') ||
|
|
43
|
+
cleanPath === '/favicon.ico' ||
|
|
44
|
+
cleanPath === '/robots.txt');
|
|
40
45
|
};
|
|
46
|
+
let lastTrackedPath = '';
|
|
47
|
+
let lastTrackedTime = 0;
|
|
41
48
|
/**
|
|
42
49
|
* Main function to track page views (Client-side)
|
|
43
50
|
*/
|
|
@@ -45,6 +52,11 @@ const trackPageView = () => {
|
|
|
45
52
|
if (typeof window === 'undefined')
|
|
46
53
|
return;
|
|
47
54
|
const path = window.location.pathname;
|
|
55
|
+
const now = Date.now();
|
|
56
|
+
// Deduplicate: Don't track same path within 1000ms
|
|
57
|
+
if (path === lastTrackedPath && now - lastTrackedTime < 1000) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
48
60
|
if (isStaticAsset(path))
|
|
49
61
|
return;
|
|
50
62
|
const isLocal = ['localhost', '127.0.0.1', '0.0.0.0'].includes(window.location.hostname);
|
|
@@ -52,12 +64,14 @@ const trackPageView = () => {
|
|
|
52
64
|
log('Skipping event sending on localhost.');
|
|
53
65
|
return;
|
|
54
66
|
}
|
|
67
|
+
lastTrackedPath = path;
|
|
68
|
+
lastTrackedTime = now;
|
|
55
69
|
const payload = {
|
|
56
70
|
siteId: config.siteId,
|
|
57
71
|
path: path,
|
|
58
72
|
referrer: document.referrer,
|
|
59
73
|
ua: navigator.userAgent,
|
|
60
|
-
ts:
|
|
74
|
+
ts: now,
|
|
61
75
|
};
|
|
62
76
|
log('Track PageView', payload);
|
|
63
77
|
sendEvent(payload);
|