Look up the public methods, callbacks, and stored key of Privacy Consent
The page API of TermsFeed Privacy Consent is 1 global object, 1 global you set before the script loads, 4 callbacks, and 1 localStorage key. Your HTML adds 2 attributes and 5 custom elements for replaceable tags. Build integrations on these names only, since every other global the script creates is internal. TermsFeed Free Cookie Consent has a different API.
Methods of the v1 page API
window.termsfeed_privacy_consent exists once the Privacy Consent code has loaded, before any consent state applies. The object is undefined before that, so a call in code that runs earlier throws a TypeError. A consent banner the server reports as not serviceable still gets the object.
Call the 2 methods on window.termsfeed_privacy_consent.v1, the official page API, to install your callbacks and open the Preferences Center from your own code. Follow the rules for each answer in Callbacks and Consent Semantics, and add a trigger link to your site with Reopen Preferences.
| Method | Arguments | Returns | Effect |
|---|---|---|---|
v1.callbacks(callbacks) |
An object with any of acceptedAll, acceptedSome, rejectedAll, and initialized, each a function |
Nothing | Installs the 4 callbacks. Each call replaces all 4, and a key left out becomes undefined. null or undefined changes nothing. |
v1.openPrivacyPreferences() |
None | Nothing | Opens the Preferences Center on the next task, the same as a click on a trigger element. Before the script is ready, or on a consent banner that is not serviceable, the call prints [ee][478058ef] and does nothing, and the script does not queue it. |
The window.termsfeed_privacy_consent_callbacks global
window.termsfeed_privacy_consent_callbacks holds your callbacks until the Privacy Consent code runs. The script reads it once, installs it like a v1.callbacks() call, and sets it to undefined. An object assigned after that moment is never read.
These values describe the global as the script reads it.
| Item | Value |
|---|---|
| Type | An object with any of acceptedAll, acceptedSome, rejectedAll, and initialized |
| Default | undefined |
| Read | Once, when the Privacy Consent code runs |
| Effect | Installs the 4 callbacks before any consent state applies |
The integration snippet takes whichever form applies when it runs. Paste it before the Privacy Consent snippet, so the callbacks are in place for an answer the script records on load, such as a Global Privacy Control opt-out.
<script>
var callbacks = {
initialized: function () {
console.log('Privacy Consent initialized');
},
acceptedAll: function (categories) {
console.log('Accepted all', categories);
},
acceptedSome: function (categories) {
console.log('Accepted some', categories);
},
rejectedAll: function () {
console.log('Rejected all');
}
};
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) -->
Confirm the install in Chrome DevTools. Filter the Network tab for plugin.js and reload, and the request shows status 200. The Console tab then prints Privacy Consent initialized, and window.termsfeed_privacy_consent_callbacks returns undefined.
The 4 Privacy Consent callbacks and when each runs
Privacy Consent calls 1 of the 3 answer callbacks after each saved answer, and initialized once per page view. A vendor category counts as accepted, rejected, or mixed, and the mix selects the callback.
| Callback | Argument | Runs when |
|---|---|---|
acceptedAll |
categories, an array of the accepted vendor category IDs |
No vendor category is rejected or mixed |
acceptedSome |
categories, an array of the fully accepted vendor category IDs, always with essential |
The answer is neither of the other 2 results |
rejectedAll |
None | Only essential is accepted, and no vendor category is mixed |
initialized |
None | Once per page view, after the script has initialized. Installed later, it runs at once when none has run yet, and a later one does not run once one has. It reports no answer. |
The categories array follows the order functionality, analytics, marketing, advertising, essential. A vendor category with only some vendors on is missing from the array, so it counts as denied.
The callback follows the saved result, not the button. Decline this vendor in an embed placeholder runs acceptedSome or rejectedAll. Showing the consent banner, closing it, and opening the Preferences Center do not run a callback.
No answer callback runs on page load for a returning visitor. A Global Privacy Control override is the one exception: a visitor who sends the signal over a stored acceptance gets rejectedAll on load, after initialized has run.
An initialized callback that throws prints [ee][9f95e52a] and does not count as run. An answer callback that throws prints [ee][9b16b888], [ee][e8832f52], or [ee][46169886] for acceptedAll, acceptedSome, or rejectedAll, followed by your error.
DOM events from Privacy Consent CMP
Privacy Consent does not dispatch a consent event on document or window. Read each answer in the callbacks, and dispatch your own event from them where several parts of your code need it.
The v1.visitor object and when to read it
window.termsfeed_privacy_consent.v1.visitor holds the location, signals, consent model, and opt-out choices of the visit. Its flags are missing until Privacy Consent has initialized, which is the moment your initialized callback runs, so read it there or in code that runs after it. An answer callback that runs later reads v1.visitor too, such as rejectedAll on a Global Privacy Control override. Find what the version promises in Versions and Changelog.
A vendor tag has no v1.visitor to read when it runs, so vendor tag code takes the same values through placeholders, such as @{TF_PC_V1_VISITOR_COUNTRY}.
Put this function in the callbacks object of the integration snippet to read the visit.
initialized: function () {
var visitor = window.termsfeed_privacy_consent.v1.visitor;
console.log(visitor.countryAndState, visitor.isOptInModel, visitor.isDnsmpiSelected);
}
Open the Console tab of Chrome DevTools and reload. A visitor in California with a saved opt-out prints a line such as US_CA false true.
v1.visitor: location and signals
These properties hold what the settings request found for the visit. The browser performs no location lookup of its own.
| Property | Type | Value |
|---|---|---|
country |
String or null |
The country code, such as US. XX and T1 mean an unknown location. |
state |
String or null |
The region code without the country, such as CA |
countryAndState |
String or null |
Both joined with _, such as US_CA. null without a country and a region. |
language |
String | The language of the visit |
dnt |
Boolean | Whether the browser sent Do Not Track, which changes nothing in Privacy Consent |
gpc |
Boolean | Whether the browser sent Global Privacy Control |
v1.visitor: consent model and opt-out flags
These flags answer what Privacy Consent decided for the visit and what the visitor chose. They are missing from v1.visitor until Privacy Consent has initialized, which is when initialized runs. The first 5 hold the same value for the whole page view, whatever the visitor answers.
| Flag | true when |
|---|---|
isOptInModel |
The visit follows the opt-in model: the consent banner asks, and only Essential vendors run until the visitor answers |
isOptOutModel |
The visit follows the opt-out model: no consent banner shows on a first visit, and every vendor runs until the visitor opts out |
isDnsmpiApplicable |
The Do Not Sell or Share section shows, because the visitor or the company is in the US |
isLspiApplicable |
isDnsmpiApplicable holds, and a non-essential vendor processes sensitive data, so the Limit the Use section shows |
hasSensitiveVendors |
A non-essential vendor has "This vendor processes sensitive data" on |
isDnsmpiSelected |
Do Not Sell or Share applies, and the saved answer has it off: I Decline, its toggle, or any non-essential vendor or vendor category turned off |
isLspiSelected |
Limit the Use applies, and the saved answer has a vendor that processes sensitive data off |
The 2 Selected flags change only when an answer is saved, never on an unsaved toggle or a Close. Both are false before any answer and after a Global Privacy Control override. isLspiSelected is false for an answer saved before a vendor that processes sensitive data existed. v1.visitor is a snapshot the script replaces, so read it each time and do not keep a reference to it.
The examples show the decided flags for a company in the US on the Standard consent logic, unless the row names another company.
| Visit | isOptInModel |
isDnsmpiApplicable |
isLspiApplicable |
hasSensitiveVendors |
|---|---|---|---|---|
| California | false |
true |
false |
false |
| California, with a vendor that processes sensitive data | true |
true |
true |
true |
| California, sending Global Privacy Control | true |
true |
false |
false |
| Quebec | true |
true |
false |
false |
| Germany | true |
true |
false |
false |
| Germany, company in Germany | true |
false |
false |
false |
| Unknown country | false |
true |
false |
false |
Visitor placeholders in vendor tag code
A vendor tag has no v1.visitor to read when it runs, so it takes the same values through placeholders. Privacy Consent replaces each placeholder in the code of every vendor tag and replaceable tag right before it inserts that code. This works for every tag type and every trigger action.
| Placeholder | Same value as | Example |
|---|---|---|
@{TF_PC_V1_VISITOR_COUNTRY} |
country |
US, or XX and T1 for an unknown location |
@{TF_PC_V1_VISITOR_STATE} |
state |
CA |
@{TF_PC_V1_VISITOR_COUNTRY_AND_STATE} |
countryAndState |
US_CA |
@{TF_PC_V1_VISITOR_LANGUAGE} |
language |
en |
@{TF_PC_V1_VISITOR_DNT}, @{TF_PC_V1_VISITOR_GPC} |
dnt, gpc |
true, false |
@{TF_PC_V1_VISITOR_IS_OPT_IN_MODEL}, @{TF_PC_V1_VISITOR_IS_OPT_OUT_MODEL} |
isOptInModel, isOptOutModel |
true, false |
@{TF_PC_V1_VISITOR_IS_DNSMPI_APPLICABLE}, @{TF_PC_V1_VISITOR_IS_DNSMPI_SELECTED} |
isDnsmpiApplicable, isDnsmpiSelected |
true, false |
@{TF_PC_V1_VISITOR_IS_LSPI_APPLICABLE}, @{TF_PC_V1_VISITOR_IS_LSPI_SELECTED} |
isLspiApplicable, isLspiSelected |
true, false |
@{TF_PC_V1_VISITOR_HAS_SENSITIVE_VENDORS} |
hasSensitiveVendors |
true, false |
A flag becomes the text true or false, so write the placeholder in quotes and compare it with 'true'.
var optedOut = "@{TF_PC_V1_VISITOR_IS_DNSMPI_SELECTED}";
if (optedOut === 'true') {
// send the vendor its restricted mode
}
A tag gets the values of the moment Privacy Consent inserts it. A tag inserted after an answer gets the choices of that answer. A tag already on the page keeps what it got, because it does not run again in that page view. An empty value becomes empty text, and so does a value with any character other than letters, digits, _, ,, and -. A name that is not in the table stays as written. Privacy Consent never reads the code of a file loaded through src, so a placeholder works only in code you paste into the tag. The Reddit Pixel template uses COUNTRY, STATE, and IS_DNSMPI_SELECTED for Limited Data Use, as Social Ad Pixels shows.
The stored consent state key
Privacy Consent stores each answer in localStorage under the key termsfeed_privacy_consent_state, per origin, and does not set a cookie. The page API has no getter for the full consent state. Read the key with JSON.parse(window.localStorage.getItem('termsfeed_privacy_consent_state')) and never write to it. Look up every field in Stored on the Device.
HTML attributes you write
Your markup names the vendor of each replaceable tag and each HTML vendor tag. Privacy Consent reads these when it starts.
| Attribute | Goes on | Values | Default | Effect |
|---|---|---|---|---|
data-termsfeed-pc1-vendor-id |
Each replaceable tag, required | A vendor ID, such as termsfeed-1a2b3c4d-5e6f, in any case |
None | Names the vendor. The vendor needs "Has replaceable tags?" on, or the tag never loads. |
data-termsfeed-pc1-replaceable-tag-id |
A replaceable tag, optional | Any string | <vendor id>-<element>-<n> |
Identifies the tag. Each tag gets its own embed placeholder and content. |
data-termsfeed-privacy-consent-vendor-id, data-termsfeed-privacy-consent-vendor-uid |
A replaceable tag, optional | As the 2 attributes above them | None | Aliases of the 2 attributes above them, for markup written with the older names |
| Every other attribute | A replaceable tag, optional | Any | None | Copied onto the real element, with every child node |
id |
The <div> for HTML vendor tags |
The vendor ID | None | Receives the HTML vendor tags of that vendor, with no insertion when the <div> is missing |
The "Important tags" button in the Vendors Manager shows the vendor ID inside the markup to paste, and the Edit vendor address holds the ID of every vendor. Write the markup with Replaceable Tags.
Custom elements for replaceable tags
Each custom element stands for a real element that loads only once the vendor is allowed to run. Privacy Consent adds a <div> right after the custom element and inserts the real element there. The custom element stays in the page, hidden.
| Custom element | Becomes | Embed placeholder before consent |
|---|---|---|
termsfeed-privacy-consent-tag-iframe |
<iframe> |
Yes |
termsfeed-privacy-consent-tag-img |
<img> |
Yes |
termsfeed-privacy-consent-tag-script |
<script> |
No |
termsfeed-privacy-consent-tag-style |
<style> |
No |
termsfeed-privacy-consent-tag-link |
<link> |
No |
The script finds custom elements once, when it starts. A custom element added later does not get an embed placeholder or load until a later page load finds it in the markup.
Element IDs and classes
The consent banner, the Preferences Center, the floating buttons, and the embed placeholders carry IDs and classes for your CSS and scripts. Your own elements open the Preferences Center with open_privacy_preferences_element, open_dnsmpi_element, open_privacy_choices_element, or the class termsfeed-pc1-open-privacy-preferences. Look up each selector in DOM and CSS Selectors.
Globals that are not part of the page API
Privacy Consent creates other globals for its own use, and page code that relies on them breaks when the script changes. Vendor globals belong to each vendor and carry consent signals only for a vendor added from a template. Check which vendor category sets each signal in Category Mapping.
| Global | What it is |
|---|---|
window.termsfeed_privacy_consent_bootstrap, window.termsfeed_privacy_consent_preferences, window.termsfeed_privacy_consent_vendors |
Internal to the script. Never set or call them. |
window.dataLayer, window.uetq, window.clarity |
Vendor globals Privacy Consent creates when missing and writes consent commands to, while a vendor carries that consent signal |
window.fbq, window.ttq, window.pintrk |
Vendor globals Privacy Consent calls when they exist and never creates |