GDPR Functions
Reference guide for GDPR functions provided by Tealium for JavaScript.
The following utag.gdpr
functions are available:
Function | Description |
---|---|
dns.getDnsState() |
Returns the value of the dns consent cookie |
dns.setDnsState() |
Sets the value of the dns consent cookie |
getCategories() |
Returns an Array with the list of compliance categories available for grouping tags |
getCategoryLanguage() |
Returns an Object with the category name and description in the active language |
getConsentState() |
Returns the consent given by the user either as full, declined, no consent, or partial consent |
getCookieValues() |
Returns an Object representing the consent cookie |
getLanguage() |
Returns a String with the language used for displaying the consent manager content |
getSelectedCategories() |
Returns an Array with the selected categories by the customer |
setAllCategories() |
Sets all categories to the same consent state of either consented or declined, and (optionally) calls the Collect API to track the consent |
setConsentValue() |
Sets the consent cookie value to enabled or disabled |
setCookie() |
Internal function that writes directly to the cookie object |
setCookieValue() |
Sets an individual value in the consent cookie |
setPreferencesFromList() |
Sets the consent state to allowed for a list of categories |
setPreferencesValues() |
Sets the cookie values from an object of categories and their consent state |
showConsentPreferences() |
Displays the preferences manager pop-up |
showDoNotSellBanner() |
Displays the CCPA banner |
showDoNotSellPrompt() |
Displays the CCPA banner |
showExplicitConsent() |
Displays the explicit consent pop-up |
updateConsentCookie() |
Updates mobile consent from an app using hidden webview |
utag.gdpr.dns.getDnsState()
Returns the value of the dns
consent cookie.
Example:
utag.gdpr.dns.getDnsState()
true
utag.gdpr.dns.setDnsState()
Sets the value of the dns consent cookie. Recognized values: true, false, 1, 0, “true,” “false.”
Example:
utag.gdpr.dns.setDnsState(true);
utag.gdpr.getCategories()
Returns an Array
with the list of compliance categories available for grouping tags. All categories are returned if no parameter is provided. Pass true
or 1
as a parameter to only return enabled (active) categories in the Tealium Consent Preference Manager interface.
utag.gdpr.getCategories(onlyEnabledCats)
Parameter | Type | Description |
---|---|---|
onlyEnabledCats |
Boolean |
(Optional) Set to true or 1 to return enabled (active) categories |
The following example returns all categories:
utag.gdpr.getCategories()
// Returns: ["analytics", "affiliates", "display_ads", "search", "email", "personalization", "social", "big_data", "misc", "cookiematch", "cdp", "mobile", "engagement", "monitoring", "crm"]
The following example returns enabled categories:
utag.gdpr.getCategories(true)
// Returns: ["analytics", "affiliates", "personalization"]
utag.gdpr.getCategoryLanguage()
Returns an Object
with the category name and description in the active language from the Consent Preferences Manager interface “Category Parameters.” The language of the category is the language returned by the getLanguage()
function.
utag.gdpr.getCategoryLanguage(category)
Parameter | Type | Description |
---|---|---|
category |
String |
Name of category |
Example:
utag.gdpr.getCategoryLanguage("analytics")
// if language is English, returns:
//{name: "Cookies that help us improve our website", notes: "These cookies help us understand how people use our website."}
// if language is Polish, returns:
//{name: "Pliki cookie dotyczące wydajności", notes: "Te pliki cookie gromadzą informacje o tym, jak odw…dynie w celu ulepszania działania naszej witryny."}
utag.gdpr.getConsentState()
Returns the consent given by the user either as full, declined, no consent, or partial consent. When full consent, declined consent, or no consent is given, the following consent state values are returned:
Consent State | Description |
---|---|
-1 |
Consent was declined (consent:false on the cookie) |
0 |
No consent is given (no cookie present) |
1 |
Full consent was given (consent:true on the cookie) |
In case of partial consent, the function returns an array of objects each representing a category. In each object, the "ct"
key represents the consent state (1/0), and the "name"
key is the category denomination.
utag.gdpr.getConsentState()
Examples:
utag.gdpr.getConsentState()
// 0
// no consent was given, cookie is not present
utag.gdpr.getConsentState()
// 1
// cookie value is true
utag.gdpr.getConsentState()
//partial consent
/* Returns: [{"ct":"1","name":"analytics"},
{"ct":"0","name":"affiliates"},
{"ct":"0","name":"display_ads"},
{"ct":"0","name":"search"},
{"ct":"0","name":"email"},
{"ct":"0","name":"personalization"},
{"ct":"0","name":"social"},
{"ct":"0","name":"big_data"},
{"ct":"0","name":"misc"},
{"ct":"0","name":"cookiematch"},
{"ct":"0","name":"cdp"},
{"ct":"0","name":"mobile"},
{"ct":"0","name":"engagement"},
{"ct":"0","name":"monitoring"},
{"ct":"0","name":"crm"}]"
*/
utag.gdpr.getCookieValues()
Returns an Object
representing the consent cookie as key-value pairs. This function uses the default cookie namespace (CONSENTMGR
) or the value provided in window.utag_cfg_ovrd.cmcookiens
. The reverse function (writing into the cookie) is utag.gdpr.setCookie()
.
Instead of using this function directly, it is recommended use a function such as utag.gdpr.getConsentState()
, which calls the getCookieValues()
function to read the cookie.
utag.gdpr.getCookieValues()
The following example gives partial consent:
utag.gdpr.getCookieValues()
/* Returns:
{
"c1":"1",
"c2":"0",
"c3":"0",
"c4":"0",
"c5":"0",
"c6":"0",
"c7":"0",
"c8":"0",
"C9":"0",
"c10":"0",
"c11":"0",
"c12":"0",
"c13":"0",
"c14":"0",
"c15":"0",
"ts":"1586965568213",
"consent":"true"
}*/
The following example gives full consent:
utag.gdpr.getCategories(true)
// Returns: {"consent":"true","ts":"1587026030058"}
utag.gdpr.getLanguage()
Returns a String
with the language used for displaying the consent manager content. Ordered by precedence of the language as set up in the data layer, the language from the browser, or the default language.
utag.gdpr.getLanguage()
Example:
utag.gdpr.getLanguage()
// Returns: "en-gb"
utag.gdpr.getSelectedCategories()
Returns an Array
with the selected categories by the customer.
utag.gdpr.getSelectedCategories()
Example:
utag.gdpr.getSelectedCategories()
// Returns: ["analytics", "personalization"]
utag.gdpr.setAllCategories()
Sets all categories to the same consent state of either consented or declined, and (optionally) calls the Collect API to track the consent.
utag.gdpr.setAllCategories(state, noCollect)
Parameter | Type | Description |
---|---|---|
state |
Boolean |
Set to true to allow consent to all categories, set to false to decline consent |
noCollect |
Boolean |
(Optional) Set to true to not fire a call to the Collect API to track the consent |
The following example allows consent for all categories, with no call to the Collect API:
utag.gdpr.setAllCategories(true,true)
The following example declines consent for all categories, and calls the Collect API to track the consent:
utag.gdpr.setAllCategories(false)
utag.gdpr.setConsentValue()
Sets the consent cookie value to enabled or disabled. The function also updates the timestamp of consent, and generates a tracking call to the Collect API, and replays tags that are kept in the queue utag.gdpr.queue
.
This doesn’t change the consent value of individual categories that needs to be disabled via the relevant API call (setPreferencesFromList()
or setPreferencesValues()
).
utag.gdpr.setConsentValue(_response)
Parameter | Type | Description |
---|---|---|
_response |
Boolean |
Set to true enable consent, or false to disable consent |
The following example sets to cookie to have value "consent:true"
and updates the timestamp:
utag.gdpr.setConsentValue(true)
The following example sets to cookie to have value "consent:false"
and updates the timestamp:
utag.gdpr.setConsentValue(0)
utag.gdpr.setCookie()
Internal function that writes directly to the cookie object. It uses an object to represent the consent state, the timestamp, and the various categories for partial consent. It automatically uses the correct cookie name and expiry period.
It is not recommended to call this function directly.
utag.gdpr.setCookie(onlyEnabledCats)
Parameter | Type | Description |
---|---|---|
cookieData |
Object |
List of key values representing the data stored in the consent cookie |
Example:
var object = {"c6":"1","c1":"0","c2":"0","ts":1587133550264,"consent":"false","c3":"0","c4":"0","c5":"0","c7":"0","c8":"0","c9":"0","c10":"0","c11":"0","c12":"0","c13":"0","c14":"0","c15":"0"}"
utag.gdpr.setCookie(object)
// Sets the cookie to: c6:1%7Cc1:0%7Cc2:0%7Cts:1587133526482%7Cconsent:false%7Cc3:0%7Cc4:0%7Cc5:0%7Cc7:0%7Cc8:0%7Cc9:0%7Cc10:0%7Cc11:0%7Cc12:0%7Cc13:0%7Cc14:0%7Cc15:0
utag.gdpr.setCookieValue()
Sets an individual value in the consent cookie.
This function is used by other higher level functions such as setConsentValue()
. Use this method cautiously and only if higher level functions do not fulfill the initial needs.
utag.gdpr.setCookieValue(key, value);
Parameter | Type | Description |
---|---|---|
key |
String |
Key used in the cookie that is set to either consent , ts or any of the categories specified by the c value representation, such as c1 for Analytics or c2 for Affiliates |
value |
String |
The value to set the cookie key |
The following example sets consent cookie to "consent:false"
:
utag.gdpr.setCookieValue("consent", false);
The following example sets consent cookie to "c1:0"
:
utag.gdpr.setCookieValue("c1", 0);
utag.gdpr.setPreferencesFromList()
Sets the consent state to allowed
for the list of categories passed in the parameter. The consent state of the categories not part of the list are set to declined
. This is used for partial consent. This function relies on the setPreferencesValues()
function and provides the reverse functionality of getSelectedCategories()
.
utag.gdpr.setPreferencesFromList(list)
Parameter | Type | Description |
---|---|---|
List |
Array |
Array of valid categories |
Example:
utag.gdpr.setPreferencesFromList(["analytics"])
// Only allows the "analytics" category in the consent cookie
utag.gdpr.getCategories(true)
//["analytics", "affiliates", "personalization"]
utag.gdpr.setPreferencesValues()
Sets the cookie preferences values from an object of categories and their consent state. This function is mainly called by the setPreferencesFromList()
function. This function replays the tags that are kept in the queue utag.gdpr.queue
.
utag.gdpr.setPreferencesValues(state, noCollect)
Parameter | Type | Description |
---|---|---|
state |
Object |
Key-value pairs in the format category:consentState |
noCollect |
Boolean |
(Optional) Set to true to not fire a call to the Collect API to track the consent |
The following example sets the cookie value:
Var cats = {"analytics":"1","affiliates":"0","personalization":"0"}
utag.gdpr.setPreferencesValues(cats)
// Sets cookie to c6:1%7Cc1:0%7Cc2:0%7Cts:1587135590035%7Cconsent:true
utag.gdpr.showConsentPreferences()
Displays the consent preferences pop-up. This function injects the CSS, the HTML and the Javascript defined in the customizations in the page. It is called by the explicit consent javascript listener or from any point in the page where the user wants to modify their preferences.
utag.gdpr.showConsentPreferences(_lang)
Parameter | Type | Description |
---|---|---|
_lang |
String |
Optional. Language as an ISO format, such as en or en-gb |
The following example displays consent in the default language or language set up in data layer:
utag.gdpr.showConsentPreferences()
The following example displays consent in French:
utag.gdpr.showConsentPreferences("fr-fr")
utag.gdpr.showDoNotSellBanner()
Displays the Opt-out banner. By default, this function is called when the enforcement rule evaluates to true.
utag.gdpr.showDoNotSellBanner(_lang)
Parameter | Type | Description |
---|---|---|
_lang |
String |
Optional. Language as an ISO format, such as en or en-gb |
The following example displays the Opt-out banner in the default language or language set up in data layer:
utag.gdpr.showDoNotSellBanner()
The following example displays the Opt-out banner in French:
utag.gdpr.showDoNotSellBanner("fr-fr")
utag.gdpr.showDoNotSellPrompt()
Displays the Opt-out popup. If you are not using the banner, integrate this function into your site banner to provide visitors a way to change their consent setting.
utag.gdpr.showDoNotSellPrompt(_lang)
Parameter | Type | Description |
---|---|---|
_lang |
String |
Optional. Language as an ISO format, such as en or en-gb |
The following example displays the Opt-out Model popup in the default language or language set up in data layer:
<a href="javascript: utag.gdpr.showDoNotSellPrompt()">Change Consent</a>
The following example displays the Opt-out Model popup in French:
<a href="javascript: utag.gdpr.showDoNotSellPrompt('fr-fr')">Change Consent</a>
utag.gdpr.showExplicitConsent()
Displays the explicit consent pop-up. This function injects the CSS, the HTML and the Javascript defined in the customizations in the page. It is natively called by Tealium Universal Tag utag.js
on DOM READY event when the explicit consent is set up.
utag.gdpr.showExplicitConsent(_lang)
Parameter | Type | Description |
---|---|---|
_lang |
String |
(Optional) Language in ISO format, such as en or en-gb |
The following example displays explicit consent in the default language or language set up in data layer:
utag.gdpr.showExplicitConsent()
The following example displays explicit consent in French:
utag.gdpr.showExplicitConsent("fr-fr")
utag.gdpr.updateConsentCookie()
Updates mobile consent from an app using hidden webview.
utag.gdpr.updateConsentCookie()
This page was last updated: March 9, 2023