ampproject / ampproject/amphtml

amp-consent doesn't fire update for granular consent changes

Open
#36,058 1 comment 0 reactions 1 assignee Claimed by @alanorozco View on GitHub
Stale Type: Bug WG: components
Dominant language
JavaScript
Stars
14.9k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

### Description

The `amp-consent` component only updates user consent based on the top level accept/reject action, and not when a change is only made at a granular level.

On completion of a granular consent form, the `amp-consent` documentation suggests to use `consent.accept(purposeConsentDefault=false)` to save the values of the granular consents. This works fine, until the re-prompt UI is used to re-open the consent form.

If you then make a change to the granular consent choices no consent update is fired (when using the `onUpdateHref ` attribute) because the action on the form is still `consent.accept`. Having tested this, an update is fired if using `consent.reject` but I believe this is the wrong action in this situation.

### Reproduction Steps

Please visit https://www.gaborshoes.co.uk/granular-consent.html with Dev Tools open on the network tab.

Select `Manage Preferences` on the consent popup, and select the 'Preference & Functional Cookies' toggle and click `Accept`. In the Network tab you'll see a network request sent to `/amp/cookies/store` with the following payload

```
ampUserId: "xxxxxxxxxxxxxx"
consentInstanceId: "cookie-consent"
consentState: true
consentStateValue: "accepted"
purposeConsents: {purpose-preference: 1, purpose-statistics: 2, purpose-marketing: 2}
purpose-marketing: 2
purpose-preference: 1
purpose-statistics: 2
```

This is totally correct based on the actions I have taken - the consent is accepted as a whole and the `purpose-preference` consent is also accepted, whilst the other 2 consents are rejected.

However, if you then click on the 'Consent Settings' button to re-open the consent popup and change your granular consent to something different and submit the form, you'll notice that no update is sent in the Network tab.

The only way to fire an update at this point would be to open the consent popup and click on 'Reject All Cookies' since that changes the `consentStateValue`.

### Relevant Logs

_No response_

### Browser(s) Affected

_No response_

### OS(s) Affected

_No response_

### Device(s) Affected

_No response_

### AMP Version Affected

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.