Skip to content

Commit ed10a76

Browse files
committed
fix: resolve incorrect hostname env
1 parent 1f66218 commit ed10a76

File tree

5 files changed

+54
-18
lines changed

5 files changed

+54
-18
lines changed

packages/nuxt/src/module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default defineNuxtModule<ModuleOptions>({
3131
// Ensure proxy has a default value if not provided
3232
const configOptions = {
3333
...options,
34+
hostname: options.hostname ?? process.env.SIMPLE_ANALYTICS_HOSTNAME,
3435
proxy: options.proxy ?? true,
3536
};
3637

packages/nuxt/src/runtime/server/lib/options.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useRuntimeConfig } from "#imports";
2+
13
export interface SimpleAnalyticsOptions {
24
autoCollect?: boolean;
35
collectDnt?: boolean;
@@ -34,7 +36,7 @@ export function parseOptions(options: SimpleAnalyticsOptions) {
3436
"data-auto-collect": options.autoCollect,
3537
"data-collect-dnt": options.collectDnt,
3638
"data-hostname":
37-
options.hostname ?? process.env.NEXT_PUBLIC_SIMPLE_ANALYTICS_HOSTNAME,
39+
options.hostname ?? useRuntimeConfig().public.simpleAnalytics.hostname,
3840
"data-mode": options.mode,
3941
"data-ignore-metrics": metrics === "" ? undefined : metrics,
4042
"data-ignore-pages": options.ignorePages?.join(","),

packages/nuxt/src/runtime/track-event.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
isEnhancedBotDetectionEnabled,
1111
} from "./server/lib/utils";
1212
import { parseHeaders } from "./server/lib/headers";
13-
import { useRequestEvent } from "nuxt/app";
13+
import { useRequestEvent, useRuntimeConfig } from "nuxt/app";
1414

1515
type TrackEventOptions = TrackingOptions & (ServerContext | HeaderOnlyContext);
1616

@@ -22,7 +22,8 @@ export async function trackEvent(
2222
return;
2323
}
2424

25-
const hostname = options?.hostname ?? process.env.SIMPLE_ANALYTICS_HOSTNAME;
25+
const hostname =
26+
options?.hostname ?? useRuntimeConfig().public.simpleAnalytics.hostname;
2627

2728
if (!hostname) {
2829
console.warn("No hostname provided for Simple Analytics");

packages/nuxt/src/runtime/track-pageview.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "./server/lib/utils";
1010
import { parseHeaders } from "./server/lib/headers";
1111
import { parseUtmParameters } from "./server/lib/utm";
12-
import { useRequestEvent, useRoute } from "nuxt/app";
12+
import { useRequestEvent, useRoute, useRuntimeConfig } from "nuxt/app";
1313

1414
// eslint-disable-next-line regexp/no-unused-capturing-group
1515
const PROXY_PATHS = /^\/(proxy\.js|auto-events\.js|simple\/.*)$/;
@@ -19,7 +19,8 @@ export async function trackPageview(options?: TrackingOptions) {
1919
return;
2020
}
2121

22-
const hostname = options?.hostname ?? process.env.SIMPLE_ANALYTICS_HOSTNAME;
22+
const hostname =
23+
options?.hostname ?? useRuntimeConfig().public.simpleAnalytics.hostname;
2324

2425
if (!hostname) {
2526
console.warn("No hostname provided for Simple Analytics");

packages/nuxt/types.d.ts

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,53 @@ declare module "@nuxt/schema" {
3333
}
3434
}
3535

36-
declare module "#app" {
37-
interface NuxtApp {
38-
$simpleAnalytics: {
39-
trackEvent: typeof import("./src/lib/server/simple-analytics").trackEvent;
40-
trackPageview: typeof import("./src/lib/server/simple-analytics").trackPageview;
41-
};
36+
// Auto-imports exposed by the module
37+
declare module "#imports" {
38+
type AnalyticsPrimitive = string | boolean | number | Date;
39+
type AnalyticsMetadata = Record<string, AnalyticsPrimitive> | undefined;
40+
41+
interface IgnoredMetrics {
42+
utm?: boolean | undefined;
43+
timezone?: boolean | undefined;
44+
userAgent?: boolean | undefined;
45+
viewportSize?: boolean | undefined;
46+
language?: boolean | undefined;
4247
}
43-
}
4448

45-
declare module "@vue/runtime-core" {
46-
interface ComponentCustomProperties {
47-
$simpleAnalytics: {
48-
trackEvent: typeof import("./src/lib/server/simple-analytics").trackEvent;
49-
trackPageview: typeof import("./src/lib/server/simple-analytics").trackPageview;
50-
};
49+
interface TrackingOptions {
50+
hostname?: string | undefined;
51+
enhancedBotDetection?: boolean | undefined;
52+
strictUtm?: boolean | undefined;
53+
ignoreMetrics?: IgnoredMetrics | undefined;
54+
collectDnt?: boolean | undefined;
55+
metadata?: AnalyticsMetadata;
5156
}
57+
58+
type HeaderOnlyContext = { headers: Headers };
59+
type ServerContextWithRequest = { request: Request };
60+
type ServerContextWithPath = {
61+
path: string;
62+
headers: Headers;
63+
searchParams?: Record<string, string | string[] | undefined>;
64+
};
65+
type ServerContext = ServerContextWithRequest | ServerContextWithPath;
66+
type NitroContext = { event: import("h3").H3Event };
67+
68+
// trackEvent overloads (SSR and Nitro)
69+
export function trackEvent(
70+
eventName: string,
71+
options?: TrackingOptions & (ServerContext | HeaderOnlyContext)
72+
): Promise<void>;
73+
export function trackEvent(
74+
eventName: string,
75+
options: TrackingOptions & NitroContext
76+
): Promise<void>;
77+
78+
// trackPageview overloads (SSR and Nitro)
79+
export function trackPageview(options?: TrackingOptions): Promise<void>;
80+
export function trackPageview(
81+
options: TrackingOptions & NitroContext
82+
): Promise<void>;
5283
}
5384

5485
declare global {

0 commit comments

Comments
 (0)