Consent and opt-out
The snippet sets no cookies, keeps nothing that identifies a reader in the browser, and never stores IP addresses. Many sites therefore don’t ask for consent before loading it. If yours does, or if your legal team wants readers to have a clear way out, the snippet supports three things, which work together:
| What it is | What you do | |
|---|---|---|
| Global Privacy Control | A browser setting where the reader asks every site not to share their data | Nothing: it’s always honored |
| Opt-out | A link on your site that stops the measurement in that browser | Call wca.optOut() (and wca.optIn() to undo) |
| Consent | Your consent tool (a cookie banner or a consent platform) decides when measurement starts | Add data-consent="required" and call wca.consent() |
Global Privacy Control
When the reader’s browser has Global Privacy Control on (some browsers have it on by default; others through a setting or an extension), nothing is measured for that reader: no pageviews, no events, no searches, no page speed, no errors, and no recording. The browser setting wins over any consent given on the page. WriteChoice also discards, on its side, anything such a browser sends.
So if you test your site with Global Privacy Control on, your visits don’t appear in the portal. That’s intended.
Let readers opt out
Add a link or a button, for example on your privacy policy page, that calls wca.optOut():
<button type="button" onclick="(window.wcaQueue = window.wcaQueue || []).push(['optOut'])">Don't measure my visits</button>- It applies right away and to every later visit in that browser. The choice is kept in the browser’s storage under
wca.disabled: it’s the only thing the snippet ever stores. wca.optIn()undoes it, and the page being read counts again:(window.wcaQueue = window.wcaQueue || []).push(['optIn']).- Clearing the site data in the browser also clears the opt-out.
Wait for your consent tool
Add data-consent to the snippet
Add data-consent="required" to the script tag (each platform below shows where):
<script defer src="https://analytics.writechoice.io/s/YOUR_SITE_KEY.js" data-consent="required"></script>The script now loads and waits. Nothing is measured, and nothing is kept to be sent later, until your consent tool says yes.
Tell the script what the reader chose
When the consent tool knows the reader’s answer, on every page load (consent tools keep the answer and give it back on each page) and whenever the reader changes their mind:
(window.wcaQueue = window.wcaQueue || []).push(['consent', { analytics: true, recording: true }])Use false for a category the reader declined.
Check it
Open your site in a private window: no /e request goes to analytics.writechoice.io until you accept in the banner. Then one /e request (the pageview of the page you’re on).
The two categories
| Category | What it allows |
|---|---|
analytics | Pageviews, custom events, searches, page speed, JavaScript errors and wca.identify |
recording | Session replay and heatmaps (clicks and scrolling). It needs analytics too, and it only records what’s turned on for your site, on its sample of page loads |
- Map them to your tool’s categories. Most tools call the first one “statistics”, “analytics” or “performance”; recording often belongs to the same category, or to a stricter one.
- When
analyticsturns on, the page being read is counted, once. What the reader did before accepting isn’t. - When a category turns off, it stops right away, on that page.
- A category you leave out keeps its current state:
wca.consent({ recording: false })doesn’t changeanalytics. - A value other than
trueorfalseis ignored, with a warning in the browser console. - The choice lives in the page’s memory only. That’s why the consent tool tells the script on every page load. On a site that changes pages without reloading (a single-page site), the choice carries over.
Why the queue
The snippet loads with defer, so your consent tool may answer before wca exists. window.wcaQueue works in both cases:
- Before the script loads, the commands wait in the queue, and the script runs them in order when it loads, before counting the page.
- After it loads, the same
pushruns the command right away.
Once the script has loaded you can also call wca.consent({ ... }), wca.optOut() and wca.optIn() directly. The queue also takes the other calls, such as ['setTag', 'v2'] or ['track', 'signup', { plan: 'pro' }].
Example: a consent tool with a JavaScript API
Most consent tools let you read the reader’s answer and listen for changes. The shape is always the same; replace the two functions with your tool’s own:
<script>
function sendConsent() {
(window.wcaQueue = window.wcaQueue || []).push(['consent', {
analytics: myConsentTool.allows('statistics'),
recording: myConsentTool.allows('statistics'),
}]);
}
myConsentTool.onReady(sendConsent); // the answer kept from earlier visits
myConsentTool.onChange(sendConsent); // the reader changed their mind
</script>
<script defer src="https://analytics.writechoice.io/s/YOUR_SITE_KEY.js" data-consent="required"></script>On each platform
Add the attribute to the line in the <head>, as in step 1 above.
Docusaurus passes extra keys of a scripts entry to the tag as attributes:
scripts: [
{ src: 'https://analytics.writechoice.io/s/YOUR_SITE_KEY.js', defer: true, 'data-consent': 'required' },
],In your analytics.js file, add s.setAttribute('data-consent', 'required'); after the s.src line.
WriteDocs has its own consent banner (integrations.consent in writedocs.json). Add "consent": true to the script entry: WriteDocs loads the script only after the reader accepts, so nothing else is needed. Its banner has a single accept or decline for everything.
{ "src": "https://analytics.writechoice.io/s/YOUR_SITE_KEY.js", "consent": true }Sites with page transitions (Astro and similar)
Frameworks that swap pages without a full reload, such as Astro’s <ClientRouter />, keep the script running across pages: it starts once, counts one pageview per navigation, and keeps the reader’s choice. Put the snippet in the <head> of every page, the same line on each one.
When a change applies
Browsers keep the script for up to a day. A reader who visited your site before you added data-consent can be counted, without waiting for consent, on their first page load after the change; from the next one, the script waits. Global Privacy Control and the opt-out apply right away.
See also: Privacy and the privacy policy template.