Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make set up cookie banner by default to false #2588

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading