stat18ion 0.1.4 → 0.1.6

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.
Files changed (2) hide show
  1. package/dist/index.js +24 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -30,23 +30,43 @@ const sendEvent = (payload) => {
30
30
  }).catch((err) => console.error(err));
31
31
  }
32
32
  };
33
+ const isStaticAsset = (path) => {
34
+ const staticExtensions = [
35
+ '.js', '.css', '.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.woff', '.woff2', '.ttf', '.otf', '.json', '.map'
36
+ ];
37
+ return (staticExtensions.some(ext => path.toLowerCase().endsWith(ext)) ||
38
+ path.includes('/_next/static/') ||
39
+ path.includes('/api/'));
40
+ };
41
+ let lastTrackedPath = '';
42
+ let lastTrackedTime = 0;
33
43
  /**
34
44
  * Main function to track page views (Client-side)
35
45
  */
36
46
  const trackPageView = () => {
37
47
  if (typeof window === 'undefined')
38
48
  return;
49
+ const path = window.location.pathname;
50
+ const now = Date.now();
51
+ // Deduplicate: Don't track same path within 500ms
52
+ if (path === lastTrackedPath && now - lastTrackedTime < 500) {
53
+ return;
54
+ }
55
+ if (isStaticAsset(path))
56
+ return;
39
57
  const isLocal = ['localhost', '127.0.0.1', '0.0.0.0'].includes(window.location.hostname);
40
58
  if (isLocal && !config.trackLocal) {
41
59
  log('Skipping event sending on localhost.');
42
60
  return;
43
61
  }
62
+ lastTrackedPath = path;
63
+ lastTrackedTime = now;
44
64
  const payload = {
45
65
  siteId: config.siteId,
46
- path: window.location.pathname,
66
+ path: path,
47
67
  referrer: document.referrer,
48
68
  ua: navigator.userAgent,
49
- ts: Date.now(),
69
+ ts: now,
50
70
  };
51
71
  log('Track PageView', payload);
52
72
  sendEvent(payload);
@@ -88,6 +108,8 @@ exports.init = init;
88
108
  * Use this in Next.js Middleware or Server Actions.
89
109
  */
90
110
  const trackServerEvent = async (options) => {
111
+ if (isStaticAsset(options.path))
112
+ return;
91
113
  const payload = {
92
114
  siteId: options.siteId,
93
115
  path: options.path,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stat18ion",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Privacy-first, lightweight analytics tracker for the modern web.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",