---
title: customerPrivacy
description: >-
  Provides access to the customerPrivacy API to track whether or not customers
  have given consent.
source_url:
  html: 'https://shopify.dev/docs/api/web-pixels-api/standard-api/customerprivacy'
  md: 'https://shopify.dev/docs/api/web-pixels-api/standard-api/customerprivacy.md'
api_name: web-pixels
---

# customer​Privacy

Provides access to the [customerPrivacy API](https://shopify.dev/api/web-pixels-api/pixel-privacy#customer-privacy-api) to track whether or not customers have given consent.

#### Properties

* **subscribe**

  **(eventName: string, event\_callback: Function) => Promise\<undefined>**

Examples

### Examples

* #### Accessing Standard Api

  ##### App Pixels

  ```js
  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

  ```js
  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,
    });
  });
  ```

***
