analytics library
Shotik Analytics: sessions, screens, taps with their response time, rage and dead taps, UI-state changes, text field spans, gestures, settled scrolls, failed and slow requests, scroll depth, errors, stalls, store-truth purchases, custom events, identify, wireframes and wireframe replay, packed byte-compatible with wire.ts (PROTOCOL.md section 4), with on-device redaction (section 7).
Classes
- Analytics
- Batch
- DeviceContext
- Entitled
- An active store entitlement: product, its latest and first purchase (ms), trial period. price and currency are optional extras for a store that reports them with the transaction (in_app_purchase).
- ErasableAnalytics
- An install's analytics as Delete my data sees it: forget() asks the server to delete the install and starts a new one; reset() starts a new one when forget could not reach the server.
- FileStorage
- HealthFilter
-
Tap and rage labels (after redaction) that contain a health term become "
health". HEALTH_TERMS is always on;extraadds app terms under the same rules. Element ids are not touched. - HttpTransport
- MemoryStorage
- RenderShotikMask
- ReplayPicture
- The picture after applying a chunk to the previous one: draw-ordered nodes and scroll offsets.
- ReplayWalk
- One capture: the screen, the window size, keyed nodes in draw order and the scroll containers' offsets.
- Shotik
- ShotikAnalytics
- ShotikConfig
- ShotikDevice
- ShotikMask
- Hides what's inside from tap labels, wireframes and replay (one grey block). EditableText is always masked; see ShotikMaskKey for the same as a flag on any widget.
- ShotikMaskKey
-
The mask as a flag on any widget (React Native's
shotikMask):Text(card.number, key: const ShotikMaskKey())hides that widget from tap labels, tap positions, wireframes and replay, the same as wrapping it in ShotikMask. value tells masked siblings apart (ShotikMaskKey('pan')), since sibling keys must differ. - ShotikNative
- ShotikResponse
- ShotikRoot
- ShotikRootState
- ShotikScreen
-
Names the screen it is on:
ShotikScreen(name: 'Paywall', child: ...). Wins over the route name. - ShotikSocket
- ShotikStorage
- ShotikTransport
- TapTarget
- WireEvent
- Wireframe
Enums
- Consent
- Labels
- Tap labels (PROTOCOL.md §7): a11y (the default) sends the Semantics label, else words from the developer id (startTrialButton -> "Start trial button"), else nothing; visible also falls back to the visible text under the pressed element (≤ 40 characters); none sends no labels. Element ids are unaffected.
Constants
- batchSize → const int
- DEFAULT_SERVER → const String
-
eventTypes
→ const List<
String> - Event types. Codes are the list position, so append only.
-
HEALTH_TERMS
→ const List<
String> - kOffIsolateEvents → const int
- Batches with more events than this are packed and encoded on a background isolate (see test/perf_test.dart).
- maxQueue → const int
- replayMaxBytes → const int
- replayRingMs → const int
- sdkVersion → const String
-
Sent as
sdk: 'flutter/<version>'in the device context. Keep equal to pubspec.yaml (a unit test checks it). - wireVersion → const int
Functions
-
applyChunk(
ReplayPicture? prev, ReplayChunk c) → ReplayPicture? - A port of wire.ts applyChunk: (1) delete every key in rm and every key in a run, (2) insert each run after its predecessor (null: at the start), (3) move each mv key, (4) apply scroll. A keyframe starts a new picture.
-
cleanProps(
Map< String, Object?> ? props, {bool dev = false, int depth = 0}) → Map<String, Object?> ? -
Custom props and identify traits: personal-data keys dropped (one warning per key when
dev), string values redacted, 3 levels deep. -
describeTarget(
Element root, RenderBox box, Offset global, {Labels? labels}) → TapTarget - The element under a point, from the render tree (hit test) and the element tree along the hit path.
-
encodeBatch(
Batch b) → String - The request body for a batch. Top-level so it can run on a background isolate via compute().
-
encodeJson(
Object? value) → String -
flushInterval(
int flushMs, int backoff) → Duration - Analytics flush interval: flushMs × 2^backoff, backoff capped at 5.
-
healthPattern(
[List< String> extra = const []]) → RegExp - The filter as one regex: HEALTH_TERMS plus the app's healthTerms, matched against the lowercased label.
-
idWords(
String id) → String - A developer id as words for a label: startTrialButton, start-trial, plan_card.annual -> "Start trial button", "Start trial", "Plan card annual".
-
localId(
String prefix) → String - prefix + time in base 36 + 8 random characters, like the reference's localId().
-
netTarget(
String url) → ({String host, String path}) - A request URL as host + path template: no scheme, credentials, query or fragment; ids, UUIDs, hex, digit runs, tokens of 8+ characters with 2+ digits, emails, anything redact() changes and percent-encoded or non-ASCII segments become :id (a file extension stays). A plain-word segment (a username) can't be detected and stays.
-
pack(
Batch b) → Map< String, Object?> -
{ v, a, u, f?, c?, t0, d, e } with e =
dt, type, seq, session, screen, name, props | 0. -
reconnectDelay(
int n, [Random? random]) → Duration - Reconnect delay: min(30 s, 500 ms × 2^n) × uniform(0.8, 1.2), n = consecutive failures.
-
redact(
String s) → String -
Emails, phone numbers, ids, tokens, credentials, long digit runs and URL queries replaced by placeholders
(
email,phone,id,token,n). -
replayWalk(
Element from, RenderBox root) → ({List< KeyedNode> nodes, List<ReplayScroll> scroll}) -
resolveServer(
String? url, {bool release = kReleaseMode}) → String? -
The base URL to use, or null when nothing may be sent. Trailing slashes are removed. An empty URL, or in a release
build (not
release== false) plain http to a host outside loopback, *.local, 10/8, 172.16/12, 192.168/16, 169.254/16 and fc00::/7, sends nothing and warns once. https is always allowed; debug builds allow anything. -
retryAfter(
int status, Map< String, String> headers, DateTime now) → Duration? - How long a 429 or 503 asks the client to wait (Retry-After in seconds or as an HTTP date), capped at 1 h; null when the status is another one or the header is missing or unreadable (the caller then uses its normal backoff).
-
retryDelay(
int attempts) → Duration - Send retry delay: min(30 s, 500 ms × 2^attempts).
-
uiFingerprint(
Element from, RenderBox root) → ({String h, int n})? -
UI-state fingerprint (PROTOCOL.md 4.1 state): FNV-1a 32 of the sorted set of interactive elements visible in
root(the developer id from a ValueKey or Semantics identifier, else "h" + hash of the element index path from the nearest route's PageStorage) plus "c" + index for each visible list cell, as 8 hex characters, and the set size. Offstage, ticker-disabled (routes under an opaque one), semantics-excluded and IndexedStack-hidden subtrees are skipped; handlers within 8 elements of the one above them are the same control. Null past 30000 elements. -
unpack(
Map< String, Object?> p) → Batch -
wireframe(
Element from, RenderBox root, {int cap = 400}) → List< KeyedNode> -
The screen under
fromas wireframe nodes inroot's coordinates (logical points), at mostcapnodes. Walks the element tree to read each render object's geometry and kind (RenderParagraph t, RenderImage i, RenderEditable n, ShotikMask or ShotikMaskKey m, tap handlers b, viewports s) and, for plain boxes, the fill from the widget (ColoredBox, DecoratedBox, Material). Offstage, transparent, tiny and off-screen boxes are skipped.
Typedefs
-
KeyedNode
= List<
Object?> -
Wireframe replay (PROTOCOL.md 4.7): POST /analytics/v1/replay. A keyframe per screen, then diffs of changed nodes keyed
by a stable key (base36 FNV-1a of kind + host index path). KeyedNode:
key, kind, x, y, w, h, fill?, radius?, in?; with in (a scroll container's key) x, y are in that container's content space. Kinds as WireNode plus w (web view). -
ReplayChunk
= Map<
String, Object?> -
{ sess, seq, t, keyframe?: { screen, w, h, nodes }, diff?: { add?:
{ after, nodes }, rm?, mv?: [key, x, y] }, scroll? } -
ReplayScroll
= Map<
String, Object?> - { node, y, x? }: a scroll container's content offset.
-
WireNode
= List<
Object?> -
A wireframe node:
kind, x, y, w, h, fill, radius(fill and radius null when absent, as the reference sends). Kinds: v view, t text, i image, b button, n input, s scroll, m masked.