Skip to content

Commit

Permalink
Updated documentation for custom cookies
Browse files Browse the repository at this point in the history
Co-authored-by: alexvoss <4134224+alexvoss@users.noreply.github.com>
  • Loading branch information
squidfunk and alexvoss committed Jul 24, 2023
1 parent ea9446e commit b72adf3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions docs/setup/ensuring-data-privacy.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,15 +547,25 @@ const url ="https://polyfill.io/v3/polyfill.min.js"
### Custom cookies

If you've customized the [cookie consent] and added a `custom` cookie, the user
will be prompted to accept your custom cookie. Use [additional JavaScript] to
check whether the user accepted it:
will be prompted to accept or reject your custom cookie. Once the user accepts
or rejects the cookie consent, or [changes the settings], the page reloads[^1].
Use [additional JavaScript] to query the result:

[^1]:
We reload the page to make interop with custom cookies simpler. If Material
for MkDocs would implement a callback-based approach, the author would need
to make sure to correctly update all scripts that use cookies. Additionally,
the cookie consent is only answered initially, which is why we consider this
to be a good trade-off of DX and UX.

=== ":octicons-file-code-16: `docs/javascripts/consent.js`"

``` js
var consent = __md_get("__consent")
if (consent && consent.custom) {
/* The user accepted the cookie */
} else {
/* The user rejected the cookie */
}
```

Expand All @@ -567,3 +577,4 @@ check whether the user accepted it:
```

[additional JavaScript]: ../customization.md#additional-javascript
[changes the settings]: #change-cookie-settings

0 comments on commit b72adf3

Please sign in to comment.