TermsFeed Privacy Consent (CMP) calls 1 of 3 answer callbacks each time a visitor saves an answer on the cookie banner: acceptedAll, acceptedSome, or rejectedAll. A 4th callback, initialized, runs once per page view and reports no answer. Your own Consent Mode code, the Shopify Customer Privacy API, the WordPress Consent API, and any other code you write take their consent signal from these callbacks. A vendor added from a template gets its signal from Privacy Consent instead.

Install your callbacks with the integration snippet, inline, above the Privacy Consent snippet. In that position the snippet sets window.termsfeed_privacy_consent_callbacks, which the script reads once as it loads. Your callbacks are then in place before Privacy Consent applies anything, including a Global Privacy Control (GPC) override on load.

The block holds a logging set of callbacks, the integration snippet, and the Privacy Consent snippet, in the order they go in your <head>. Replace YOUR_TOKEN with the token in the snippet the TermsFeed app gives you.

<script>
  var callbacks = {
    acceptedAll: function (categories) { console.log('accepted all', categories); },
    acceptedSome: function (categories) { console.log('accepted some', categories); },
    rejectedAll: function () { console.log('rejected all'); },
    initialized: function () { console.log('initialized'); }
  };

  if (window.termsfeed_privacy_consent !== undefined)
    window.termsfeed_privacy_consent.v1.callbacks(callbacks);
  else
    window.termsfeed_privacy_consent_callbacks = callbacks;
