@neomanex/analytics-nuxt 1.0.4 → 1.1.0

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/module.mjs CHANGED
@@ -16,7 +16,9 @@ const module = defineNuxtModule({
16
16
  trackPageVisits: true,
17
17
  trackPageViews: true,
18
18
  trackPageLeave: true,
19
- excludePaths: []
19
+ excludePaths: [],
20
+ allowedDomains: [],
21
+ excludeUserAgents: []
20
22
  },
21
23
  setup(options, nuxt) {
22
24
  const resolver = createResolver(import.meta.url);
@@ -28,7 +30,9 @@ const module = defineNuxtModule({
28
30
  trackPageVisits: options.trackPageVisits,
29
31
  trackPageViews: options.trackPageViews,
30
32
  trackPageLeave: options.trackPageLeave,
31
- excludePaths: options.excludePaths
33
+ excludePaths: options.excludePaths,
34
+ allowedDomains: options.allowedDomains,
35
+ excludeUserAgents: options.excludeUserAgents
32
36
  }
33
37
  );
34
38
  nuxt.options.runtimeConfig.public.analytics = defu(
@@ -27,6 +27,19 @@ export default defineEventHandler(async (event) => {
27
27
  if (!body?.events || !Array.isArray(body.events) || body.events.length === 0) {
28
28
  return { ok: false, error: "No events provided" };
29
29
  }
30
+ if (analyticsConfig.allowedDomains?.length) {
31
+ const host = getRequestHeader(event, "host");
32
+ const hostname = host?.split(":")[0]?.toLowerCase();
33
+ if (!hostname || !analyticsConfig.allowedDomains.some((d) => d.toLowerCase() === hostname)) {
34
+ return { ok: true, ingested: 0 };
35
+ }
36
+ }
37
+ if (analyticsConfig.excludeUserAgents?.length) {
38
+ const ua = getRequestHeader(event, "user-agent");
39
+ if (ua && analyticsConfig.excludeUserAgents.some((pattern) => ua.toLowerCase().includes(pattern.toLowerCase()))) {
40
+ return { ok: true, ingested: 0 };
41
+ }
42
+ }
30
43
  const clientIp = extractClientIp(event);
31
44
  const userAgent = getRequestHeader(event, "user-agent");
32
45
  const referer = getRequestHeader(event, "referer");
@@ -26,6 +26,19 @@ export default defineEventHandler((event) => {
26
26
  if (!analyticsConfig.trackPageVisits) {
27
27
  return;
28
28
  }
29
+ if (analyticsConfig.allowedDomains?.length) {
30
+ const host = getRequestHeader(event, "host");
31
+ const hostname = host?.split(":")[0]?.toLowerCase();
32
+ if (!hostname || !analyticsConfig.allowedDomains.some((d) => d.toLowerCase() === hostname)) {
33
+ return;
34
+ }
35
+ }
36
+ if (analyticsConfig.excludeUserAgents?.length) {
37
+ const ua = getRequestHeader(event, "user-agent");
38
+ if (ua && analyticsConfig.excludeUserAgents.some((pattern) => ua.toLowerCase().includes(pattern.toLowerCase()))) {
39
+ return;
40
+ }
41
+ }
29
42
  const url = getRequestURL(event);
30
43
  const path = url.pathname;
31
44
  if (EXCLUDED_PREFIXES.some((prefix) => path.startsWith(prefix))) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neomanex/analytics-nuxt",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "description": "Nuxt module for analytics tracking with SSR middleware, browser plugin, and server proxy",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",