Skip to content

Commit b107438

Browse files
nixalloverFrozenPandaz
authored andcommitted
docs(misc): allow cookiebot to be disabled (#32394)
Allow for temporarily disabling the cookie consent mechanism. (cherry picked from commit f2bda54)
1 parent a33d63d commit b107438

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

nx-dev/feature-analytics/src/lib/google-analytics.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export function sendPageViewEvent(data: {
2222

2323
// Check if user has consented to statistics cookies
2424
if (
25+
process.env.NEXT_PUBLIC_COOKIEBOT_DISABLE !== 'true' &&
2526
typeof window !== 'undefined' &&
2627
window.Cookiebot &&
2728
!window.Cookiebot.consent?.statistics
@@ -55,6 +56,7 @@ export function sendCustomEvent(
5556

5657
// Check if user has consented to statistics cookies
5758
if (
59+
process.env.NEXT_PUBLIC_COOKIEBOT_DISABLE !== 'true' &&
5860
typeof window !== 'undefined' &&
5961
window.Cookiebot &&
6062
!window.Cookiebot.consent?.statistics

nx-dev/nx-dev/app/global-scripts.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ declare global {
1818
export default function GlobalScripts({ gaMeasurementId, gtmMeasurementId }) {
1919
// Don't load analytics scripts in development
2020
const isProduction = process.env.NODE_ENV === 'production';
21+
const isCookiebotDisabled =
22+
process.env.NEXT_PUBLIC_COOKIEBOT_DISABLE === 'true';
2123

2224
useEffect(() => {
2325
if (!isProduction) return;
@@ -127,7 +129,10 @@ export default function GlobalScripts({ gaMeasurementId, gtmMeasurementId }) {
127129
};
128130

129131
const checkAndLoadScripts = () => {
130-
if (window.Cookiebot && window.Cookiebot.consent) {
132+
if (isCookiebotDisabled) {
133+
loadGoogleAnalytics();
134+
loadGTM();
135+
} else if (window.Cookiebot && window.Cookiebot.consent) {
131136
// Statistics cookies (Google Analytics, GTM)
132137
if (window.Cookiebot.consent.statistics) {
133138
loadGoogleAnalytics();

nx-dev/nx-dev/app/layout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ export default function RootLayout({ children }: { children: ReactNode }) {
6262
const gtmMeasurementId = 'GTM-KW8423B6';
6363
return (
6464
<html lang="en" className="h-full scroll-smooth" suppressHydrationWarning>
65-
{process.env.NEXT_PUBLIC_COOKIEBOT_ID ? (
65+
{process.env.NEXT_PUBLIC_COOKIEBOT_DISABLE !== 'true' &&
66+
process.env.NEXT_PUBLIC_COOKIEBOT_ID ? (
6667
<Script
6768
id="Cookiebot"
6869
src="https://consent.cookiebot.com/uc.js"

nx-dev/nx-dev/pages/_app.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ export default function CustomApp({
7777
/>
7878
<meta name="viewport" content="width=device-width, initial-scale=1" />
7979
</Head>
80-
{process.env.NEXT_PUBLIC_COOKIEBOT_ID ? (
80+
{process.env.NEXT_PUBLIC_COOKIEBOT_DISABLE !== 'true' &&
81+
process.env.NEXT_PUBLIC_COOKIEBOT_ID ? (
8182
<Script
8283
id="Cookiebot"
8384
src="https://consent.cookiebot.com/uc.js"

0 commit comments

Comments
 (0)