Compliant with GDPR, CCPA, COPPA, LGPD, PECR, PDPA, PIPEDA, and more.
Custom Purposes allow you to define your own consent purposes beyond the standard IAB TCF purposes and Google Consent Mode types. They are displayed in the consent UI, stored separately from TCF consent, and can be queried via JavaScript API or used with UnicScript tag loading.
custom_analytics, ab_testing, newsletter_tracking). This ID is used in storage, dataLayer, tag loading, and API queries.You can add multiple custom purposes. Each must have a unique ID.
__unic_custom_consent), independent from TCF consent strings and Google Consent Mode.Use getCustomConsent to retrieve the current consent status of all custom purposes:
__tcfapi('getCustomConsent', 2, function(data, success) {
if (success) {
console.log(data);
// Example output: { "custom_analytics": true, "ab_testing": false }
}
});
Or using the __unicapi alias:
__unicapi('getCustomConsent', 2, function(data, success) {
if (success) {
// Check a specific custom purpose
if (data['custom_analytics']) {
// Custom analytics consent is granted
}
}
});
Custom purpose consent status is pushed to the dataLayer as UNIC_CP_{id}:
// Listen for consent data
(function waitCMP() {
var readyCMP;
if (!readyCMP && window['dataLayer']) {
window['dataLayer'].forEach(function(event) {
if (event['event'] === 'unic_data') {
readyCMP = 1;
console.log(event['UNIC_CP_custom_analytics']); // true or false
console.log(event['UNIC_CP_ab_testing']); // true or false
}
});
}
if (!readyCMP) {
setTimeout(waitCMP, 100);
}
})();
You can conditionally load scripts and iframes based on custom purpose consent using the unic-cp-id and unic-cp-ids attributes.
<script type="text/unicscript" unic-cp-id="custom_analytics">
console.log('Custom analytics consent granted');
</script>
<script type="text/unicscript" unic-cp-id="custom_analytics" src="https://example.com/analytics.js"></script>
All specified purposes must be consented for the script to load:
<script type="text/unicscript" unic-cp-ids="custom_analytics,ab_testing">
console.log('Both custom analytics and A/B testing consent granted');
</script>
<iframe
data-unicscript
unic-cp-id="custom_analytics"
width="560"
height="315"
data-src="https://example.com/widget"
frameborder="0"
></iframe>
<iframe
data-unicscript
unic-cp-ids="custom_analytics,ab_testing"
width="560"
height="315"
data-src="https://example.com/widget"
frameborder="0"
></iframe>
In GTM, you can use the dataLayer variables UNIC_CP_{id} to create triggers based on custom purpose consent:
UNIC_CP_custom_analytics.UNIC_CP_custom_analytics equals true.Custom consent data is stored under the __unic_custom_consent key in localStorage (web) or native key-value storage (mobile apps). The format is:
{
"custom_analytics": true,
"ab_testing": false
}
This storage is independent from:
euconsent-v2)__unic_consent_mode)Custom consent is cleared when users reset their consent via the CMP.
Contact us: support@uniconsent.com