</script>
<!-- Privacy Consent by TermsFeed (https://www.termsfeed.com) -->
<script type="text/javascript" src="https://cdn.termsfeedtag.com/plugins/pc/v1/YOUR_TOKEN/plugin.js" async></script>
<!-- End Privacy Consent by TermsFeed (https://www.termsfeed.com) -->

Keep the integration snippet in front of the Privacy Consent snippet, where it always sets the global. Code that runs later, such as a bundle, takes the v1.callbacks() branch instead. An answer callback installed that late misses a GPC override that Privacy Consent has already applied, while initialized still runs at once if no initialized callback has run yet.

Keep one set of callbacks on the page

Privacy Consent keeps a single set of callbacks for the whole page, and each v1.callbacks() call replaces all 4. A key you leave out becomes undefined, so a second integration that installs its own set silently removes the first one. Register the set once and announce each answer to the rest of your code with a DOM event.

The block dispatches a tf-consent-change event on window after each answer. Privacy Consent neither sends nor reads that event, so its name and its contents are yours to choose. Put it in your <head>, before the Privacy Consent snippet, in place of any other set of callbacks.

<script>
  function tfAnnounceConsent(result, categories) {
    window.dispatchEvent(new CustomEvent('tf-consent-change', {
      detail: { result: result, categories: categories }
    }));
  }

  var callbacks = {
    acceptedAll: function (categories) { tfAnnounceConsent('acceptedAll', categories); },
    acceptedSome: function (categories) { tfAnnounceConsent('acceptedSome', categories); },
    rejectedAll: function () { tfAnnounceConsent('rejectedAll', ['essential']); }
  };

  if (window.termsfeed_privacy_consent !== undefined)
    window.termsfeed_privacy_consent.v1.callbacks(callbacks);
  else
    window.termsfeed_privacy_consent_callbacks = callbacks;
</script>

Privacy Consent picks the callback from the saved answer, not from the button the visitor clicked. It sorts each vendor category into accepted, mixed, or rejected. A vendor category is accepted when every vendor in it is on, mixed when some are on, and rejected when none are. A vendor category with no vendors is accepted only when the visitor switched it on.

Result Condition Callback and argument
Accept all No vendor category rejected and none mixed acceptedAll(categories), with every vendor category ID
Reject all Only essential accepted and none mixed rejectedAll(), with no argument
Accept some Any other combination acceptedSome(categories), with the IDs of the fully accepted vendor categories

The categories array always holds essential, in the order functionality, analytics, marketing, advertising, essential. An acceptedAll call receives ["functionality","analytics","marketing","advertising","essential"]. Check membership with indexOf() or includes(), never by position.

The computed result explains some surprises. Accept this vendor on an embed placeholder usually fires acceptedSome, and Decline this vendor fires acceptedSome or rejectedAll. A visitor who switches on every vendor but leaves a vendor category with no vendors off fires acceptedSome. No callback exists for the consent banner showing, for Close, for opening the Preferences Center, or for a partly declined answer as such.

Mixed vendor categories count as denied

A vendor category the visitor accepted only in part does not appear in the categories array. A visitor who turns on 2 of your 3 Analytics vendors fires acceptedSome with no analytics in the array. An integration that maps the array straight onto a consent signal reports analytics as denied, although 2 Analytics vendors are running.

Every integration page in this manual takes that conservative reading, and the consent signals Privacy Consent sends treat a mixed vendor category as declined too. The signal never claims more consent than the visitor gave. You lose some analytics or advertising data from visitors who made a partial choice, and you never send a granted signal for a vendor the visitor switched off.

Read each vendor for a vendor-accurate answer

Read the stored record inside the callback where one vendor category holds vendors with different purposes. Privacy Consent saves the record before it calls your callback, so the record already holds the new answer. The record lists each vendor with its own enabled value.

The function returns an object whose keys are the IDs of the vendors the visitor turned on. Call it from a callback or a tf-consent-change listener. Each vendor ID has the form termsfeed-1a2b3c4d-5e6f, and you find it in the address of the "Edit vendor" page in the TermsFeed app.

function tfEnabledVendors() {
  var enabled = {};
  try {
    var record = JSON.parse(window.localStorage.getItem('termsfeed_privacy_consent_state') || '{}');
    var state = record.consentState;
    if (!state || !state.consentedDate) return enabled;
    (state.categories || []).forEach(function (category) {
      (category.vendors || []).forEach(function (vendor) {
        if (vendor.enabled === true) enabled[vendor.id] = true;
      });
    });
  } catch (error) {
    return {};
  }
  return enabled;
}

Choose one reading and use it in every integration on the site. Build the full readers for vendor categories and single vendors with read consent state in your own code.

Privacy Consent writes the answer to localStorage under the key termsfeed_privacy_consent_state, with no cookie. The record holds each vendor category and vendor with its enabled value, and the time of the answer in consentedDate, in Unix seconds. localStorage belongs to one origin, so shop.example.com does not see what www.example.com stored, and no request carries it to your server.

Treat the record as read-only. No page-level getter returns the full consent state, so reading this key is the supported way to see vendor categories and vendors. Find every field in what is stored on the device.

Privacy Consent fires an answer callback on every save, including a save that changes nothing. A visitor who accepts, reopens the Preferences Center, and saves again fires a second callback. A click in each of 2 embed placeholders fires 2 more.

Write every callback so that running it twice gives the same result as running it once. Send a consent update, set a flag, or write a cookie there, and never count a conversion. An answer callback that throws prints its console code followed by your error, such as [ee][9b16b888] for acceptedAll, so wrap risky code in your own try and catch.

Returning visitors do not fire an answer callback

A visitor with a stored answer clicks nothing, so no answer callback runs on page load. Privacy Consent still runs the vendors that visitor accepted. An integration that listens only to answer callbacks does not send a consent signal on any page a returning visitor opens.

A first visit under the opt-out model behaves the same way: every vendor runs, no answer is saved, and no answer callback runs. The single exception is a stored acceptance from a visitor who now sends GPC. Privacy Consent overrides it on load and fires rejectedAll with no click.

Use initialized for code that has to run on every page. Inside it, window.termsfeed_privacy_consent.v1.visitor holds the location and consent model of the visit, and the stored record holds the saved answer. Read v1.visitor there or in a later answer callback, such as rejectedAll on a GPC override, which runs after initialized, because its flags are missing until Privacy Consent has initialized. The next block logs the consent model of the visit.

var callbacks = {
  initialized: function () {
    var visitor = window.termsfeed_privacy_consent.v1.visitor;
    console.log('Opt-out model:', visitor.isOptOutModel, 'Country:', visitor.country);
  }
};

Install that set with the integration snippet. An initialized callback that throws prints [ee][9f95e52a]. Copy a page-load push for returning visitors from send events to the data layer.

Open the Preferences Center from your own code

Call window.termsfeed_privacy_consent.v1.openPrivacyPreferences() to open the Preferences Center from any script. The method takes no arguments. A call made before the script is ready does nothing and prints [ee][478058ef], and Privacy Consent does not queue the call.

The block opens the Preferences Center from a button with the ID cookie-settings. The optional chaining skips the call while the script has not loaded yet.

<button type="button" id="cookie-settings">Cookie settings</button>
<script>
  document.getElementById('cookie-settings').addEventListener('click', function () {
    window.termsfeed_privacy_consent?.v1?.openPrivacyPreferences();
  });
</script>

An element with the class termsfeed-pc1-open-privacy-preferences, or the ID open_privacy_preferences_element, opens the Preferences Center with no code. Choose between the element, the floating button, and the method with reopen preferences.

3 globals are internal, with no compatibility promise: window.termsfeed_privacy_consent_bootstrap, window.termsfeed_privacy_consent_preferences, and window.termsfeed_privacy_consent_vendors. Privacy Consent uses them to connect its own files. Code that calls into them breaks without warning at the next script update.

Build on window.termsfeed_privacy_consent, the callbacks, and the stored record only. Find each of them with its type in the JavaScript API reference.

Confirm that each callback runs once per save and receives the vendor categories you expect. Paste the logging block in your <head>, before the Privacy Consent snippet, then use a private window with Chrome DevTools open. These steps assume a visit that shows the consent banner.

  1. Select the Console tab, load your site, and confirm that initialized prints once.
  2. Click I Agree and confirm that accepted all prints with all 5 vendor category IDs.
  3. Select the Network tab, type events.push in the filter box, and confirm that 1 request with status 201 accompanies the save.
  4. Reload the page and confirm that initialized prints again with no answer callback beside it.
  5. Close every private window, open a new one, load your site, and click I Decline.
  6. Select the Console tab and confirm that rejected all prints.