Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
import { corsPreflight, getApiCorsHeaders, withCorsHeaders } from '@/lib/cors';
import { getRecorderConfig } from '@/lib/recorder';
import { parseRequest } from '@/lib/request';
import { getWebsite } from '@/queries/prisma';
export function OPTIONS() {
return corsPreflight();
}
export async function GET(
request: Request,
{ params }: { params: Promise<{ websiteId: string }> },
) {
const { error } = await parseRequest(request, null, { skipAuth: true });
if (error) {
return withCorsHeaders(error());
}
const { websiteId } = await params;
const website = await getWebsite(websiteId);
const headers = {
...getApiCorsHeaders(),
'Cache-Control': 'public, max-age=60, stale-while-revalidate=300',
};
if (!website || !website.recorderEnabled) {
return Response.json({ enabled: false }, { headers });
}
const config = getRecorderConfig(website.replayConfig);
return Response.json(
{
enabled: true,
replayEnabled: config.replayEnabled === true,
heatmapEnabled: config.heatmapEnabled === true,
sampleRate: config.sampleRate ?? 0.15,
heatmapSampleRate: config.heatmapSampleRate ?? 0.15,
maskLevel: config.maskLevel ?? 'moderate',
maxDuration: config.maxDuration ?? 300000,
blockSelector: config.blockSelector ?? '',
},
{ headers },
);
}