fix(analytics): ensure Umami Website ID is visible to client bundle
All checks were successful
All checks were successful
This commit is contained in:
@@ -29,9 +29,9 @@ function createConfig() {
|
||||
|
||||
analytics: {
|
||||
umami: {
|
||||
websiteId: env.UMAMI_WEBSITE_ID,
|
||||
websiteId: env.NEXT_PUBLIC_UMAMI_WEBSITE_ID || env.UMAMI_WEBSITE_ID,
|
||||
apiEndpoint: env.UMAMI_API_ENDPOINT,
|
||||
enabled: Boolean(env.UMAMI_WEBSITE_ID),
|
||||
enabled: Boolean(env.NEXT_PUBLIC_UMAMI_WEBSITE_ID || env.UMAMI_WEBSITE_ID),
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
@@ -22,6 +22,11 @@ const envExtension = {
|
||||
|
||||
INFRA_DIRECTUS_URL: z.string().url().optional(),
|
||||
INFRA_DIRECTUS_TOKEN: z.string().optional(),
|
||||
|
||||
// Analytics
|
||||
UMAMI_WEBSITE_ID: z.string().optional(),
|
||||
NEXT_PUBLIC_UMAMI_WEBSITE_ID: z.string().optional(),
|
||||
UMAMI_API_ENDPOINT: z.string().optional(),
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -68,12 +68,15 @@ export class UmamiAnalyticsService implements AnalyticsService {
|
||||
private async sendPayload(type: 'event', data: Record<string, any>) {
|
||||
if (!this.options.enabled) return;
|
||||
|
||||
// On the client, we don't need the websiteId (it's injected by the server-side proxy handler).
|
||||
// On the server, we need it because we're calling the Umami API directly.
|
||||
const isClient = typeof window !== 'undefined';
|
||||
const websiteId =
|
||||
this.websiteId ||
|
||||
(isClient ? (process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID as string) : undefined);
|
||||
|
||||
if (!isClient && !this.websiteId) {
|
||||
this.logger.warn('Umami tracking called on server but no Website ID configured');
|
||||
if (!websiteId) {
|
||||
this.logger.warn(
|
||||
`Umami tracking called on ${isClient ? 'client' : 'server'} but no Website ID configured`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user