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 categories selected 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 (true
or false
).
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 shows the results when utag.gdpr.getCategories()
returns all categories:
["analytics", "affiliates", "display_ads", "search", "email", "personalization", "social", "big_data", "misc", "cookiematch", "cdp", "mobile", "engagement", "monitoring", "crm"]
The following example shows the results when utag.gdpr.getCategories()
returns the enabled categories:
["analytics", "affiliates", "personalization"]
utag.gdpr.getCategoryLanguage()
Returns an Object
with the category name and description in the active language. The language of the category is the language returned by the getLanguage()
function.
For more information on categories, see Manage consent preferences.
utag.gdpr.getCategoryLanguage(category)
Parameter | Type | Description |
---|---|---|
category |
String |
Name of category. |
The following example shows the Object
returned by utag.gdpr.getCategoryLanguage("analytics")
when the language is English:
{name: "Cookies that help us improve our website", notes: "These cookies help us understand how people use our website."}
The following example shows the Object
returned by utag.gdpr.getCategoryLanguage("analytics")
when the language is Polish:
{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 one of two data types, as follows:
- A numeric value indicating the consent state (full, declined, or no consent).
- For partial consent, an
Array
ofObjects
specifying consent by category.
When full, declined, or no consent is given, one of the following consent state values is returned:
Consent State | Consent Value | Description |
---|---|---|
Full | 1 |
Full consent was given (consent:true on the cookie). |
Decline | -1 |
Consent was declined (consent:false on the cookie). |
None Given | 0 |
No consent is given (no cookie present). |
When partial consent is given, an Array
of Objects
is returned. Each Object
represents a consent category. For each Object
in the Array
, the "ct"
key represents the consent value (1
/0
), and the "name"
key specifies the consent category.
utag.gdpr.getConsentState()
The following example shows an Array
of Objects
returned for partial consent:
[{"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()
Instead of using this function directly, it is recommended that you use a function such as utag.gdpr.getConsentState()
, which calls the getCookieValues()
function to read the cookie.
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()
.
utag.gdpr.getCookieValues()
The following example shows the Array
returned by utag.gdpr.getCookieValues()
for partial consent:
{
"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 shows the Array
returned by utag.gdpr.getCookieValues()
for full consent:
utag.gdpr.getCategories(true)
{"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()
The following example shows the String
returned when the language is English (United Kingdom):
"en-gb"
utag.gdpr.getSelectedCategories()
Returns an Array
that contains the categories selected by the customer.
utag.gdpr.getSelectedCategories()
The following example shows an Array
returned by utag.gdpr.getSelectedCategories()
:
["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 call the Collect API to track the consent. |
The following example specifies 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
.
utag.gdpr.setConsentValue()
doesn’t change the consent value of individual categories. The consent value 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 the cookie to the value "consent:true"
and updates the timestamp:
utag.gdpr.setConsentValue(true)
The following example sets the cookie to the value "consent:false"
and updates the timestamp:
utag.gdpr.setConsentValue(0)
utag.gdpr.setCookie()
We do not recommend calling this function directly.
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.
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)
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 in the cookie key. |
The following example sets the 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 that are not in the list is 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. |
The following example sets the consent state for the "analytics"
category in the consent cookie:
utag.gdpr.setPreferencesFromList(["analytics"])
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 call the Collect API to track the consent. |
The following example sets the cookie value for the "analytics"
, "affiliates"
, and "personalization"
categories:
Var cats = {"analytics":"1","affiliates":"0","personalization":"0"}
utag.gdpr.setPreferencesValues(cats)
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 specified in ISO format, such as en or en-gb . |
The following example displays consent in the default language or the language set up in the data layer:
utag.gdpr.showConsentPreferences()
The following example displays consent in French:
utag.gdpr.showConsentPreferences("fr-fr")
utag.gdpr.showDoNotSellBanner()
Displays the CCPA 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 specified in ISO format, such as en or en-gb . |
The following example displays the CCPA banner in the default language or the language set up in the 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 specified in ISO format, such as en or en-gb . |
The following example displays the CCPA popup in the default language or the language set up in the 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 the 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 specified in ISO format, such as en or en-gb . |
The following example displays explicit consent in the default language or the language set up in the 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: May 26, 2023