getCustomVendorConsents

The getCustomVendorConsents command returns an object that contains information on IAB and custom vendors an end-user consents to, and the legitimate interest and consent purposes mapped to a vendor.


Command

//call the __tcfapi() function from the browser console with the getCustomVendorConsents command 
__tcfapi('getCustomVendorConsents', 2, function(data, success) {console.log("getCustomVendorConsents response: ", data, " + ", success);});
/*
This example also uses the addEventListener commandthat allows your organization to listen to 
specific events (e.g. an end-user changes their consent), and automatically perform 
custom actions in response.
*/
...
function show_cvc(data)  {
    var vendors = Object.keys(data.grants);
    var grants = Object.values(data.grants);
    console.log("date created - " + data.dateCreated);
    console.log("new user - " + data.newUser);
    for(i in vendors) {
       var vendor = vendors[i];
       console.log(" ");
       console.log("for vendor - " + vendor);
       console.log(" >> vendor grant - " + grants[i].vendorGrant);
       var purpose_grants = grants[i].purposeGrants;
       var purposes = Object.keys(purpose_grants);
       var purpose_consent = Object.values(purpose_grants);
       for(j in purposes)   {
          console.log(" >> purpose id " + purposes[j] + " has consent given - " + purpose_consent[j]);
       }
    }
    console.log(" ");
    var consented_purposes = data.consentedPurposes;
    for(i in consented_purposes)  {
       var purpose = consented_purposes[i];
       console.log("purpose id " + purpose._id + " is " + purpose.name);
    }
    console.log(" ");
    var consentedCustomVendors = data.consentedVendors;
    for(i in consentedCustomVendors) {
       var custom_vendor = consentedCustomVendors[i];
       console.log("purpose id " + custom_vendor._id + " is " + custom_vendor.name + " and type " + custom_vendor.vendorType);
    }
    console.log(" ");
    var legitimateInterestPurposes = data.legIntPurposes;
    for(i in legitimateInterestPurposes)   {
       var li_purpose = legitimateInterestPurposes[i];
       console.log("legitimate interest purpose id " + li_purpose._id + " is " + li_purpose.name);
    }
 }

 __tcfapi('addEventListener', 2, function(tcdata, success) {
    if(success) {

       // call TCF API getCustomVendorConsent command
       __tcfapi('getCustomVendorConsents', 2, (data, success) => {
          show_cvc(data);
       });

       if (tcdata.eventStatus === 'useractioncomplete') {
          // call code when user has made an action
       } else if (tcdata.eventStatus === 'tcloaded') {
          // call code when consent string has loaded
       } else if (tcdata.eventStatus === 'cmpuishown') {
          // call code when cmp message is shown
       }
    }
 });
 ...

Response

{
  "consentedAll": true,
  "consentedPurposes": [
    {
      "_id": "5fd7e01e32bd4d27654ba1d5",
      "name": "Select basic ads"
    }
  ],
  "consentedVendors": [
    {
      "_id": "abcde01e32bd4d27654ba1d5",
      "name": "Vendor example name",
      "vendorType": "CUSTOM"
    }
  ],
  "dateCreated": "2023-05-26T14:12:48.333Z",
  "grants": {
    "5f1aada6b8e05c306c0597d7": {
      "purposeGrants": {
        "5fd7e01e32bd4d27654ba1d5": true
      },
      "vendorGrant": true
    }
  },
  "legIntPurposes": [
    {
      "_id": "6011ea75c5d9c787531b3ede",
      "name": "Apply market research to generate audience insights"
    }
  ],
  "newUser": false
}
schema:
  description: getCustomVendorConsents response
  type: object
  properties:
    consentedAll:
      type: boolean
      description: End-user has consented to all vendors
    consentedPurposes:
      type: array
      description: Lists the purposes that apply to the end-user
      items:
        type: object
        properties:
          _id:
            type: string
            description: Purpose ID
          name:
            type: string
            description: Purpose name in vendor list
    consentedVendors:
      type: array
      description: Lists the custom vendors in the vendor list that apply to the end-user
      items:
        type: object
        properties:
          _id:
            type: string
            description: Custom vendor ID
          name:
            type: string
            description: Custom vendor name as described in vendor list
          vendorType:
            type: string
            description: The vendor type, if the vendor is custom or affiliated to the IAB
    dateCreated:
      type: string
      description: Date consent status was created
    grants:
      type: object
      description: Contains the applicable purposes and the consent status for that vendor
      properties:
        vendorId: #value will be a string of the vendor's ID
          type: object
          properties:
            purposeGrants:
              type: object
              description: Contains all applicable purposes (identified by its purpose_id) for the vendor and whether consent was given from the end-user.
              properties:
                purposeId: #value will be a string of the purpose ID
                  type: boolean
            vendorGrant:
              type: boolean
              description: true if end-user granted consent to all applicable purposes for the vendor | false if end-user has not given consent to one or more applicable purposes for the vendor
    legIntPurposes:
      type: array
      description: Lists a purpose who uses legitimate interest as a legal basis for at least one vendor on your vendor list.
      items:
        type: object
        properties:
          _id:
            type: string
            description: The purpose ID
          name:
            type: string
            description: Purpose name as described in vendor list
    newUser:
      type: boolean
      description: Is the end-user a first time visitor to the property?