Consent-gated analytics and the Site preferences Analytics switch.
Coastal Healthcare Advocates uses Cloudflare Web Analytics, a cookieless,
privacy-friendly analytics service. It loads only on the production host
(PROD_HOSTS), so local dev, deploy previews and branch deploys never
record traffic. Analytics are on by default and load on first visit;
a visitor can opt out at any time. A browser that sends the Global Privacy
Control signal starts with them off instead, as the Privacy Notice promises.
There is no first-visit consent prompt. The practice's visitors are in the US, so none is required; the banner was removed on 2026-09-18 and the opt-out lives in the Site preferences dialog instead.
How it fits together:
- The Site preferences dialog (
prefs.js, opened from the header and footer gear buttons) carries an Analytics switch, defaulted on, so a visitor can change their mind at any time. It reads and saves the choice throughwindow.chaConsent. - The visitor's choice is stored in
localStorageunderSTORE_KEY. No cookie is ever set by this script. Until a choice is saved, the default applies: on, or off under Global Privacy Control (gpc). - Other scripts may call
window.chaTrack(name, props). Cloudflare Web Analytics has no custom events, so it is always a harmless no-op, kept so callers don't need changing if a tool with events is added later.
Loaded as an ES module (<script type="module">), so it runs after the
document has been parsed.
- Source:
Namespaces
- chaConsent
Members
(inner, constant) CF_BEACON_TOKEN :string
Cloudflare Web Analytics site token (Cloudflare dashboard → Analytics & Logs → Web Analytics → the coastalhealthcareadvocates.org site → Manage site → JS snippet). It is public: it ships in the page like the snippet itself.
Type:
- string
- Source:
(inner, constant) PROD_HOSTS :Array.<string>
Hosts that count as production. Analytics load only here, so only real traffic is recorded.
Type:
- Array.<string>
- Source:
(inner, constant) STORE_KEY :string
localStorage key that holds the visitor's saved ConsentRecord.
Type:
- string
- Source:
(inner, constant) gpc :boolean
Whether the browser sends a Global Privacy Control signal. It only changes the default: a choice the visitor saves here still wins.
Type:
- boolean
- Source:
(inner, constant) isProd :boolean
Whether this page is being served from production.
Type:
- boolean
- Source:
Methods
(inner) choose(analytics) → {void}
Saves a consent choice and starts or stops analytics to match.
Parameters:
| Name | Type | Description |
|---|---|---|
analytics |
boolean |
|
- Source:
Returns:
- Type
- void
(inner) loadAnalytics() → {void}
Injects the Cloudflare Web Analytics beacon.
Does nothing off the production host (isProd), without a token, or
if the script tag (#cf-beacon) is already in the page. The beacon comes
from static.cloudflareinsights.com and reports to cloudflareinsights.com;
both are allowed in the Content-Security-Policy.
- Source:
Returns:
- Type
- void
(inner) readConsent() → {ConsentRecord|null}
Reads the visitor's saved consent choice.
Any failure — storage blocked (e.g. some private-browsing modes), the key missing, or the stored value not being valid JSON — is treated as "no choice made yet".
- Source:
Returns:
The saved record, or null if there isn't one.
- Type
- ConsentRecord | null
(inner) unloadAnalytics() → {void}
Turns analytics off for the rest of this page view, after the visitor withdraws consent.
Removes the beacon's script tag. (A script that has already executed can't be fully unloaded, but the next page load won't include the beacon at all.)
- Source:
Returns:
- Type
- void
(inner) writeConsent(analytics) → {ConsentRecord}
Saves the visitor's consent choice to localStorage.
If storage is unavailable the write is silently skipped; the choice still applies for the current page view because the record is returned.
Parameters:
| Name | Type | Description |
|---|---|---|
analytics |
boolean |
|
- Source:
Returns:
The record that was (or would have been) saved.
- Type
- ConsentRecord
Type Definitions
ConsentRecord
The shape of the consent choice saved in localStorage.
Type:
- Object
Properties:
| Name | Type | Description |
|---|---|---|
necessary |
true | Strictly-necessary storage — always allowed. |
analytics |
boolean | Whether the visitor accepted analytics. |
ts |
string | ISO-8601 timestamp of when the choice was made. |
v |
number | Schema version of this record (currently |
- Source: