Visitor-facing view of what analytics is doing on this page: whether it runs, why it is off, and which fields an event carries, with Pause and Resume.
Overview
The <analytics-panel> component shows visitors what Vanilla Breeze analytics is doing on the current page: whether it is running, why it is off, which fields an event carries, and how many events this page has sent. Visitors can pause collection for the tab and resume it.
Everything the panel shows comes from the live runtime through Analytics.getStatus(). Nothing is hardcoded, so the panel cannot drift from what the runtime actually sends.
Basic Usage
Place the element anywhere: dashboard, privacy page, settings section. It renders on upgrade and updates itself when the runtime starts, sends an event, or the consent state changes.
1
<analytics-panel></analytics-panel>
Compact Mode
Add compact for a tighter layout when embedding alongside other UI: smaller text, heading and buttons, and less spacing.
<analytics-panel heading="Your analytics data" compact></analytics-panel>
Heading Text and Level
Override the default Analytics on this page
heading text with heading. The panel heading is an h2 by default, which suits a panel placed directly under the page’s h1. Inside a section that already has an h2, set heading-level="3" so the outline stays in order; the panel’s field-list subheading is always one level below (at most h6). Values outside 1–6 fall back to 2.
The attribute is heading, not title: the global title attribute would also show a tooltip over the whole panel.
<section> <h2>Data we collect</h2> <analytics-panel heading="What we send from this page" heading-level="3"></analytics-panel></section>
What the Panel Reports
The status line, and the reflected data-state and data-reason attributes, follow the same gate that drops events in the runtime:
data-state | data-reason | Meaning |
active | (none) | Events are sent to the configured endpoint. |
debug | (none) | The console transport is on: events are logged in the browser, not sent. |
paused | user | The visitor paused analytics for this tab. |
off | gpc | The browser sends Global Privacy Control. |
off | dnt | The browser sends Do Not Track. |
off | consent | The site’s consent callback returned false. |
off | disabled | The site configured transport: 'disabled'. |
off | iframe | The page is in an iframe and the runtime does not run there. |
off | uninitialized | Analytics.init() has not run on this page. |
Below the status, a description list shows the envelope fields an event from this page carries (name, ts, site, path, referrer, context, props), the path and referrer as they would be sent after URL masking, the keys in context (the <html> data-* attributes and vb:* meta tags on the page), the endpoint, and the number of events sent from this page load.
Pause and Resume
The toggle calls Analytics.setConsent(false) or Analytics.setConsent(true), which sets or removes the vb_optout flag in sessionStorage. The runtime checks that flag before every event. The panel and the API stay in sync: calling setConsent() directly updates any open panel.
import { Analytics } from 'vanilla-breeze'; Analytics.setConsent(false); Analytics.setConsent(true);
Resume cannot override Global Privacy Control, Do Not Track, or the site’s consent callback. When one of those keeps analytics off, the Resume button is marked unavailable (aria-disabled="true") and a note linked by aria-describedby explains why.
Reading Status Yourself
Analytics.getStatus() is a read-only snapshot; it never changes state or sends anything. The runtime fires vb:analytics-status on document when the status changes.
import { Analytics } from 'vanilla-breeze'; const s = Analytics.getStatus();
Counts cover the current page load. Outbound link ping requests are sent by the browser and are not counted.
Events
| Event | When |
analytics-panel:optout | When the user pauses analytics for this tab |
analytics-panel:optin | When the user resumes analytics for this tab |
123
document.addEventListener('analytics-panel:optout', () => { console.info('User paused analytics for this session');});
Privacy and Storage
- On this device: only the pause flag (
vb_optout in sessionStorage), which the browser clears when the tab closes. The runtime keeps no event history on the device, so there is no clear my data
action: there is nothing local to clear.
- On the server: each sent event is stored as a row with the event name, site, path, referrer, the page’s taxonomy fields, event properties and a timestamp. The server adds the visitor’s country from the request.
- No identifier: no cookies and no visitor ID. The IP address is not stored; unique visits are counted with a daily-rotating salted hash that is pruned after a day or two. Because sent events carry no identifier, they cannot be looked up or deleted from the panel.
Accessibility
- The panel renders once and then updates text in place, so the activated button keeps focus.
- One persistent
role="status" region announces each change of state; a Refresh that changes nothing stays quiet.
- The toggle exposes its state with
aria-pressed, and uses aria-disabled rather than disabled when Resume is unavailable, so it stays focusable and its explanation stays reachable.
- Colours come from VB tokens (
--color-surface-raised, --color-text, --color-text-muted), which keep 4.5:1 contrast in light and dark modes.
- The field readout uses a
<dl> so screen readers announce labels with their values.
- Set
heading-level so the panel’s headings fit the page outline.
- Runtime values (endpoint, path, referrer, context keys) are written as text, never parsed as HTML, so a crafted URL or referrer cannot inject markup.