stat18ion 0.1.4 → 0.1.5

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 +14 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -30,12 +30,23 @@ 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
+ };
33
41
  /**
34
42
  * Main function to track page views (Client-side)
35
43
  */
36
44
  const trackPageView = () => {
37
45
  if (typeof window === 'undefined')
38
46
  return;
47
+ const path = window.location.pathname;
48
+ if (isStaticAsset(path))
49
+ return;
39
50
  const isLocal = ['localhost', '127.0.0.1', '0.0.0.0'].includes(window.location.hostname);
40
51
  if (isLocal && !config.trackLocal) {
41
52
  log('Skipping event sending on localhost.');
@@ -43,7 +54,7 @@ const trackPageView = () => {
43
54
  }
44
55
  const payload = {
45
56
  siteId: config.siteId,
46
- path: window.location.pathname,
57
+ path: path,
47
58
  referrer: document.referrer,
48
59
  ua: navigator.userAgent,
49
60
  ts: Date.now(),
@@ -88,6 +99,8 @@ exports.init = init;
88
99
  * Use this in Next.js Middleware or Server Actions.
89
100
  */
90
101
  const trackServerEvent = async (options) => {
102
+ if (isStaticAsset(options.path))
103
+ return;
91
104
  const payload = {
92
105
  siteId: options.siteId,
93
106
  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.5",
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",