Consent Docs

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.

How-to1 min readFor web, backend and mobile developers

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#

Ask at the moment of use#

  1. 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();
    }
  2. Run the feature only when answer.granted is true.

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#

  1. Add an element with the form's key where the choices go, outside any <form>.

    HTML
    <div data-piedap-form="preference-centre-8ux1"></div>
  2. 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.

↑↓ to move, Enter to open