Skip to content

Commit 79990a1

Browse files
committed
feat(scripts): integrate consent manager with control panel privacy setting
1 parent e5bb5e3 commit 79990a1

5 files changed

Lines changed: 33 additions & 6 deletions

File tree

.changeset/silent-carrots-wash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bigcommerce/catalyst-core": minor
3+
---
4+
5+
Integrates Catalyst's consent manager with the BigCommerce Control Panel's Cookie Consent setting, allowing merchants to centrally control whether the consent banner displays on the storefront. When disabled in the Control Panel, the consent banner is suppressed and all script categories are consented implicitly, matching Stencil behavior.

core/app/[locale]/layout.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ const RootLayoutMetadataQuery = graphql(
3131
query RootLayoutMetadataQuery {
3232
site {
3333
settings {
34+
privacy {
35+
cookieConsentEnabled
36+
}
3437
storeName
3538
seo {
3639
pageTitle
@@ -124,12 +127,14 @@ export default async function RootLayout({ params, children }: Props) {
124127
});
125128

126129
const scripts = scriptsTransformer(rootData.data.site.content.scripts);
130+
const isCookieConsentEnabled =
131+
rootData.data.site.settings?.privacy?.cookieConsentEnabled ?? false;
127132

128133
return (
129134
<html className={clsx(fonts.map((f) => f.variable))} lang={locale}>
130135
<body className="flex min-h-screen flex-col">
131136
<NextIntlClientProvider>
132-
<ConsentManager scripts={scripts}>
137+
<ConsentManager isCookieConsentEnabled={isCookieConsentEnabled} scripts={scripts}>
133138
<NuqsAdapter>
134139
<StreamableAnalyticsProvider data={streamableAnalyticsData} />
135140
<Providers>

core/components/consent-manager/consent-providers.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ export type C15tScripts = NonNullable<ComponentProps<typeof ClientSideOptionsPro
1010

1111
interface ConsentManagerProviderProps extends PropsWithChildren {
1212
scripts: C15tScripts;
13+
isCookieConsentEnabled: boolean;
1314
}
1415

15-
export function ConsentManagerProvider({ children, scripts }: ConsentManagerProviderProps) {
16+
export function ConsentManagerProvider({
17+
children,
18+
scripts,
19+
isCookieConsentEnabled,
20+
}: ConsentManagerProviderProps) {
1621
return (
1722
<C15TConsentManagerProvider
1823
options={{
@@ -21,7 +26,7 @@ export function ConsentManagerProvider({ children, scripts }: ConsentManagerProv
2126

2227
// @ts-expect-error endpointHandlers type is not yet exposed by the package
2328
endpointHandlers: {
24-
showConsentBanner,
29+
showConsentBanner: () => showConsentBanner(isCookieConsentEnabled),
2530
setConsent,
2631
verifyConsent,
2732
},

core/components/consent-manager/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import { CookieBanner } from './cookie-banner';
88

99
interface ConsentManagerProps extends PropsWithChildren {
1010
scripts: C15tScripts;
11+
isCookieConsentEnabled: boolean;
1112
}
1213

13-
export function ConsentManager({ children, scripts }: ConsentManagerProps) {
14+
export function ConsentManager({ children, scripts, isCookieConsentEnabled }: ConsentManagerProps) {
1415
return (
15-
<ConsentManagerProvider scripts={scripts}>
16+
<ConsentManagerProvider isCookieConsentEnabled={isCookieConsentEnabled} scripts={scripts}>
1617
<ConsentManagerDialog />
1718
<CookieBanner />
1819
{children}

core/lib/consent-manager/handlers.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const ok = <T>(data: T | null = null) => ({
77
response: null,
88
});
99

10-
export function showConsentBanner() {
10+
export function showConsentBanner(isCookieConsentEnabled: boolean) {
1111
let show = true;
1212
let language = 'en';
1313

@@ -23,6 +23,17 @@ export function showConsentBanner() {
2323
show = false;
2424
}
2525

26+
if (!isCookieConsentEnabled) {
27+
return ok({
28+
showConsentBanner: false,
29+
jurisdiction: { code: 'NONE' },
30+
translations: {
31+
language,
32+
},
33+
branding: 'none',
34+
});
35+
}
36+
2637
return ok({
2738
showConsentBanner: show,
2839
translations: {

0 commit comments

Comments
 (0)