# consent.onReady

{% hint style="info" %}
Method to obtain consent when it becomes available.The Commanders Act [OnSite API stub](/trustcommander/onsite-api/getting-started.md) has to be installed before using any of the OnSite API functions.
{% endhint %}

```javascript
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`'.&#x20;

## 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.

```javascript
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. 
           
    }
    
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://community.commandersact.com/trustcommander/onsite-api/consent.onready.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
