Add web analytics or a support chat widget to a docs site with one line per
provider, and ask readers for consent before anything loads.
aiui build adds them to every page (the home page, each docs page and
aiui build
404.html). Each client-side page change counts as a page view.
404.html
A provider takes its main id as a plain value (ga4: G-ABC1234) or a block
ga4: G-ABC1234
with more settings. The build checks every id and URL and stops on a bad one.
| Key | Settings (first one is the main id) | Page views on navigation |
|-----|-------------------------------------|--------------------------|
| ga4 | measurementId (G-...) | Counted by GA4's enhanced measurement (page changes based on browser history, on by default) |
ga4
measurementId
G-...
| gtm | tagId (GTM-...) | Pushes {event: "aiui.pageview", page_path, page_title} to the data layer |
gtm
tagId
GTM-...
{event: "aiui.pageview", page_path, page_title}
| posthog | apiKey (phc_...), apiHost (default https://us.i.posthog.com), sessionRecording (default false) | Counted by PostHog (history_change) |
posthog
apiKey
phc_...
apiHost
https://us.i.posthog.com
sessionRecording
false
history_change
| plausible | domain, server (default https://plausible.io, or your own instance) | Counted by Plausible |
plausible
domain
server
https://plausible.io
| fathom | siteId | Counted by Fathom (data-spa="auto") |
fathom
siteId
data-spa="auto"
| umami | websiteId (a UUID), src (default https://cloud.umami.is/script.js) | Counted by Umami |
umami
websiteId
src
https://cloud.umami.is/script.js
| segment | key (the write key) | analytics.page() |
segment
key
analytics.page()
| mixpanel | projectToken, region (us, eu or in) | Counted by Mixpanel (track_pageview: "url-with-path") |
mixpanel
projectToken
region
us
eu
in
track_pageview: "url-with-path"
| scripts | A list of https:// script URLs for any other tool | Up to the tool |
scripts
https://
Support chat widgets load when the browser is idle, so they never slow the first paint:
| Key | Settings |
|-----|----------|
| intercom | appId (calls Intercom('update') on each page change) |
intercom
appId
Intercom('update')
| crisp | websiteId (a UUID) |
crisp
| front | chatId |
front
chatId
With consent, nothing loads until the reader accepts. A small banner at the
consent
bottom of the page offers Decline and Accept, the same size and style,
so declining is as easy as accepting. The choice is remembered in the
browser's local storage (aiui-consent: granted or denied). The banner
aiui-consent
granted
denied
uses the site's theme colours in light and dark mode and fits a phone screen.
| Key | Default | Meaning |
|-----|---------|---------|
| required | true | consent: true is short for this; false loads without asking. |
required
true
consent: true
| banner | true | false: no built-in banner; your own consent tool decides (below). |
banner
| text, accept, decline | an English sentence, Accept, Decline | The banner's words. |
text
accept
decline
Accept
Decline
| policy, policyLabel | none, Privacy policy | A link to your privacy page (a site path or URL). |
policy
policyLabel
Privacy policy
Change of mind. Any link to #cookie-settings opens the banner again, for
#cookie-settings
example in the footer: Cookie settings. Declining after
Cookie settings
accepting reloads the page, so the trackers that were running stop.
Your own consent tool. Set banner: false and tell the page the reader's
banner: false
choice from the tool's callback:
Readers whose browser sends Global Privacy Control or Do Not Track get no
analytics (support chat still loads); respectDoNotTrack: false counts them
respectDoNotTrack: false
anyway. aiui dev leaves integrations out so previews are not visits;
aiui dev
dev: true under integrations loads them there too.
dev: true
integrations
No inline script is emitted: the settings are a JSON data block and the loader
is a file at the site root (/aiui-integrations.js). The build's
/aiui-integrations.js
Content Security Policy adds each provider's
hosts per directive by itself (Compiler(config).external_origins() lists
Compiler(config).external_origins()
them). A tag manager container (gtm) loads whatever tags you add to it, so
with gtm the policy is report-only until you add their hosts under
site.csp and set it to enforce.
site.csp