feat: turbostarter boilerplate
Production-ready Next.js boilerplate with: - Runtime env validation (fail-fast on missing vars) - Feature-gated config (S3, Stripe, email, OAuth) - Docker + Coolify deployment pipeline - PostgreSQL + pgvector, MinIO S3, Better Auth - TypeScript strict mode (no ignoreBuildErrors) - i18n (en/es), AI modules, billing, monitoring Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
45
packages/analytics/web/src/providers/umami/server.ts
Normal file
45
packages/analytics/web/src/providers/umami/server.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { logger } from "@turbostarter/shared/logger";
|
||||
|
||||
import { env } from "./env";
|
||||
|
||||
import type { AnalyticsProviderServerStrategy } from "@turbostarter/analytics";
|
||||
|
||||
export const { track } = {
|
||||
track: (event, data) => {
|
||||
const hostname =
|
||||
typeof data?.hostname === "string" ? data.hostname : undefined;
|
||||
const language =
|
||||
typeof data?.language === "string" ? data.language : undefined;
|
||||
const referrer =
|
||||
typeof data?.referrer === "string" ? data.referrer : undefined;
|
||||
const screen = typeof data?.screen === "string" ? data.screen : undefined;
|
||||
const title = typeof data?.title === "string" ? data.title : undefined;
|
||||
const url = typeof data?.url === "string" ? data.url : "app://server-side";
|
||||
|
||||
void fetch(`${env.UMAMI_API_HOST}/api/send`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"x-umami-api-key": env.UMAMI_API_KEY ?? "",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
type: "event",
|
||||
payload: {
|
||||
website: env.NEXT_PUBLIC_UMAMI_WEBSITE_ID,
|
||||
name: event,
|
||||
url: url,
|
||||
...(hostname && { hostname }),
|
||||
...(language && { language }),
|
||||
...(referrer && { referrer }),
|
||||
...(screen && { screen }),
|
||||
...(title && { title }),
|
||||
data,
|
||||
},
|
||||
}),
|
||||
}).then((res) => {
|
||||
if (!res.ok) {
|
||||
logger.error("Failed to post event to Umami: ", res);
|
||||
}
|
||||
});
|
||||
},
|
||||
} satisfies AnalyticsProviderServerStrategy;
|
||||
Reference in New Issue
Block a user