fix(www): show missing GA env warning once (#1272)
This commit is contained in:
@@ -4,6 +4,8 @@ import { GA4Report, isDocument, isServerError } from "$ga4";
|
|||||||
|
|
||||||
const GA4_MEASUREMENT_ID = Deno.env.get("GA4_MEASUREMENT_ID");
|
const GA4_MEASUREMENT_ID = Deno.env.get("GA4_MEASUREMENT_ID");
|
||||||
|
|
||||||
|
let showedMissingEnvWarning = false;
|
||||||
|
|
||||||
function ga4(
|
function ga4(
|
||||||
request: Request,
|
request: Request,
|
||||||
conn: MiddlewareHandlerContext,
|
conn: MiddlewareHandlerContext,
|
||||||
@@ -11,6 +13,15 @@ function ga4(
|
|||||||
_start: number,
|
_start: number,
|
||||||
error?: unknown,
|
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 () => {
|
Promise.resolve().then(async () => {
|
||||||
// We're tracking page views and file downloads. These are the only two
|
// We're tracking page views and file downloads. These are the only two
|
||||||
// HTTP methods that _might_ be used.
|
// HTTP methods that _might_ be used.
|
||||||
|
|||||||
Reference in New Issue
Block a user