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
  • Example
  • Example to wait for consent availability and do something on a specific category
  1. Onsite API

consent.onReady

Method to obtain consent when it becomes available.

Previousconsent.onUpdateNextconsentBanner.show

Last updated 2 years ago

Method to obtain consent when it becomes available.The Commanders Act has to be installed before using any of the OnSite API functions.

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

The consent.onReady method allow to subscribe a callback function for when consent is set. The callback function will be called only once, with the updated Consent Object. It is called whenever the consent is set via a consent banner interaction or when a consent cookie is already set.

Like in the command consent.onUpdate, the consentObject argument will be enriched with the property updateEvent, but only with the value 'set'.

Example

Example to wait for consent availability and do something on a specific category

In this example, the code is waiting for the user's interaction with the consent banner. The Analytics category was configured with the consent category id 2 on privacy banner.

cact('consent.onReady', 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. 
           
    }
    
});
OnSite API stub