> 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

Méthode pour s'abonner aux mises à jour du statut de consentement Commanders Act OnSite via JavaScript.

{% hint style="info" %}
Méthode permettant de s’abonner aux mises à jour du consentement Commanders Act OnSite via JavaScript. Le [stub de l’API OnSite Commanders Act](https://doc.commandersact.com/fr/fonctionnalites/consent-management/onsite-api/getting-started.md) doit être installé avant d’utiliser les fonctions de l’API OnSite.
{% endhint %}

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

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

L’argument `consentObject` est également enrichi d’une propriété supplémentaire, `updateEvent` qui indique comment la mise à jour a eu lieu. Cette propriété peut prendre les valeurs suivantes :

| Valeur    | Description                                                                                                                                               |
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `set`     | Le consentement a été défini.                                                                                                                             |
| `changed` | Le consentement avait déjà été établi, puis a été modifié.                                                                                                |
| `revoked` | Le consentement a été révoqué par l’utilisateur. Cette valeur est utilisée pour les tâches de nettoyage, comme la suppression des identifiants de cookie. |

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

## Exemples

### Exemple de réaction aux modifications du consentement pour 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 de consentement 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 cette catégorie. 
    
    } else {
        
        // Le consentement n’a pas été donné pour cette catégorie. 
           
    }
    
});
```

### Exemple de réaction aux modifications du consentement pour une catégorie spécifique uniquement 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 cette 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
