> For the complete documentation index, see [llms.txt](https://doc.commandersact.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.commandersact.com/fr/fonctionnalites/consent-management/onsite-api/consent.onupdate.md).

# consent.onUpdate

{% hint style="info" %}
Méthode pour s’abonner aux mises à jour de consentement OnSite de Commanders Act via JavaScript.The Commanders Act [stub de l'API OnSite](/fr/fonctionnalites/consent-management/onsite-api/getting-started.md) doit être installé avant d'utiliser l'une des fonctions de l'API OnSite.
{% endhint %}

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

Le `consent.onUpdate` La méthode permet d'abonner une fonction de rappel aux mises à jour de consentement. La fonction de rappel sera appelée avec le Consent Object mis à jour. Elle est appelée chaque fois que le consentement est modifié via une interaction avec une bannière Commanders Act ou la `consent.update` méthode de l'API OnSite.

Le `consentObject` argument sera également enrichi d'une propriété supplémentaire `updateEvent` pour indiquer comment la mise à jour s'est produite. Il peut prendre les valeurs suivantes :

| Valeur    | Description                                                                                                                         |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| `set`     | Le consentement a été défini.                                                                                                       |
| `changed` | Le consentement était déjà établi, puis modifié.                                                                                    |
| `revoked` | Le consentement a été révoqué par l'utilisateur. Utilisé pour des tâches de nettoyage comme la suppression des identifiants cookie. |

{% hint style="info" %}
Lorsque le consentement est révoqué, deux événements sont déclenchés : un changed suivi d'un revoked.
{% endhint %}

## Exemples

### Exemple pour réagir aux changements de consentement d'une catégorie spécifique

Dans cet exemple, la catégorie Analytics a été configurée avec l'ID de catégorie de consentement 2 dans les paramètres Consent de Commanders Act.

```javascript
cact('consent.onUpdate', function (result) { 
    
    var ANALYTICS_ID = 2;
    var analyticsCategory = result.consent.categories[ANALYTICS_ID] || {};
     
    if (analyticsCategory.status === 'on') {
    
        // Le consentement a été donné pour la catégorie. 
    
    } else {
        
        // Le consentement n'a pas été donné pour la catégorie. 
           
    }
    
});
```

### Exemple pour réagir uniquement aux changements de consentement d'une catégorie spécifique après que le consentement initial a été donné

Dans cet exemple, la catégorie Analytics a été configurée avec l'ID de catégorie de consentement 2 dans TrustCommander.

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

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

    if (result.updateEvent === "changed" && analyticsCategory.status === 'on') {
    
        // Le consentement a été donné pour la catégorie lors d'une mise à jour.
    
    } 
    
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://doc.commandersact.com/fr/fonctionnalites/consent-management/onsite-api/consent.onupdate.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
