customer Privacyinterface
interface
Provides access to the customerPrivacy API to track whether or not customers have given consent.
Anchor to propertiesProperties
- Anchor to subscribesubscribe(eventName: string, event_callback: Function) => Promise<undefined>
CustomerPrivacySubscribe
- subscribe
(eventName: string, event_callback: Function) => Promise<undefined>
export interface CustomerPrivacySubscribe {
subscribe?: (
eventName: string,
event_callback: Function,
) => Promise<undefined>;
}
Name
The name of the customer event
string
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,
});
});
});
examples
Accessing Standard Api
App Pixels
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, }); }); });
Custom Pixels
let customerPrivacyStatus = init.customerPrivacy; // Use the customerPrivacy Standard API to subscribe to consent collected events and update the status api.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, }); });