Skip to main content

useCustomerPrivacy
hook

A hook that loads the Customer Privacy API.

You can get the customer privacy instance with getCustomerPrivacy().

required
Was this section helpful?

Example

import {useCustomerPrivacy} from '@shopify/hydrogen';

export function MyComponent() {
useCustomerPrivacy({
storefrontAccessToken: '12345',
checkoutDomain: 'checkout.example.com',
onVisitorConsentCollected: (consent) => {
console.log('Visitor consent collected:', consent);
},
});
}

Example usage with useAnalytics:

Returns the value of window.Shopify.customerPrivacy if it exists.

Was this section helpful?

JavaScript

import {getCustomerPrivacy} from '@shopify/hydrogen';
import {useEffect} from 'react';

export function MyComponent() {
useEffect(() => {
const customerPrivacy = getCustomerPrivacy();
if (customerPrivacy) {
console.log('Customer privacy:', customerPrivacy);
}
}, []);
}