getUSPData
Functionality
This function returns the US Privacy consent string from the CMP. In other words, it retrieves user consent for CCPA users. It is part of the US Privacy User Signal Mechanism “USP API”.
Syntax
function __uspapi()
argument name | type | optional | value | description |
---|---|---|---|---|
command | string |
|
|
|
version | integer |
|
| The USP API version in use. Can be null instead. |
callback | function |
|
| The callback function that is called with the function call result. |
Description
More information about getUSPData
can be found in the official IAB specification.
Scope
The function can be called at any time, but the response will change depending on when it is called.
Examples
Retrieve CCPA consent state
This example validates the CCPA Reference Code to check the user's consent. The code "1---" is considered as CCPA does not apply.
__uspapi("getUSPData", 1, function(uspData, success) {
if(success) {
// check if CCPA applies
if(uspData.uspString == "1---") {
console.log("ccpa does not apply");
} else if(uspData.uspString.toUpperCase().charAt(2) == 'Y') {
console.log("user has opted out");
} else {
console.log("full consent");
}
}
});