customer Privacyinterface
interface
Provides access to the customerPrivacy API to track whether or not customers have given consent.
Anchor to propertiesProperties
Anchor to subscribe
subscribe
(eventName: string, event_callback: Function) => Promise<undefined>
Was this section helpful?
Accessing Standard Api
import {register} from '@shopify/web-pixels-extension';
register(({analytics, init, customerPrivacy}) => {
// Use the init.customerPrivacy object to get the initial customer privacy status
let customerPrivacyStatus = init.customerPrivacy;
// Use the customerPrivacy Standard API to subscribe to consent collected events and update the status
customerPrivacy.subscribe('visitorConsentCollected', (event) => {
customerPrivacyStatus = event.customerPrivacy;
/**
* {
* "analyticsProcessingAllowed": boolean,
* "marketingAllowed": boolean,
* "preferencesProcessingAllowed": boolean,
* "saleOfDataAllowed": boolean,
* }
*/
})
// Every product added to cart event will have the most up to date customer privacy status
analytics.subscribe("product_added_to_cart", event => {
const payload = {
eventName: event.name,
customerPrivacyStatus: customerPrivacyStatus,
};
fetch('https://example.com/pixel', {
method: 'POST',
body: JSON.stringify(payload),
keepalive: true,
});
});
});