> 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 pour s'abonner aux mises à jour du consentement OnSite de Commanders Act via JavaScript. Le Commanders Act [stub OnSite API](/fr/fonctionnalites/consent-management/onsite-api/getting-started.md) doit être installé avant d’utiliser l’une des fonctions API OnSite.
{% endhint %}

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

Le `consent.onUpdate` la méthode permet de s'abonner à une fonction de rappel pour les mises à jour du 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` l'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                                                                                                                         |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| `définir` | 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é, cela déclenche deux événements : 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 de consentement 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 : ne réagir aux changements de consentement d'une catégorie spécifique qu'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é fourni 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 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.
