Tracking
Analytics in the PanelWave Player — consent-aware TrackingService, event whitelisting, batching, the endpoint payload, and player events.
The player's TrackingService is a privacy-conscious analytics pipeline: nothing is recorded without consent (when required), events can be whitelisted by the work's manifest, and delivery is batched to a configurable endpoint. Integrators can also bypass it entirely and forward the shell's Angular outputs to their own analytics.
How the manifest configures tracking
When a manifest with a tracking section loads, the shell configures the service automatically:
{
"tracking": {
"enabled": true,
"consent": { "required": true, "defaultOptIn": false },
"eventWhitelist": ["panelChange", "decision", "videoPlay", "videoEnded"],
"endpoint": "https://analytics.example.com/pw/events"
}
}
Mapping (verified in the shell's configureTracking):
| Manifest field | Effect |
|---|---|
consent.required | Sets consentRequired (defaults to true when absent) |
consent.defaultOptIn | If true, consent is granted immediately (until an explicit consent UI overrides it) |
eventWhitelist | Only listed event types are recorded; all others are dropped |
endpoint | Where batches are POSTed; without it, events stay in the local queue/observable only |
See Tracking (schema) for the format definition.
Consent
import { inject } from '@angular/core';
import { TrackingService } from '@panelwave/player';
const tracking = inject(TrackingService);
// Wire this to your cookie/consent banner:
tracking.setConsent(true);
tracking.getConsent(); // → boolean
While consentRequired is true and consent has not been given, track() is a no-op. Revoking consent (setConsent(false)) also clears any queued, unsent events.
Privacy mode for framed players
From player 2.4.0 a host page that frames the player can decide about analytics itself (embed protocol 4): with track=0 in the frame address, the host SDK option privacy: { tracking: false } or a setPrivacy message, TrackingService switches to privacy mode (setSuppressed(true)). Nothing is queued and no request leaves the player, whatever the work's consent setting says. The session_start is kept in memory only; when the host turns analytics on (setPrivacy({ tracking: true })), it is sent with the time of the opt-in. Events from before are not recovered. isSuppressed() reports the mode.
Recording events
tracking.track('decision', {
panelId: 'p-12',
choiceId: 'hs-door-left',
});
track(type, data?) applies, in order: consent check → whitelist check → debouncing for high-frequency types (scroll, mousemove, resize, progress; 300 ms default) → queue.
Each recorded event has this shape (TrackingEvent):
interface TrackingEvent {
type: string;
timestamp: number; // Date.now()
data?: Record<string, any>;
sessionId?: string; // anonymized, random per session
}
The session id is a crypto.randomUUID() generated when the service is created — it identifies a session, not a user.
Batching and delivery
Events are sent when the queue reaches 10 events (batchSize) or every 5 seconds (batchInterval), whichever comes first. Delivery is a JSON POST:
{
"sessionId": "6f0d…",
"events": [
{ "type": "panelChange", "timestamp": 1751712000000, "data": { "panelId": "p-2" }, "sessionId": "6f0d…" }
],
"timestamp": 1751712001234
}
A non-2xx response is logged; failed batches are not re-queued (deliberately, to avoid memory buildup). Useful controls:
| Method | Purpose |
|---|---|
configure(partialConfig) | Override endpoint, consentRequired, eventWhitelist, batchSize, batchInterval, debounceMs |
flush() | Send the current queue immediately (e.g. on beforeunload) |
clear() | Drop queued events and pending debounce timers |
getSessionId() / getQueueSize() | Introspection |
Events the player emits
The PlayerEvent enum defines the event vocabulary used by the player internals:
| Event | Value | Meaning |
|---|---|---|
READY | ready | Player initialized |
PANEL_CHANGE | panelChange | Navigation to a panel |
DECISION | decision | A branch choice was made |
PAYWALL_SHOWN | paywallShown | A gate was displayed |
ERROR | error | An error occurred |
STATE_CHANGE / PREFERENCE_CHANGE / LOCALE_CHANGE | stateChange / preferenceChange / localeChange | State, preference, locale updates |
VIDEO_PLAY | videoPlay | A video layer started |
VIDEO_PAUSE | videoPause | A video layer paused |
VIDEO_ENDED | videoEnded | A video finished — or was force-skipped after stalling |
VIDEO_LOOP | videoLoop | A loop/pingpong cycle completed |
Video events carry a VideoTrackingPayload:
interface VideoTrackingPayload {
panelId?: string;
assetId?: string;
trigger: 'view' | 'hover' | 'click' | 'sequencer';
reason?: 'ended' | 'stall-skip'; // qualifies VIDEO_ENDED
}
reason: 'stall-skip' marks videos the autoplay watchdog or the page-view sequencer skipped because the source never finished — valuable for spotting broken encodes in the wild.
Reading-session and hotspot events
Beyond video events, the shell instruments the reading session automatically — every event below flows through the same consent/whitelist pipeline:
| Event | When | Payload highlights |
|---|---|---|
session_start | Once, when tracking is configured | deviceType, locale, totalPanels (reading-order count), plus every field of the shell's trackingContext input (from 1.9.0; the PanelWave reader sends embedHost, the origin of the page that embeds it, and from 2.4.0 channel and listing when the frame runs on a confirmed channel) |
panel_view | Each panel the reader lands on (deduplicated) | panelId, chapterId, panelOrder |
transition | Every move from one panel to another (from 1.7.0) | fromPanelId, toPanelId, panelId (= the target), chapterId |
work_complete | Once, when the reader reaches an end panel of the last chapter (in a chapter without edges: its last panel in reading order) | panelId, chapterId |
hotspot_click | Every click/tap on panel content (panel, page and canvas view) | see below |
decision | The reader picked a path — in the branch chooser or with a goTo hotspot (from 1.7.0; replaces branch_choice) | panelId (= the panel chosen from), chapterId, fromPanelId, toPanelId, choiceId, choiceLabel, source (branch or hotspot), index (position in the edge list, branch chooser only) |
paywall_view | A paywall prompt is shown (from 1.7.0) | panelId, chapterId, ruleId, scope, refId, lockReason, requireEntitlement |
paywallAction | The reader acts on a paywall prompt (from 1.7.0; whitelistable from format 1.9) | as paywall_view, plus action (purchase, subscribe, login or dismiss) and productId when one was chosen |
lang_change | The reader switches language (from 1.7.0) | from, to, panelId, chapterId |
like | Like toggled | workId, liked, panelId, chapterId (panel fields from 1.7.0) |
bookmark | Bookmark set or cleared | workId, chapterId, panelId, bookmarked |
share | The reader copies or posts a link from the share dialog — not on opening it (from 1.7.0) | workId, channel (copy, twitter, facebook, …), panelId, chapterId, url |
speech_toggle / audio_toggle / sfx_toggle | A sound toggle changed (toolbar or Settings) | enabled |
session_end | On page hide / destroy, followed by a synchronous flush (sendBeacon) | — |
From 1.9.0, every event that names a chapterId also carries chapterUuid when that chapter has a chapterId in the manifest (the CMS's permanent chapter id). Manifest chapter ids such as ch-2 follow the chapter's position, so an analytics backend that keys on chapterUuid keeps its figures when the author reorders chapters.
hotspot_click
Activating a hotspot — and, deliberately, also clicking panel artwork that hits no hotspot — records a hotspot_click:
{
"type": "hotspot_click",
"data": {
"panelId": "p-12",
"chapterId": "ch-1",
"hotspotId": "hs-door",
"x": 0.3142,
"y": 0.6108,
"hit": true
}
}
x/yare normalized (0–1), panel-relative coordinates of the click.hit: truecarries thehotspotId;hit: falsemarks a dead click — a tap that missed every hotspot — and omitshotspotId.- Keyboard activations report the shape's centroid.
Dead clicks are recorded on purpose: they show where readers try to interact, which powers the click heatmap in the CMS — see Analytics (CMS). Like every event, hotspot_click respects consent and must be present in the manifest's eventWhitelist to be recorded.
Forwarding player activity yourself
If you already have an analytics stack, subscribe to the shell's outputs and forward what you need — no TrackingService required:
import { Component } from '@angular/core';
import { PlayerShellComponent } from '@panelwave/player';
import type { PlayerPanelChangeEvent } from '@panelwave/player';
@Component({
selector: 'app-reader',
standalone: true,
imports: [PlayerShellComponent],
template: `
<pw-player-shell
[manifest]="manifest"
(ready)="analytics.event('pw_ready')"
(panelChange)="onPanel($event)"
(navigationAttempt)="analytics.event('pw_nav', $event)"
(localeChange)="analytics.event('pw_locale', { locale: $event })"
(likeChange)="analytics.event('pw_like', $event)"
(bookmarkChange)="analytics.event('pw_bookmark', $event)"
(error)="analytics.event('pw_error', { message: $event.message })">
</pw-player-shell>
`,
})
export class ReaderComponent {
// panelChange fires exactly once per navigation — no de-duplication needed.
// panelId / previousPanelId are part of the payload from player 1.2.0.
onPanel(e: PlayerPanelChangeEvent): void {
this.analytics.event('pw_panel_view', {
chapterId: e.chapter.id,
panelId: e.panelId,
from: e.previousPanelId,
});
}
}
Creators publishing through the PanelWave platform get aggregated dashboards in the CMS — see Analytics (CMS).