• Platforms
  • Partners
  • Forums
  • TLC Tealium Learning Center Tealium Learning
    Community
  • Discussions & Ideas Dicussions & Ideas
  • Product Guides Product Guides
  • Knowledge Base Knowledge Base
  • Developer Docs Developer Docs
  • Education Education
  • TLC Blog TLC Blog
  • Support Desk Support Desk
  • CDH Customer Data Hub Customer Data Hub

Table of Contents

  • utag.gdpr.getCategories()
  • utag.gdpr.getCategoryLanguage()
  • utag.gdpr.getConsentState()
  • utag.gdpr.getCookieValues()
  • utag.gdpr.getLanguage()
  • utag.gdpr.getSelectedCategories()
  • utag.gdpr.setAllCategories()
  • utag.gdpr.setConsentValue()
  • utag.gdpr.setCookie()
  • utag.gdpr.setCookieValue()
  • utag.gdpr.setPreferencesFromList()
  • utag.gdpr.setPreferencesValues()
  • utag.gdpr.showConsentPreferences()
  • utag.gdpr.showExplicitConsent()
JAVASCRIPT

GDPR Functions

Reference guide for GDPR functions provided by Tealium for JavaScript.

The following utag.gdpr functions are available:

Function Description
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
showExplicitConsent() Displays the explicit consent pop-up
updateConsentCookie() Updates mobile consent from an app using hidden webview

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.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:
```js utag.gdpr.showExplicitConsent(“fr-fr”)

Cookie Functions
Tracking Functions

 
  • Mobile
  • Getting Started
    • Overview
    • Quick Start Guide
    • Mobile Concepts
    • Client-Side
    • Server-Side
    • Tracking Webviews
    • Data Layer
    • Consent Management
    • Event Batching
    • User Location and Geofencing
    • Deep Links
    • Timed Events
    • Trace
    • Hosted Data Layer
    • Feature Comparison
    • Troubleshooting
  • Remote Commands
    • Overview
    • How It Works
    • Integrations
      • AppsFlyer
      • Braze
      • Contentsquare
      • Facebook
      • Firebase
      • Kochava
      • Usabilla
  • Android (Java)
    • Overview
    • Install
    • Track
    • Data Layer
    • Data Management
    • Consent Management
    • Module List
      • Ad Identifier Module
      • Crash Reporter Module
      • Install Referrer Module
      • Lifecycle Tracking Module
      • Location Module
      • Optimizely X Tracking Module
    • Android TV
    • Android Wear
    • API Reference
      • ConsentManager
      • DataSources
      • Lifecycle
      • Tealium
      • Tealium.Config
      • TealiumLocation
    • Release Notes
  • Android (Kotlin)
    • Overview
    • Install
    • Track
    • Data Layer
    • Consent Management
    • Identity Resolution
    • Module List
      • Collect Module
      • Collectors Module
      • Crash Reporter Module
      • Install Referrer Module
      • Lifecycle Tracking Module
      • Location Manager Module
      • Tag Management Dispatcher Module
      • Visitor Service Module
    • Android TV
    • API Reference
      • ConsentCategory
      • ConsentManager
      • CurrentVisit
      • DataLayer
      • Lifecycle
      • LocationManager
      • Tealium
      • TealiumConfig
      • VisitorProfile
      • VisitorService
    • Release Notes
  • Cordova
    • Overview
    • Install
    • Track
    • Data Management
    • Module List
      • Ad Identifier Module
      • Crash Reporter Module
      • Install Referrer Module
    • API Reference
    • Release Notes
  • Flutter
    • Overview
    • Install
    • Track
    • Consent Management
    • Data Management
    • API Reference
    • Release Notes
  • iOS (Objective-C)
    • Overview
    • Install
    • Track
    • Data Layer
    • Data Management
    • Consent Management
    • Tag Management
    • Module List
      • Lifecycle Tracking Module
      • Optimizely X Tracking Module
    • tvOS
    • watchOS
    • API Reference
    • Release Notes
  • iOS (Swift) 1.x
    • Overview
    • Install
    • Track
    • Data Layer
    • Data Management
    • App Extensions
    • Identity Resolution
    • Consent Management
    • Modules
    • Module List
      • AppData Module
      • Attribution Module
      • AutoTracking Module
      • Collect Module
      • Connectivity Module
      • CrashReporter Module
      • DataSource Module
      • DefaultStorage Module
      • Delegate Module
      • DeviceData Module
      • DispatchQueue Module
      • FileStorage Module
      • Lifecycle Module
      • Location Module
      • Logger Module
      • PersistentData Module
      • RemoteCommands Module
      • TagManagement Module
      • VisitorService Module
      • VolatileData Module
    • Feature Comparison
    • Working with Objective-C
    • API Reference
      • TealiumConfig
      • TealiumConsentCategories
      • TealiumConsentManagerDelegate
      • TealiumConsentManager
      • TealiumInstanceManager
      • TealiumPersistentData
      • TealiumVolatileData
      • Tealium
    • Release Notes
  • iOS (Swift) 2.x
    • Overview
    • Install
    • Track
    • Data Layer
    • Consent Management
    • App Extensions
    • Identity Resolution
    • Modules
    • Module List
      • AppData Module
      • Attribution Module
      • AutoTracking Module
      • Collect Module
      • Connectivity Module
      • CrashReporter Module
      • DeviceData Module
      • Lifecycle Module
      • Location Module
      • RemoteCommands Module
      • TagManagement Module
      • VisitorService Module
    • Working with Objective-C
    • API Reference
      • Tealium
      • TealiumConfig
      • TealiumConsentCategories
      • TealiumConsentManager
      • TealiumDataLayer
      • TealiumInstanceManager
    • Release Notes
  • React Native
    • Overview
    • Install
    • Track
    • API Reference
    • Release Notes
  • Unity
    • Overview
    • Install
    • Track
    • API Referencee
  • Xamarin
    • Overview
    • Install
    • Track
    • Data Management
    • Consent Management
    • API Reference
    • Release Notes
  • Web
  • AMP
    • Overview
    • Install
    • Track
    • Data Layer
  • Angular
    • Overview
    • Install
    • Track
    • API Reference
  • Google Tag Manager
    • Overview
    • Install
    • Data Layer
  • JavaScript (Web)
    • Overview
    • Install
    • Track
    • Data Layer
    • Universal Data Object (utag_data)
    • Universal Tag (utag.js)
    • Data Layer Object (b)
    • Single-Page Applications
    • Settings
    • Debugging
    • API Reference
      • Cookie Functions
      • GDPR Functions
      • Tracking Functions
      • Utility Functions
    • Release Notes
  • Server
  • C#
    • Overview
    • Install
    • Track
    • Data Layer
    • API Reference
    • Release Notes
  • HTTP API
    • Overview
    • Endpoint
    • Data Layer
  • Java
    • Overview
    • Install
    • Track
    • API Reference
    • Release Notes
  • Node
    • Overview
    • Install
    • Track
    • API Reference
  • Python
    • Overview
    • Install
    • Track
    • API Reference
  • Roku
    • Overview
    • Install
    • Track
    • API Reference
  • Ruby
    • Overview
    • Install
    • Track
    • API Reference

Was this article helpful?

This page was last updated: July 16, 2020       Thank you for your feedback!
  • Platforms
  • Partners
  • Forums
  • Mobile
  • Getting Started
  • Remote Commands
  • Android (Java)
  • Android (Kotlin)
  • Cordova
  • Flutter
  • iOS (Objective-C)
  • iOS (Swift) 1.x
  • iOS (Swift) 2.x
  • React Native
  • Unity
  • Xamarin
  • Web
  • AMP
  • Angular
  • Google Tag Manager
  • JavaScript (Web)
  • Server
  • C#
  • HTTP API
  • Java
  • Node
  • Python
  • Roku
  • Ruby