feat: whyrating - initial project from turbostarter boilerplate

This commit is contained in:
Alejandro Gutiérrez
2026-02-04 01:54:52 +01:00
commit 5cdc07cd39
1618 changed files with 338230 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
import { randomUUID } from "crypto";
import { logger } from "@turbostarter/shared/logger";
import { env } from "./env";
import type {
AllowedPropertyValues,
AnalyticsProviderServerStrategy,
} from "@turbostarter/analytics";
const postEvent = async (
event: string,
data?: Record<string, AllowedPropertyValues>,
) => {
const response = await fetch(
`https://www.google-analytics.com/mp/collect?measurement_id=${env.NEXT_PUBLIC_GOOGLE_ANALYTICS_MEASUREMENT_ID}&api_secret=${env.GOOGLE_ANALYTICS_SECRET}`,
{
method: "POST",
body: JSON.stringify({
client_id: data?.clientId ?? randomUUID(),
events: [{ name: event, params: data }],
}),
},
);
if (!response.ok) {
logger.error("Failed to post event to Google Analytics: ", response);
}
};
export const { track } = {
track: (event, data) => {
void postEvent(event, data);
},
} satisfies AnalyticsProviderServerStrategy;