stat18ion 0.1.3 → 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 +24 -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,
@@ -112,3 +125,13 @@ const Analytics = () => {
112
125
  return null;
113
126
  };
114
127
  exports.Analytics = Analytics;
128
+ // Auto-initialize if running in a browser and script tag has data-site-id
129
+ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
130
+ const script = document.currentScript || document.querySelector('script[data-site-id]');
131
+ if (script) {
132
+ const siteId = script.getAttribute('data-site-id');
133
+ if (siteId && !config.siteId) {
134
+ (0, exports.init)({ siteId });
135
+ }
136
+ }
137
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stat18ion",
3
- "version": "0.1.3",
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",