### Install @iabtechlabtcf/cli with npm Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cli/README.md Install the command line interface globally using npm. ```bash npm install -g @iabtechlabtcf/cli ``` -------------------------------- ### Install Dependencies with Yarn Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/CONTRIBUTING.md Run this command to install all necessary project dependencies. ```sh yarn install ``` -------------------------------- ### Install @iabtechlabtcf/cli with yarn Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cli/README.md Install the command line interface globally using yarn. ```bash yarn add -g @iabtechlabtcf/cli ``` -------------------------------- ### Install @iabtechlabtcf/stub with npm Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/stub/README.md Use this command to install the stub module via npm. ```bash npm install @iabtechlabtcf/stub ``` -------------------------------- ### Install @iabtechlabtcf/cmpapi Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cmpapi/README.md Install the cmpapi package using npm or yarn. ```bash npm install @iabtechlabtcf/cmpapi --save ``` ```bash yarn add @iabtechlabtcf/cmpapi ``` -------------------------------- ### Custom Commands Example Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cmpapi/README.md Demonstrates how to initialize CmpApi with custom commands like 'bingo' and 'connectBones', and how to invoke them using `__tcfapi`. ```javascript import {CmpApi} from '@iabtechlabtcf/cmpapi'; const cmpApi = new CmpApi(1, 3, false, { 'bingo': (callback, dogName) => { callback(`There was a farmer who had a dog, and ${dogName} was his name-o`); }, 'connectBones': (callback, startBone, endBone) => { callback(`The ${startBone} bone is connected to the ${endBone} bone.`); }, }); const songLyricCallback = (lyrics, success) => { if(success) { console.log(lyrics) } else { console.error('Error: could not get song lyrics') } } __tcfapi('bingo', 2, songLyricCallback, 'Bingo'); // ouput: There was a farmer who had a dog, and Bingo was his name-o __tcfapi('connectBones', 2, songLyricCallback, 'knee', 'thigh'); // ouput: The knee bone is connected to the thigh bone ``` -------------------------------- ### Install @iabtechlabtcf/testing with npm Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/testing/README.md Install the testing package as a development dependency using npm. ```bash npm install @iabtechlabtcf/testing --save-dev ``` -------------------------------- ### Install @iabtechlabtcf/stub with yarn Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/stub/README.md Use this command to install the stub module via yarn. ```bash yarn add @iabtechlabtcf/stub ``` -------------------------------- ### Install @iabtechlabtcf/testing with yarn Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/testing/README.md Install the testing package as a development dependency using yarn. ```bash yarn add -D @iabtechlabtcf/testing ``` -------------------------------- ### Build stub for direct page inclusion Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/stub/README.md Steps to clone the repository, install dependencies, and build the stub for direct inclusion on a page. ```bash git clone https://github.com/InteractiveAdvertisingBureau/iabtechlabtcf-es.git cd iabtechlabtcf-es/modules/stub/ yarn // or npm install yarn build // or npm run build ``` -------------------------------- ### Install @iabtechlabtcf/core with npm Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Use npm to install the core library for managing TCF data. ```bash npm install @iabtechlabtcf/core --save ``` -------------------------------- ### Install @iabtechlabtcf/core with yarn Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Use yarn to add the core library to your project for TCF data management. ```bash yarn add @iabtechlabtcf/core ``` -------------------------------- ### Custom Command Middleware Example Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cmpapi/README.md Shows how to use a custom 'getTCData' command as middleware to modify TCData before it's passed to the built-in command's response or event listeners. ```javascript import {CmpApi} from '@iabtechlabtcf/cmpapi'; const cmpApi = new CmpApi(1, 3, false, { 'getTCData': (next, tcData, status) => { /* * If using with 'removeEventListener' command, add a check to see if tcData is not a boolean. */ if (typeof tcData !== 'boolean') { // tcData will be constructed via the TC string and can be added to here tcData.reallyImportantExtraProperty = true; } // pass data and status along next(tcData, status); }, }); ``` -------------------------------- ### Get command queue from __tcfapi Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/stub/README.md Retrieve the queue of commands that have been processed by the TCF API stub. ```javascript const queue = __tcfapi(); console.log(queue); // [ ['command', 2, callback], ...] ``` -------------------------------- ### Get Vendors by Purpose Consent Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Retrieve vendors that require consent for a specific purpose. Ensure the GVL is loaded by waiting for `readyPromise`. ```javascript import {GVL} from '@iabtechlabtcf/core'; // only needs to be set once per application as this is a static variable GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/'; // loads 'http://cmp.mysupercoolcmp.com/cmp/vendor-list.json' const gvl = new GVL(); gvl.readyPromise.then(() => { const vendorMap = gvl.getVendorsWithConsentPurpose(1); // logs all vendor ids who have specified they require consent for purpose 1 Object.keys(vendorMap).forEach(console.log); }); ``` -------------------------------- ### Get Vendors by Purpose, Feature, or Legal Basis Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Provides methods to filter vendors based on their consent, feature, or legal basis requirements, returning an `IntMap`. ```APIDOC ## Get only vendors with a specific feature or purpose under legal basis A CMP UI may want to group vendors by what purpose they use under what legal basis and/or features. This can be accomplished quite easily by using one of the 6 grouping methods: * `getVendorsWithConsentPurpose(purposeId)` * `getVendorsWithFeature(featureId)` * `getVendorsWithFlexiblePurpose(purposId)` * `getVendorsWithLegIntPurpose(purposId)` * `getVendorsWithSpecialFeature(featureId)` * `getVendorsWithSpecialPurpose(purposId)` All 6 grouping methods return an `IntMap` object ### Method ```javascript import { GVL } from '@iabtechlabtcf/core'; // only needs to be set once per application as this is a static variable GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/'; // loads 'http://cmp.mysupercoolcmp.com/cmp/vendor-list.json' const gvl = new GVL(); gvl.readyPromise.then(() => { const vendorMap = gvl.getVendorsWithConsentPurpose(1); // logs all vendor ids who have specified they require consent for purpose 1 Object.keys(vendorMap).forEach(console.log); }); ``` ``` -------------------------------- ### Get specific version of GVL Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/testing/README.md Retrieve a specific version of the Global Vendor List (GVL) by version number. This allows for testing against historical GVL states. ```typescript import {GVLFactory} from '@iabtechlabtcf/testing'; import {GVL} from '@iabtechlabtcf/core'; const gvl = GVLFactory.getVersion(10); ``` -------------------------------- ### Get latest GVL Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/testing/README.md Retrieve the latest Global Vendor List (GVL) using GVLFactory. This is essential for TCF compliance checks and vendor information retrieval. ```typescript import {GVLFactory} from '@iabtechlabtcf/testing'; import {GVL} from '@iabtechlabtcf/core'; const gvl = GVLFactory.getLatest(); ``` -------------------------------- ### Encode Publisher TC Segment Only Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Generates only the Publisher TC segment using specific encoding options. This is useful for storing the Publisher TC segment separately, for example, in a first-party cookie, when `TCModel.isServiceSpecific` is false. ```typescript const encodingOptions = { segments: [Segment.PUBLISHER_TC] } const publisherTCSegment = TCString.encode(tcModel, encodingOptions); ``` -------------------------------- ### Compile and Minify for Production Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/CONTRIBUTING.md Run this command to create a production-ready build of the library. ```sh yarn build ``` -------------------------------- ### Custom Commands Initialization Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cmpapi/README.md Demonstrates how to initialize the CMP API with custom commands. ```APIDOC ## Custom Commands Initialization ### Description Initializes the `CmpApi` with a map of custom commands. The CMP is responsible for validation. ### Constructor `new CmpApi(1, 3, false, { customCommandName: (callback, ...params) => { ... } })` ### Example ```javascript import {CmpApi} from '@iabtechlabtcf/cmpapi'; const cmpApi = new CmpApi(1, 3, false, { 'bingo': (callback, dogName) => { callback(`There was a farmer who had a dog, and ${dogName} was his name-o`); }, 'connectBones': (callback, startBone, endBone) => { callback(`The ${startBone} bone is connected to the ${endBone} bone.`); }, }); const songLyricCallback = (lyrics, success) => { if(success) { console.log(lyrics) } else { console.error('Error: could not get song lyrics') } } __tcfapi('bingo', 2, songLyricCallback, 'Bingo'); // ouput: There was a farmer who had a dog, and Bingo was his name-o __tcfapi('connectBones', 2, songLyricCallback, 'knee', 'thigh'); // ouput: The knee bone is connected to the thigh bone ``` ``` -------------------------------- ### Show UI - New User - No TC String Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cmpapi/README.md For new users with no existing TC string, call `update` with an empty string and `true` to show the UI. ```javascript // showing the ui to the user cmpApi.update('', true); ``` ```javascript /** CMP gathers user preferences */ cmpApi.update(updatedEncodedTCString, false); ``` -------------------------------- ### Autoload Latest Vendor List Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Instantiate GVL by autoloading the latest vendor list. Ensure GVL.baseUrl is set. The GVL is ready after the readyPromise resolves. ```javascript import {GVL} from '@iabtechlabtcf/core'; // only needs to be set once per application as this is a static variable GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/'; // loads 'http://cmp.mysupercoolcmp.com/cmp/vendor-list.json' const gvl = new GVL(); gvl.readyPromise.then(() => { // GVL has loaded and it's ready to use }); ``` -------------------------------- ### Autoload Specific Vendor List Version Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Instantiate GVL by autoloading a specific version of the vendor list. Set GVL.baseUrl and pass the version number to the constructor. The GVL is ready after the readyPromise resolves. ```javascript import {GVL} from '@iabtechlabtcf/core'; // only needs to be set once per application as this is a static variable GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/'; // loads 'http://cmp.mysupercoolcmp.com/cmp/archives/vendor-list-v23.json' const gvl = new GVL(23); gvl.readyPromise.then(() => { // GVL has loaded and it's ready to use }); ``` -------------------------------- ### Test Project with Yarn Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/CONTRIBUTING.md Execute this command to run the project's test suite. ```sh yarn test ``` -------------------------------- ### Create CmpApi Instance Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cmpapi/README.md Instantiate the CmpApi class with your CMP ID, version, and service-specific scope setting. Optionally, pass a custom commands object. ```javascript import {CmpApi} from '@iabtechlabtcf/cmpapi'; const cmpApi = new CmpApi(1, 3, true); ``` -------------------------------- ### Create and Encode TC String Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Demonstrates creating a default 'all-no' TC string and encoding it. Ensure the GVL baseUrl is set before creating a GVL instance. The GVL must be loaded before encoding. ```javascript import {TCModel, TCString, GVL} from '@iabtechlabtcf/core'; /** * the IAB requires CMPs to host their own vendor-list.json files. This must * be set before creating any instance of the GVL class. */ GVL.baseUrl = "http://mydomain.com/cmp/vendorlist"; // create a new TC string const tcModel = new TCModel(new GVL()); // Some fields will not be populated until a GVL is loaded tcModel.gvl.readyPromise.then(() => { // Set values on tcModel... const encodedString = TCString.encode(tcModel); console.log(encodedString); // TC string encoded begins with 'C' }); // take an encoded TC string and decode into a TCModel const decodedTCModel = TCString.decode(encodedString); ``` -------------------------------- ### Include via module loading (ES Modules) Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/stub/README.md Import the stub module using ES module syntax. ```javascript import * as cmpstub from '@iabtechlabtcf/stub'; cmpstub(); ``` -------------------------------- ### Instantiate GVL with JSON Object Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Instantiate GVL directly by passing a vendor-list.json object. No asynchronous operation is involved, so the GVL is immediately ready for use. ```javascript import {GVL} from '@iabtechlabtcf/core'; const gvl = new GVL(gvljson); // no need for ready promise because no asynchronous action has occurred // gvl is ready to use ``` -------------------------------- ### Update for New User with No TC String Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cmpapi/README.md Handles the scenario of a new user with no existing TC string, showing the UI. ```APIDOC ## Update for New User with No TC String ### Description Used when a new user is encountered and no TC string exists. The UI will be displayed. ### Method `cmpApi.update('', true)` ### Parameters - `encodedTCString` (string): An empty string indicating no existing TC string. - `boolean` (true): Indicates that the UI should be shown to the user. ``` -------------------------------- ### Update TC String and Show UI Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cmpapi/README.md Demonstrates how to update the TC string and explicitly show the UI to the user. ```APIDOC ## Update TC String and Show UI ### Description This method is used to update the TC string and ensure the user interface is displayed. ### Method `cmpApi.update(encodedTCString, true)` ### Parameters - `encodedTCString` (string): The new TC string to be set. - `boolean` (true): Indicates that the UI should be shown to the user. ``` -------------------------------- ### Include via module loading (CommonJS) Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/stub/README.md Import the stub module using require for CommonJS environments. ```javascript const cmpstub = require('@iabtechlabtcf/stub'); cmpstub(); ``` -------------------------------- ### Autoload Latest Vendor List with Custom Filename Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Autoload the latest vendor list using a custom filename. Set GVL.baseUrl and GVL.latestFilename before instantiation. The GVL is ready after the readyPromise resolves. ```javascript import {GVL} from '@iabtechlabtcf/core'; // only needs to be set once per application as this is a static variable GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/'; GVL.latestFilename = 'latest/vendorlist.js'; // loads 'http://cmp.mysupercoolcmp.com/cmp/latest/vendorlist.json' const gvl = new GVL(); gvl.readyPromise.then(() => { // GVL has loaded and it's ready to use }); ``` -------------------------------- ### Cloning a GVL with a Non-Default Language Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Demonstrates how to clone a GVL instance, ensuring that any pending language change operations are resolved first to avoid unexpected behavior. ```APIDOC ## Cloning a GVL with a Non-Default language When cloning a GVL with a non-default language, make sure that any prior `changeLanguage` call is resolved. If changeLanguage has not yet resolved, `clone` will make an http request for the current language but will have no indication of resolving that request since it is synchronous. ### Method ```javascript import { GVL } from '@iabtechlabtcf/core'; const gvl = new GVL(); // Resolving changeLanguage promise using thenables. gvl.changeLanguage('fr').then(() => { const clone = gvl.clone(); }); // Resolving changeLanguage through async/await const someAsyncFunction = async () => { await gvl.changeLanguage('fr'); const clone = gvl.clone(); }; ``` ``` -------------------------------- ### Custom Command as Middleware Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cmpapi/README.md Explains how custom commands can act as middleware for built-in commands. ```APIDOC ## Custom Command as Middleware ### Description Custom commands can override built-in commands (except `addEventListener` and `removeEventListener`) to act as middleware, processing data before passing it along. ### Constructor Example ```javascript import {CmpApi} from '@iabtechlabtcf/cmpapi'; const cmpApi = new CmpApi(1, 3, false, { 'getTCData': (next, tcData, status) => { if (typeof tcData !== 'boolean') { tcData.reallyImportantExtraProperty = true; } next(tcData, status); }, }); ``` ### Notes - If using `getTCData` as middleware with `removeEventListener`, ensure `tcData` is not a boolean before modification. - The `next()` function must be called with the `TCData` object for the caller's callback to execute. ``` -------------------------------- ### Autoload Specific Vendor List Version with Custom Filename Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Autoload a specific vendor list version using a custom filename scheme. Set GVL.baseUrl, GVL.versionedFilename, and pass the version number to the constructor. The GVL is ready after the readyPromise resolves. ```javascript import {GVL} from '@iabtechlabtcf/core'; // only needs to be set once per application as this is a static variable GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/'; GVL.versionedFilename = 'vendorlist[VERSION].json'; // loads 'http://cmp.mysupercoolcmp.com/cmp/vendorlist23.json' const gvl = new GVL(23); gvl.readyPromise.then(() => { // GVL has loaded and it's ready to use }); ``` -------------------------------- ### Lint Project Files with Yarn Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/CONTRIBUTING.md Use this command to lint the project files for code style and quality. ```sh yarn lint ``` -------------------------------- ### Create TCModel Instance Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Instantiates a new TCModel. To encode a TCModel, a GVL must be included, and cmpId and cmpVersion must be set. ```javascript import {TCModel} from '@iabtechlabtcf/core'; // creates a TCModel const tcModel = new TCModel(); // to encode you must have a cmpId and cmpVersion tcModel.cmpId = //{myCMPID} tcModel.cmpVersion = //{myCMPVersion} /** * we now have a TCString assigned with a GVL which will set vendorListVersion, * tcfPolicyVersion and consentLanguage */ ``` -------------------------------- ### Change GVL Language (Default Filename) Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Change the language of the GVL after instantiation using the default language filename scheme. Ensure GVL.baseUrl is set. The promise resolves when the new language GVL is ready. ```javascript import {GVL} from '@iabtechlabtcf/core'; // only needs to be set once per application as this is a static variable GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/'; const gvl = new GVL(gvljson); // loads the French langauge gvl.changeLanguage('fr').then(() => { // French Language GVL is ready for use }); ``` -------------------------------- ### Handle GDPR Non-Applicability Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cmpapi/README.md Provides a method to inform the CMP API that GDPR does not apply. ```APIDOC ## Handle GDPR Non-Applicability ### Description In cases where GDPR is not applicable, this method updates the CMP API accordingly. ### Method `cmpApi.update(null)` ### Parameters - `null`: Indicates that GDPR does not apply. ``` -------------------------------- ### Manage Vendor Consents Vector Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Illustrates the methods for managing the vendorConsents Vector, including setting, checking, and removing individual vendor consents, setting multiple consents, and iterating or emptying the vector. ```javascript // Give Vendor ID 24 consent tcModel.vendorConsents.set(24); console.log(tcModel.vendorConsents.has(24)); // true console.log(tcModel.vendorConsents.maxId); // 24 console.log(tcModel.vendorConsents.size); // 1 // remove vendor 24 tcModel.vendorConsents.unset(24); console.log(tcModel.vendorConsents.has(24)); // false console.log(tcModel.vendorConsents.maxId); // 0 console.log(tcModel.vendorConsents.size); // 0 // give a group of vendors consent tcModel.vendorConsents.set([24, 14, 24, 100, 102]); console.log(tcModel.vendorConsents.has(24)); // true console.log(tcModel.vendorConsents.has(14)); // true console.log(tcModel.vendorConsents.has(200)); // false console.log(tcModel.vendorConsents.maxId); // 102 console.log(tcModel.vendorConsents.size); // 5 // loop through all ids 1 to maxId (102 loops) tcModel.vendorConsents.forEach((hasConsent, vendorId) => { // check each id for consent }); // empty everything tcModel.vendorConsents.empty(); console.log(tcModel.vendorConsents.has(24)); // false console.log(tcModel.vendorConsents.maxId); // 0 console.log(tcModel.vendorConsents.size); // 0 ``` -------------------------------- ### Change GVL Language (Custom Filename) Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Change the GVL language using a custom filename scheme. Set GVL.baseUrl and GVL.langaugeFilename before calling changeLanguage. The promise resolves when the new language GVL is ready. ```javascript import {GVL} from '@iabtechlabtcf/core'; const gvl = new GVL(gvljson); // only needs to be set once per application as this is a static variable GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/'; GVL.langaugeFilename = 'langauges/purp[LANG].json'; // loads the French langauge from 'http://cmp.mysupercoolcmp.com/purpfr.json' gvl.changeLanguage('fr').then(() => { // French Language GVL is ready for use }); ``` -------------------------------- ### Set CMP Meta Fields Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Sets the basic CMP meta fields required for all TC strings: cmpId, cmpVersion, and consentScreen. ```javascript import {TCModel} from '@iabtechlabtcf/core'; const tcModel = new TCModel(); tcModel.cmpId = // my CMP ID tcModel.cmpVersion = // my CMP Version tcModel.consentScreen = // On which 'screen' consent was captured; this is a cmp proprietary number encoded into the TC string ``` -------------------------------- ### Decode TCF String with CLI Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cli/README.md Use the CLI to decode a given TCF string and display its decoded properties. ```bash ! tcstring COrVd1pOrVd1pACABCENAHCAAAAAAAAAAAiQAAAAAAAA encoded: "COrVd1pOrVd1pACABCENAHCAAAAAAAAAAAiQAAAAAAAA" version: 2 cmpId: 2 cmpVersion: 1 consentScreen: 2 consentLanguage: "EN" created: Mon Dec 09 2019 00:00:00 GMT lastUpdated: Mon Dec 09 2019 00:00:00 GMT policyVersion: 2 isServiceSpecific: false useNonStandardTexts: false purposeOneTreatment: false publisherCountryCode: "ES" supportOOB: false vendorListVersion: 7 purposeConsents purposeLegitimateInterest specialFeatureOptIns publisherCustomConsents publisherLegitimateInterest publisherCustomConsents publisherCustomLegitimateInterest vendorConsents vendorLegitimateInterest vendorsDisclosed vendorsAllowed ``` -------------------------------- ### Set Publisher Restrictions Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Demonstrates how to set publisher restrictions for vendors. This involves creating a PurposeRestriction object with the purpose ID and restriction type, then adding it to the TCModel's publisherRestrictions. ```javascript import {TCModel, PurposeRestriction, RestrictionType} from '@iabtechlabtcf/core'; // first you must create a PurposeRestriction const purposeRestriction = new PurposeRestriction(); purposeRestriction.purposeId = 2; purposeRestriction.restrictionType = RestrictionType.NOT_ALLOWED; // vendorID and restriction tcModel.publisherRestrictions.add(2000, purposeRestriction); ``` -------------------------------- ### Show UI - TC String Needs Update Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cmpapi/README.md Call `update` with the encoded TC string and `true` to display the UI when an update is required. ```javascript // showing the ui to the user cmpApi.update(encodedTCString, true); ``` ```javascript /** CMP gathers user preferences */ cmpApi.update(updatedEncodedTCString, false); ``` -------------------------------- ### Clone GVL with Non-Default Language Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Clone a GVL instance after ensuring any pending language change has resolved. Failure to do so may result in an incomplete clone. ```javascript import {GVL} from '@iabtechlabtcf/core'; const gvl = new GVL(); // Resolving changeLanguage promise using thenables. gvl.changeLanguage('fr').then(() => { const clone = gvl.clone(); }) // Resolving changeLanguage through async/await const someAsyncFunction = async () => { await gvl.changeLanguage('fr'); const clone = gvl.clone(); } ``` -------------------------------- ### GDPR Doesn't Apply Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cmpapi/README.md When GDPR does not apply, call `update` with `null` to inform the CmpApi. ```javascript // only one update needed to let CmpApi that gdpr doesn't apply cmpApi.update(null); ``` -------------------------------- ### Narrow Vendor List Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Filter the GVL instance to include only a specified subset of vendors. This affects subsequent operations like `getVendorsWithLegIntPurpose`. ```javascript import {GVL} from '@iabtechlabtcf/core'; // only needs to be set once per application as this is a static variable GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/'; // loads 'http://cmp.mysupercoolcmp.com/cmp/vendor-list.json' const gvl = new GVL(); gvl.readyPromise.then(() => { // now this gvl instance only has these 3 vendors gvl.narrowVendorsTo([1,2,3]); // will only show the Vendor objects for 1, 2, and 3 console.log(gvl.vendors); // will only return the vendors within the narrowed vendor list const vendorsWithLegInt2 = gvl.getVendorsWithLegIntPurpose(2); }); ``` -------------------------------- ### Don't Show UI - TC String Does Not Need Update Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cmpapi/README.md Call `update` with the encoded TC string and `false` to avoid displaying the UI when no update is needed. ```javascript // not showing the ui to the user, only one update is needed cmpApi.update(encodedTCString, false); ``` -------------------------------- ### Generate random TCModel with GVL Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/testing/README.md Create a randomized TCModel instance that includes GVL data. This is useful for simulating a complete TCF string. ```typescript import {TCModelFactory} from '@iabtechlabtcf/testing'; const tcModel = TCModelFactory.withGVL(); ``` -------------------------------- ### Narrowing the Vendor List Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Allows filtering the GVL to a specific subset of vendors, affecting subsequent operations like vendor lookups. ```APIDOC ### Narrow the list of vendors If loading a CMP would like to show a subset of the Vendor List a filter may be passed to only work with those vendors on the list. ### Method ```javascript import { GVL } from '@iabtechlabtcf/core'; // only needs to be set once per application as this is a static variable GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/'; // loads 'http://cmp.mysupercoolcmp.com/cmp/vendor-list.json' const gvl = new GVL(); gvl.readyPromise.then(() => { // now this gvl instance only has these 3 vendors gvl.narrowVendorsTo([1, 2, 3]); // will only show the Vendor objects for 1, 2, and 3 console.log(gvl.vendors); // will only return the vendors within the narrowed vendor list const vendorsWithLegInt2 = gvl.getVendorsWithLegIntPurpose(2); }); ``` ``` -------------------------------- ### Update TC String without Showing UI Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cmpapi/README.md Shows how to update the TC string when no UI update is necessary. ```APIDOC ## Update TC String without Showing UI ### Description This method updates the TC string without displaying the user interface, typically when the TC string does not require an update. ### Method `cmpApi.update(encodedTCString, false)` ### Parameters - `encodedTCString` (string): The new TC string to be set. - `boolean` (false): Indicates that the UI should not be shown to the user. ``` -------------------------------- ### Disable CmpApi Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cmpapi/README.md Call `cmpApi.disable()` to permanently place the CmpApi in an error state, allowing only ping and custom commands. ```javascript cmpApi.disable(); ``` -------------------------------- ### Encode an IAB TC String Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Encodes a `TCModel` object into an IAB TC String. Requires a GVL instance to be ready. ```APIDOC ### Encode an IAB TC String ```typescript import { TCString, TCModel, GVL } from '@iabtechlabtcf/core'; /** * With v2.0 of the TCF, CMPs are required to host their own vendor-list.json for * their client-side scripts to consume. This GVL class follows the convention * outlined in the GVL URL Version scheme. (latest at vendor-list.json and * version specific at archives/vendor-list-v{vendor-list-version}.json */ GVL.baseUrl = "http://mydomain.com/cmp/vendorlist"; // we'll get the latest GVL to encode this TCString to const gvl = new GVL("LATEST"); // have to wait for it to fetch the json gvl.readyPromise.then(() => { const tcModel = new TCModel(gvl); const encodedTCString = TCString.encode(tcModel); /** * this will output a default all "no" encoded string to the console at the * lastest GVL version. */ console.log(encodedTCString); }); ``` ``` -------------------------------- ### Decoding a Segment At A Time Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Allows decoding individual TC String segments and merging them into an existing `TCModel`, useful for managing segments stored separately. ```APIDOC ### Decoding A Segment At A Time It is possible to pass a reference to an already created `TCModel` and add individual segments to the model. An important use case for this is if using a globally-scoped TC string and storing the Publisher TC Segment separately in a first-party cookie. ```typescript import { TCString, Segment } from '@iabtechlabtcf/core'; // if you had a getCookie function that returned just that segment const publisherTCSegment = getCookie('euconsent-ptc'); let tcModel; // if you had an asynchronous function to get the cookie from global getGlobalTCString().then((encodedTCString) => { tcModel = TCString.decode(encodedTCString); TCString.decode(publisherTCSegment, tcModel); // now you have a combined TCModel }); ``` ``` -------------------------------- ### Disable CMP API Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cmpapi/README.md Disables the CMP API, putting it into a permanent error state. ```APIDOC ## Disable CMP API ### Description Disables the `CmpApi` to prevent further operations in compliance with TCF, except for ping and custom commands. ### Method `cmpApi.disable()` ``` -------------------------------- ### Add random publisher restrictions to TCModel Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/testing/README.md Add randomized publisher restrictions to an existing TCModel. This is useful for testing how different publisher restriction configurations are handled. ```typescript import {TCModelFactory} from '@iabtechlabtcf/testing'; let tcModel = TCModelFactory.withGVL(); tcModel = TCModelFactory.addPublisherRestrictions(tcModel); // now has random publisher restrictions ``` -------------------------------- ### Update TC String Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/cmpapi/README.md Call the update method with an encoded TC string, an empty string, or null to trigger consent data updates and events. ```javascript cmpApi.update(encodedTCString || '' || null); ``` -------------------------------- ### Encode IAB TC String Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Encode a TCModel object into an IAB TCF TC String. Requires a GVL instance to be ready to fetch the latest vendor list. ```typescript import {TCString, TCModel, GVL} from '@iabtechlabtcf/core'; /** * With v2.0 of the TCF, CMPs are required to host their own vendor-list.json for * their client-side scripts to consume. This GVL class follows the convention * outlined in the GVL URL Version scheme. (latest at vendor-list.json and * version specific at archives/vendor-list-v{vendor-list-version}.json */ GVL.baseUrl = "http://mydomain.com/cmp/vendorlist"; // we'll get the latest GVL to encode this TCString to const gvl = new GVL("LATEST"); // have to wait for it to fetch the json gvl.readyPromise.then(() => { const tcModel = new TCModel(gvl); const encodedTCString = TCString.encode(tcModel); /** * this will output a default all "no" encoded string to the console at the * lastest GVL version. */ console.log(encodedTCString); }); ``` -------------------------------- ### Encode TC String for CMP API Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Encodes a TC String specifically for the __tcfapi function, which includes necessary segments for CMP interaction. This is the default behavior for CMPs. ```typescript import {TCString, Segment} from '@iabtechlabtcf/core'; // produces the version of the string for the __tcfapi function const cmpApiEncodedString = TCString.encode(tcModel, { isForVendors: true }); ``` -------------------------------- ### Generate random TC string Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/testing/README.md Generate a random TC string by encoding a TCModel that does not include GVL data. This is useful for testing TC string parsing and decoding. ```typescript import {TCString} from '@iabtechlabtcf/core'; import {TCModelFactory} from '@iabtechlabtcf/testing'; console.log(TCString.encode(TCModelFactory.noGVL())); // ... random tc string ``` -------------------------------- ### Decode an IAB TC String Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Decodes a given IAB TC String into a `TCModel` object, providing access to the TCF data. ```APIDOC ### Decode an IAB TC String ```typescript import { TCString, TCModel } from '@iabtechlabtcf/core'; const myTCModel = TCString.decode(encodedTCString); ``` *returns:* [`TCModel`](#tcmodel) ``` -------------------------------- ### Encode TC String with Custom Segments Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Encodes a TC String using custom encoding options to override the default segments. This is not recommended unless you have a specific reason and understand the implications. ```typescript const encodingOptions = { segments: [ Segment.CORE, Segment.VENDORS_DISCLOSED, Segment.VENDORS_ALLOWED, Segment.PUBLISHER_TC, ] } const customEncodedString = TCString.encode(tcModel, encodingOptions); ``` -------------------------------- ### Decode TC String Segments Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Decode individual TC String segments and merge them into an existing TCModel. Useful for combining global TC strings with locally stored segments like publisher TC segments. ```typescript import {TCString, Segment} from '@iabtechlabtcf/core'; // if you had a getCookie function that returned just that segment const publisherTCSegment = getCookie('euconsent-ptc'); let tcModel; // if you had an asynchronous function to get the cookie from global getGlobalTCString().then((encodedTCString) => { tcModel = TCString.decode(encodedTCString); TCString.decode(publisherTCSegment, tcModel); // now you have a combined TCModel }); ``` -------------------------------- ### Decode IAB TC String Source: https://github.com/interactiveadvertisingbureau/iabtcf-es/blob/master/modules/core/README.md Decode an encoded IAB TCF TC String into a TCModel object. Ensure the `TCString` and `TCModel` are imported. ```typescript import {TCString, TCModel} from '@iabtechlabtcf/core'; const myTCModel = TCString.decode(encodedTCString); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.