MNTOR-2957 - avoid loading client-side analytics on server (#4207)
* MNTOR-2957 - avoid loading client-side analytics on server
This commit is contained in:
Родитель
7f25facd11
Коммит
280edb4c4f
|
@ -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>;
|
||||
|
|
Загрузка…
Ссылка в новой задаче