From 45120155d215ca25f0285974c027c61e98748c15 Mon Sep 17 00:00:00 2001 From: Ivan Vasilov Date: Fri, 27 Feb 2026 17:20:16 +0100 Subject: [PATCH 1/3] feat: Fetch the google scripts only if consent is accepted (#43221) This pull request improves how user consent is handled for telemetry and tracking, ensuring that analytics scripts and cookies are only active when the user has provided consent. The changes both enforce stricter checks before enabling Google Tag Manager and ensure that tracking cookies are cleared when consent is denied. --- packages/common/telemetry.tsx | 13 ++++++++----- packages/ui-patterns/src/consent.tsx | 6 ++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/common/telemetry.tsx b/packages/common/telemetry.tsx index 36b3ea4ee011c..0a0df847c540a 100644 --- a/packages/common/telemetry.tsx +++ b/packages/common/telemetry.tsx @@ -8,7 +8,7 @@ import { useCallback, useEffect, useRef } from 'react' import { useLatest } from 'react-use' import { useUser } from './auth' -import { hasConsented } from './consent-state' +import { hasConsented, useConsentState } from './consent-state' import { IS_PLATFORM, IS_PROD, LOCAL_STORAGE_KEYS } from './constants' import { useFeatureFlags } from './feature-flags' import { post } from './fetchWrappers' @@ -30,11 +30,14 @@ const { TELEMETRY_DATA } = LOCAL_STORAGE_KEYS // Reexports GoogleTagManager with the right API key set export const TelemetryTagManager = () => { - const isGTMEnabled = Boolean(IS_PLATFORM && process.env.NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID) + // useConsentState is used here to trigger a re-render when consent state changes + const { hasAccepted } = useConsentState() - if (!isGTMEnabled) { - return - } + const isGTMEnabled = Boolean( + IS_PLATFORM && process.env.NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID && hasAccepted + ) + + if (!isGTMEnabled) return null return (