2024-08-12 15:37:45 +00:00
|
|
|
import { json, type ActionFunctionArgs } from '@remix-run/cloudflare';
|
|
|
|
import { handleWithAuth } from '~/lib/.server/login';
|
2024-08-19 15:39:37 +00:00
|
|
|
import { getSessionData } from '~/lib/.server/sessions';
|
2024-08-12 15:37:45 +00:00
|
|
|
import { sendEventInternal, type AnalyticsEvent } from '~/lib/analytics';
|
|
|
|
|
|
|
|
async function analyticsAction({ request, context }: ActionFunctionArgs) {
|
|
|
|
const event: AnalyticsEvent = await request.json();
|
2024-08-19 15:39:37 +00:00
|
|
|
const sessionData = await getSessionData(request, context.cloudflare.env);
|
|
|
|
const { success, error } = await sendEventInternal(sessionData, event);
|
2024-08-12 15:37:45 +00:00
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
return json({ error }, { status: 500 });
|
|
|
|
}
|
|
|
|
|
|
|
|
return json({ success }, { status: 200 });
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function action(args: ActionFunctionArgs) {
|
|
|
|
return handleWithAuth(args, analyticsAction);
|
|
|
|
}
|