Ask at the moment of use, or show a preference centre
Ask for one purpose with PiedapConsent.ask() just before you need it, or put a preference centre on a page, both recorded from the browser.
Some forms have buttons of their own and record from the browser, with no form of yours around them. Ask at the moment of use shows a prompt right before a feature needs a purpose. A preference centre sits on a page and shows the answer saved last time.
Before you start#
- The loader tag on the page. See Install on a website.
- A published form of the kind Ask at the moment of use or Preference centre. See Kinds of consent form.
Ask at the moment of use#
-
Right before the feature runs, call
ask()with the form's key.JavaScript const answer = await PiedapConsent.ask('just-in-time-4mp1'); if (answer.granted) { readTheResume(); } -
Run the feature only when
answer.grantedistrue.
The prompt shows the form's title, its text and its buttons, Allow and Not now to start with. A person who answered before is not asked again, and answer.asked is then false. Pass { again: true } to ask anyway. Closing the prompt records nothing, and answer.dismissed is true.
Put a preference centre on a page#
-
Add an element with the form's key where the choices go, outside any
<form>.HTML <div data-piedap-form="preference-centre-8ux1"></div> -
Leave the rest to the runtime. It draws a switch for each purpose and a Save my choices button.
The page shows the answer this browser saved last time. Saving again updates the same record. The element fires piedap-consent:saved with the answer after each save.
Keep the answer under the account#
For signed-in people, give the loader their identity proof. See Signed-in visitors. The answer is then recorded under their account, and the preference centre shows it on every device they sign in on.