fix(www): show missing GA env warning once (#1272)

This commit is contained in:
Marvin Hagemeister
2023-06-12 09:44:31 +02:00
committed by GitHub
parent d3a2edc984
commit d511283162
+11
View File
@@ -4,6 +4,8 @@ import { GA4Report, isDocument, isServerError } from "$ga4";
const GA4_MEASUREMENT_ID = Deno.env.get("GA4_MEASUREMENT_ID");
let showedMissingEnvWarning = false;
function ga4(
request: Request,
conn: MiddlewareHandlerContext,
@@ -11,6 +13,15 @@ function ga4(
_start: number,
error?: unknown,
) {
if (GA4_MEASUREMENT_ID === undefined) {
if (!showedMissingEnvWarning) {
showedMissingEnvWarning = true;
console.warn(
"GA4_MEASUREMENT_ID environment variable not set. Google Analytics reporting disabled.",
);
}
return;
}
Promise.resolve().then(async () => {
// We're tracking page views and file downloads. These are the only two
// HTTP methods that _might_ be used.