ampproject / ampproject/amphtml

Allow for all granular consents to be accepted/rejected in one click

Open
#36,060 1 comment 0 reactions 0 assignees View on GitHub
Stale Type: Feature Request
Dominant language
JavaScript
Stars
14.9k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

### Description

We are attempting to develop a granular consent UI using the `amp-consent` component that allows all types of cookies to be accepted or rejected with 1 click, but it doesn't seem possible for this to work if a user was to change their mind using the re-prompt functionality.

Here is an example of the UI we are working on:

![Screenshot 2021-09-14 at 09 49 29](https://user-images.githubusercontent.com/5079679/133226669-01b579c7-9c35-48fb-91e0-e30ef0fd300d.png)

![Screenshot 2021-09-14 at 09 49 54](https://user-images.githubusercontent.com/5079679/133226736-8e4e426b-cf75-4d23-b825-714cf5fb63cf.png)

### Alternatives Considered

Our existing implementation can be seen at https://www.gaborshoes.co.uk/granular-consent.html but it has issues. We are currently using the `consent.accept(purposeConsentDefault=true)` and `consent.reject(purposeConsentDefault=false)` actions to save the consent preferences with the 'Accept All Cookies' and 'Reject All Cookies' buttons respectively. These both work ok the first time a user makes a selection, but if the user then changes their mind then there seems to be no way to change the values of the granular consents.

For example, if you visit the link provide and click the 'Reject All Cookies' button, this will send a request to `/amp/cookies/store` with a payload of the following:

```
ampUserId: "xxxxxxxxxxxxxxx"
consentInstanceId: "cookie-consent"
consentState: false
consentStateValue: "rejected"
purposeConsents:
purpose-marketing: 2
purpose-preference: 2
purpose-statistics: 2
```

This is fine, the consent StateValue is rejected and all the granular consents are rejected too. However, if you then click on the Consent Settings button and choose 'Accept All Cookies' the payload that is sent is as follows:

```
ampUserId: "xxxxxxxxxxxxxxx"
consentInstanceId: "cookie-consent"
consentState: true
consentStateValue: "accepted"
purposeConsents:
purpose-marketing: 2
purpose-preference: 2
purpose-statistics: 2
```

You can see that the `consentStateValue` has been set to `true` which is correct, but the `purposeConsents` values are all still set to rejected. Therefore, it would be useful to have a way to change all granular consents in 1 click as well as the top level accept/reject action.

We have tried to use the `consent.setPurpose` action in the tap event for the buttons to try to force set the granular consents, but it didn't take any effect.

### Additional Context

https://www.gaborshoes.co.uk/granular-consent.html

Contributor guide

Open the contributing guide

Research direction

Reproduce the reject-then-accept flow using the linked granular-consent example and the amp-consent actions described in the issue. Start by tracing how consent.accept, consent.reject, and consent.setPurpose update purposeConsents; done means one-click top-level actions also update every granular consent consistently after a re-prompt.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.