TrustCommander (deprecated)
Community home
English
English
  • Overview
  • Responsability of actors
  • Releases notes
  • Setup Guides
    • Tag Manager
      • TagCommander
      • Google Tag Manager (GTM)
      • Consent Mode
      • Consent Mode in GTM
      • Adobe Launch
    • Websites (Hardcoded)
    • Mobile apps
      • iOS
        • ATT - App Tracking Transparency (iOS 14.5+)
      • Android
  • User Guides
    • Categories & Tags
      • Manage Categories
      • Manage Vendors
      • Assign Categories
    • Privacy Banners
      • Banner Templates
        • Accessibility Template
      • Manage Banner
      • Deploy Banner
      • Copy Banner
    • Dashboard
    • Exports
    • Options
  • Extensions
    • Cookie Scanner
    • TagFirewall
    • Tag Hierarchy
  • Marketing Preferences Center
    • Marketing Preferences Center (Trust Premium only)
  • Knowledge Base
    • Consent Object
    • TrustCommander cookies exemption
    • Consent Cookie
    • IAB TCF V2.0 Consent
    • IAB TCF V2.0 and Google FAQ
  • Rest data API
    • GET/PUT Consents / preferences
  • Onsite API
    • Getting Started
    • consent.get
    • consent.update
    • consent.revoke
    • consent.onUpdate
    • consent.onReady
    • consentBanner.show
    • consentBanner.hide
    • consentCenter.show
    • consentCenter.hide
  • PLATFORM API
    • Get statistics
Powered by GitBook
On this page
  • Examples
  • Example to react to consent changes of a specific category
  • Example only react to consent changes of a specific category after the initial consent was given
  1. Onsite API

consent.onUpdate

Method to subscribe to TrustCommander consent updates OnSite via JavaScript.

Previousconsent.revokeNextconsent.onReady

Last updated 3 years ago

The Commanders Act has to be installed before using any of the OnSite API functions.

cact('consent.onUpdate', function (result) { ... })

The consent.onUpdate method allow to subscribe a callback function for consent updates. The callback function will be called with the updated Consent Object. It is called whenever the consent is changed via a TrustCommander banner interaction or the consent.update method of the OnSite API.

The consentObject argument will also be enriched with an additional property updateEvent to signal how the update happened. It can have following values:

Value

Description

set

The consent was set.

changed

Consent was already established and then changed.

revoked

Consent was revoked by the user. Used for cleanup tasks like deleting cookie identifiers.

When consent is revoked it fires two events: One changed followed by one revoked.

Examples

Example to react to consent changes of a specific category

In this example the Analytics category was configured with the consent category id 2 in TrustCommander.

cact('consent.onUpdate', function (result) { 
    
    const ANALYTICS_ID = 2;
    const analyticsCategory = result.consent.categories[ANALYTICS_ID] || {};
     
    if (analyticsCategory.status === 'on') {
    
        // Consent was provided for the category. 
    
    } else {
        
        // Consent was not provided for the category. 
           
    }
    
});

Example only react to consent changes of a specific category after the initial consent was given

In this example the Analytics category was configured with the consent category id 2 in TrustCommander.

cact('consent.onUpdate', function (result) { 

    const ANALYTICS_ID = 2;
    const analyticsCategory = result.consent.categories[ANALYTICS_ID] || {};

    if (result.updateEvent === "changed" && analyticsCategory.status === 'on') {
    
        // Consent was provided for the category during an update.
    
    } 
    
});
OnSite API stub