MNTOR-2957 - avoid loading client-side analytics on server (#4207)

* MNTOR-2957 - avoid loading client-side analytics on server
This commit is contained in:
Robert Helmer 2024-02-13 15:53:14 -08:00 коммит произвёл GitHub
Родитель 7f25facd11
Коммит 280edb4c4f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 14 добавлений и 0 удалений

Просмотреть файл

@ -91,6 +91,11 @@ export const sendGAEvent = (type: "event", eventName: string, args: object) => {
return;
}
if (typeof window === "undefined") {
console.warn("GA4 should only be used on the client");
return;
}
if (currDataLayerName === undefined) {
console.warn(`@next/third-parties: GA has not been initialized`);
return;

Просмотреть файл

@ -15,6 +15,11 @@ export const useGlean = () => {
// Initialize Glean only on the first render of our custom hook.
useEffect(() => {
if (typeof window === "undefined") {
console.warn("Glean should only be used on the client");
return;
}
// Enable upload only if the user has not opted out of tracking.
const uploadEnabled =
navigator.doNotTrack !== "1" ||
@ -54,6 +59,10 @@ export const useGlean = () => {
event: keyof GleanMetricMap[EventModule],
data: GleanMetricMap[EventModule][EventName],
) => {
if (typeof window === "undefined") {
console.warn("Glean should only be used on the client");
return;
}
const mod = (await import(
`../../telemetry/generated/${eventModule}`
)) as Record<keyof GleanMetricMap[EventModule], EventMetricType>;