Skip to content

Commit

Permalink
Make set up cookie banner by default to false (#2588)
Browse files Browse the repository at this point in the history
  • Loading branch information
wizardlyhel authored Oct 21, 2024
1 parent c7c9f2e commit a253ef9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
21 changes: 21 additions & 0 deletions .changeset/olive-fishes-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
'skeleton': patch
'@shopify/hydrogen': patch
---

Change `<Analytics.Provider>` to set up Customer Privacy without the Shopify's cookie banner by default.

# Breaking Change

If you are using `<Analytics.Provider>` in your app, you need to add `withPrivacyBanner={true}` to the `<AnalyticsProvider>` component if you are using the Shopify's cookie banner. Without this props, the Shopify cookie banner will not appear.

```diff
<Analytics.Provider
cart={data.cart}
shop={data.shop}
consent={data.consent}
+ withPrivacyBanner={true}
>
...
</Analytics.Provider>
```
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ function AnalyticsProvider({
}

if (consent.withPrivacyBanner === undefined) {
consent.withPrivacyBanner = true;
consent.withPrivacyBanner = false;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function logMissingConfig(fieldName: string) {

export function useCustomerPrivacy(props: CustomerPrivacyApiProps) {
const {
withPrivacyBanner = true,
withPrivacyBanner = false,
onVisitorConsentCollected,
onReady,
...consentConfig
Expand Down
28 changes: 13 additions & 15 deletions packages/hydrogen/src/customer-privacy/useCustomerPrivacy.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ let body: HTMLBodyElement;

const CUSTOMER_PRIVACY_PROPS = {
checkoutDomain: 'checkout.shopify.com',
storefrontAccessToken: 'test-token',
storefrontAccessToken: '3b580e70970c4528da70c98e097c2fa0',
withPrivacyBanner: true,
};

describe(`useCustomerPrivacy`, () => {
Expand Down Expand Up @@ -42,25 +43,25 @@ describe(`useCustomerPrivacy`, () => {
document.querySelectorAll('script').forEach((node) => node.remove());
});

it('loads the customerPrivacy with privacyBanner script', () => {
renderHook(() => useCustomerPrivacy(CUSTOMER_PRIVACY_PROPS));
const script = html.querySelector('body script');
expect(script).toContainHTML(`src="${CONSENT_API_WITH_BANNER}"`);
expect(script).toContainHTML('type="text/javascript"');
});

it('loads just the customerPrivacy script', () => {
it('By default, loads just the customerPrivacy script', () => {
renderHook(() =>
useCustomerPrivacy({
...CUSTOMER_PRIVACY_PROPS,
withPrivacyBanner: false,
checkoutDomain: 'checkout.shopify.com',
storefrontAccessToken: '3b580e70970c4528da70c98e097c2fa0',
}),
);
const script = html.querySelector('body script');
expect(script).toContainHTML(`src="${CONSENT_API}"`);
expect(script).toContainHTML('type="text/javascript"');
});

it('loads the customerPrivacy with privacyBanner script', () => {
renderHook(() => useCustomerPrivacy(CUSTOMER_PRIVACY_PROPS));
const script = html.querySelector('body script');
expect(script).toContainHTML(`src="${CONSENT_API_WITH_BANNER}"`);
expect(script).toContainHTML('type="text/javascript"');
});

it('returns just customerPrivacy initiallly as null', () => {
let cp;
renderHook(() => {
Expand All @@ -75,10 +76,7 @@ describe(`useCustomerPrivacy`, () => {
it('returns both customerPrivacy and privacyBanner initially as null', async () => {
let cp;
renderHook(() => {
cp = useCustomerPrivacy({
...CUSTOMER_PRIVACY_PROPS,
withPrivacyBanner: true,
});
cp = useCustomerPrivacy(CUSTOMER_PRIVACY_PROPS);
});

// Wait until idle
Expand Down
2 changes: 1 addition & 1 deletion templates/skeleton/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export async function loader(args: LoaderFunctionArgs) {
consent: {
checkoutDomain: env.PUBLIC_CHECKOUT_DOMAIN,
storefrontAccessToken: env.PUBLIC_STOREFRONT_API_TOKEN,
withPrivacyBanner: true,
withPrivacyBanner: false,
// localize the privacy banner
country: args.context.storefront.i18n.country,
language: args.context.storefront.i18n.language,
Expand Down

0 comments on commit a253ef9

Please sign in to comment.