Skip to content

Latest commit

 

History

History
344 lines (261 loc) · 14.1 KB

API.md

File metadata and controls

344 lines (261 loc) · 14.1 KB

Modules

GetConsent

Functions

getUSPCookieValue([win])String | null

Get the cookie value for the USP string

Typedefs

GetConsentDataOptions : Object
OnUSPStringOptions : Object
ConsentPayload : Object
VendorConsentPayload : Object
GoogleConsentPayload : Object
WaitForConsentDataOptions : Object
Mem : Array

Memoized function collection

GetConsent

GetConsent.exports.getConsentData([options]) ⇒ Promise.<(null|ConsentPayload|VendorConsentPayload|GoogleConsentPayload)>

Get consent data from a CMP

Kind: static method of GetConsent
Returns: Promise.<(null|ConsentPayload|VendorConsentPayload|GoogleConsentPayload)> - A promise that resolves with consent data, or null if appropriate

Param Type Description
[options] GetConsentDataOptions Options for the CMP/consent request

GetConsent.exports.getConsentString([options]) ⇒ Promise.<(String|null)>

Get the current consent string, if available

Kind: static method of GetConsent

Param Type Description
[options] GetConsentDataOptions Options for the lookup

GetConsent.exports.getGoogleConsent([options]) ⇒ Promise.<(Number|null)>

Get the current Google consent state, if available

Kind: static method of GetConsent
Returns: Promise.<(Number|null)> - Returns 1 or 0 for Google consent, or null if not available and specified not to throw

Param Type Description
[options] GetConsentDataOptions Options for the lookup

GetConsent.exports.getUSPString([options]) ⇒ Promise.<(String|null)>

Get the USP string, if available (CCPA)

Kind: static method of GetConsent
Returns: Promise.<(String|null)> - The USP string if found or null

Param Type Description
[options] GetConsentDataOptions Options for the lookup

GetConsent.exports.getVendorConsentData([options]) ⇒ Promise.<(VendorConsentPayload|null)>

Get the current vendors consent state, if available

Kind: static method of GetConsent

Param Type Description
[options] GetConsentDataOptions Options for the lookup

GetConsent.exports.onConsentData(cb, [options]) ⇒ function

Listen for consent data and fire a callback once received

Kind: static method of GetConsent
Returns: function - Function to call to stop listening

Param Type Description
cb function The callback to fire - receives the ConsentPayload
[options] GetConsentDataOptions Options for the lookup

Example

const remove = onConsentData(
     (err, data) => {
         if (err) {
             console.error(err);
         } else {
             console.log("Consent payload:", data);
         }
     },
     { win: window.top }
 );
 // Later:
 remove();

GetConsent.exports.onConsentString(cb, [options]) ⇒ function

Listen for consent data and fire a callback with the consent string once received

Kind: static method of GetConsent
Returns: function - Removal function

Param Type Description
cb function Callback to fire - receives just the consent string or an error if not avail.
[options] GetConsentDataOptions

GetConsent.exports.onGoogleConsent(cb, [options]) ⇒ function

Listen for consent data and fire a callback with the consent string once received

Kind: static method of GetConsent
Returns: function - Removal function

Param Type Description
cb function Callback to fire - receives just the consent string or an error if not avail.
[options] GetConsentDataOptions

GetConsent.exports.onUSPString(cb, [options]) ⇒ function

Listen for a USP string and fire a callback with the privacy string once received

Kind: static method of GetConsent
Returns: function - Removal function

Param Type Description
cb function Callback to fire - called with (error, uspString): error if failed, or null and with uspString as following argument
[options] OnUSPStringOptions

GetConsent.exports.onVendorConsent(cb, [options]) ⇒ function

Listen for consent data and fire a callback with vendor consent data once received

Kind: static method of GetConsent
Returns: function - Removal function

Param Type Description
cb function Callback to fire - receives vendor consent data or an error if not avail.
[options] GetConsentDataOptions

GetConsent.exports.createMem() ⇒ Mem

Create a new memoization instance

Kind: static method of GetConsent

GetConsent.exports.uspApplies(str) ⇒ Boolean

Detect whether or not a value is indicative of USP applying to the user (does not detect whether or not the string disables data sales).

Kind: static method of GetConsent
Returns: Boolean - Whether or not a value is a USP string and whether or not USP applies due to it
See: uspOptsOut

Param Type Description
str String | * The USP string or value

Example

uspApplies("1---") // false
 uspApplies("1YN-") // true

GetConsent.exports.uspOptsOut(str) ⇒ Boolean

Detect whether or not a USP string opts a user out of data sales.

Kind: static method of GetConsent
Returns: Boolean - True if the value is a USP string that opts the user out from the sale of their data

Param Type Description
str String | * The USP string or value

Example

uspOptsOut("1---") // false
 uspOptsOut("1YYN") // true

getUSPCookieValue([win]) ⇒ String | null

Get the cookie value for the USP string

Kind: global function
Returns: String | null - The USP string or null if not found

Param Type Description
[win] Window Optional window override

GetConsentDataOptions : Object

Kind: global typedef
Properties

Name Type Description
[mem] Mem Memoization collection for caching results
[noConsent] String Action to take when no consent or fetching times-out. When set to "reject" (default), an error is thrown. When set to "resolve", null is returned.
timeout Number | null Timeout in milliseconds. Defaults to null (no timeout).
[type] String Type of consent data to fetch. Defaults to "" (generic CMP consent data). Can be set to "google" for Google consent data, "usp" for USP strings or "vendor" for vendors consent data.
[win] Window Optional window override.

OnUSPStringOptions : Object

Kind: global typedef
Properties

Name Type Description
[mem] Mem Optional mem instance override
[win] Window Optional window instance override

ConsentPayload : Object

Kind: global typedef
Properties

Name Type Description
consentData String Consent string for the user
gdprApplies Boolean Whether or not GDPR consent applies for this particular user
hasGlobalConsent Boolean ?
hasGlobalScope Boolean Whether or not the publisher is participating in the global scope for the IAB's consent framework

VendorConsentPayload : Object

Kind: global typedef
Properties

Name Type Description
gdprApplies Boolean Whether or not GDPR consent applies for this particular user
hasGlobalConsent Boolean ?
hasGlobalScope Boolean Whether or not the publisher is participating in the global scope for the IAB's consent framework
metadata String Base64 encoded header information
purposeConsents Object.<String, Boolean> Key-value list of purposes that the user has consented to. Key is a purpose ID, value is whether or not consent was granted.
vendorConsents Object.<String, Boolean> Key-value list of vendor IDs that the user has consented to

GoogleConsentPayload : Object

Kind: global typedef
Properties

Name Type Description
googlePersonalizationData Object Data related to Google personalization state
googlePersonalizationData.consentValue Number Either 1 or 0, indicating whether or not Google personalization consent was granted
googlePersonalizationData.created Date | null When the consent state was created for this user
googlePersonalizationData.lastUpdated Date | null When the consent state was last updated for this user

WaitForConsentDataOptions : Object

Kind: global typedef
Properties

Name Type Description
[cmpCmd] String CMP command to execute (default: "getConsentData")
cmpParam null | Boolean Extra parameter to send to CMP (default: null). If set to false it will not be provided in the __cmp call.
[validate] Boolean Validate CMP payload (only necessary for "getConsentData") (default: true)
[win] Window Optional window reference override

Mem : Array

Memoized function collection

Kind: global typedef