@shotik/react-native 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +26 -0
  3. package/README.md +39 -3
  4. package/README.ru.md +40 -3
  5. package/dist/analytics/core.d.ts +96 -11
  6. package/dist/analytics/core.js +295 -22
  7. package/dist/analytics/privacy.d.ts +4 -0
  8. package/dist/analytics/privacy.js +46 -0
  9. package/dist/analytics/replay.d.ts +41 -0
  10. package/dist/analytics/replay.js +192 -0
  11. package/dist/analytics/rn.d.ts +52 -2
  12. package/dist/analytics/rn.js +669 -62
  13. package/dist/analytics/wire.d.ts +54 -2
  14. package/dist/analytics/wire.js +44 -4
  15. package/dist/client.d.ts +94 -1
  16. package/dist/client.js +254 -17
  17. package/dist/flow.d.ts +48 -0
  18. package/dist/flow.js +56 -0
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +2 -2
  21. package/dist/parts.d.ts +42 -1
  22. package/dist/parts.js +72 -14
  23. package/dist/react.d.ts +24 -3
  24. package/dist/react.js +42 -15
  25. package/dist/sheet.d.ts +2 -1
  26. package/dist/sheet.js +207 -16
  27. package/dist/support.js +2 -2
  28. package/dist/theme.d.ts +43 -0
  29. package/dist/theme.js +90 -4
  30. package/package.json +15 -2
  31. package/recipe.json +1 -1
  32. package/src/analytics/README.md +10 -6
  33. package/src/analytics/core.ts +314 -25
  34. package/src/analytics/privacy.ts +50 -0
  35. package/src/analytics/recipe.json +1 -1
  36. package/src/analytics/replay.ts +190 -0
  37. package/src/analytics/rn.tsx +620 -63
  38. package/src/analytics/wire.ts +99 -8
  39. package/src/client.ts +344 -19
  40. package/src/flow.ts +100 -0
  41. package/src/index.ts +4 -4
  42. package/src/parts.tsx +102 -14
  43. package/src/react.tsx +57 -16
  44. package/src/sheet.tsx +423 -20
  45. package/src/support.ts +2 -2
  46. package/src/theme.ts +90 -4
@@ -6,7 +6,7 @@
6
6
  export const WIRE_VERSION = 1
7
7
 
8
8
  // Event types. Codes are the array position, so append only.
9
- export const TYPES = ['session', 'open', 'close', 'screen', 'leave', 'tap', 'rage', 'scroll', 'error', 'slow', 'purchase', 'custom', 'identify', 'snapshot'] as const
9
+ export const TYPES = ['session', 'open', 'close', 'screen', 'leave', 'tap', 'rage', 'scroll', 'error', 'slow', 'purchase', 'custom', 'identify', 'snapshot', 'net', 'field', 'state', 'gesture'] as const
10
10
  export type EventType = (typeof TYPES)[number]
11
11
 
12
12
  export interface DeviceContext {
@@ -19,16 +19,31 @@ export interface DeviceContext {
19
19
  tz?: string
20
20
  w?: number
21
21
  h?: number
22
+ // Release context (additive, 2026-11-29): the running OTA update id (absent on the embedded bundle), its channel, the
23
+ // runtime version, the SDK as '<platform sdk>/<version>' (e.g. 'rn/0.2.0'), the UTC offset in minutes (east positive,
24
+ // UTC+8 = 480), and dev: 1 in development builds.
25
+ ota?: string
26
+ ch?: string
27
+ rt?: string
28
+ sdk?: string
29
+ tzo?: number
30
+ dev?: 1
22
31
  }
23
32
 
24
33
  // Props by type (all optional, short keys keep batches small):
25
34
  // session { first: 1 on the first session of this install, store: 'none' | 'error' when the id can't persist }
26
35
  // screen { from, ms (ready time) } leave { dur, depth (0..1), drag (pt), stalls, maxStall }
27
- // tap { el, id, label, x, y, nx, ny (0..1000), dead: 1, input: 1 } rage { el, id, label, n, x, y }
28
- // id is the stable element key (testID, nativeID or a structural hash); el and label are for display
36
+ // tap { el, x, y, nx, ny (0..1000), id, label, dead: 1, input: 1, resp (ms to the first response) } rage { el, id, label, n, x, y }
37
+ // id is the stable element key (testID, nativeID or a structural hash); el and label are for display; x, y, nx, ny absent when masked
29
38
  // error { msg, fatal: 1, stack (top frames, no values) } slow { ms, kind: 'ready' | 'stall' }
30
- // purchase { product, price, currency, status: start | done | cancel | fail, store, trial: 1 }
39
+ // purchase { product, status: start | done | cancel | fail, price, currency, store, trial: 1, renew: 1, conv: 1, at (store purchase ms) }
31
40
  // custom free-form (no PII by contract) identify { traits }
41
+ // net { m (method), host, path (template, no query), s (status, 0 = network error), ms }: failures and slow calls only
42
+ // field { id, el, ms (focused), edits (<= 20, none on secure inputs), filled: 1 }: one per focus span, never a value or length
43
+ // state { h (32-bit hash, 8 hex chars), n }: the visible interactive element set changed on the same screen
44
+ // gesture { k: long | swipe | pan | pinch, dir: left | right | up | down | in | out, dx, dy (pt), ms, el, id, sc (pinch scale) }: never a position
45
+ // scroll { el, id, off, len, vis (pt), hz: 1, pg (pager page) }: a container settled at a new offset after a touch scrolled it
46
+ // close { perf: { tap, walk, fp (p95 ms), rb, eb (replay / event bytes sent this session) } }
32
47
  export interface WireEvent {
33
48
  seq: number
34
49
  ts: number
@@ -37,6 +52,9 @@ export interface WireEvent {
37
52
  name?: string
38
53
  screen?: string
39
54
  props?: Record<string, unknown>
55
+ // 'test': a connection check (ShotikAnalytics.sendTestEvent, Shotik's "Send test event"). The server keeps test events apart,
56
+ // so they prove the key and the path work and never count as a user, a session or a metric.
57
+ kind?: 'test'
40
58
  }
41
59
 
42
60
  export interface Batch {
@@ -48,7 +66,8 @@ export interface Batch {
48
66
  }
49
67
 
50
68
  // [dt, type, seq, session, screen, name, props]; string slots are dictionary indexes, -1 = absent.
51
- export type PackedEvent = [number, number, number, number, number, number, Record<string, unknown> | 0]
69
+ // The optional 8th slot is 1 for a test event; older servers ignore it.
70
+ export type PackedEvent = [number, number, number, number, number, number, Record<string, unknown> | 0, 1?]
52
71
  export interface PackedBatch {
53
72
  v: 1
54
73
  a: string
@@ -89,7 +108,9 @@ export function pack(b: Batch): PackedBatch {
89
108
  p[k] = PACKED_PROPS.includes(k) && typeof v === 'string' ? s(v) : v
90
109
  }
91
110
  }
92
- return [dt, TYPES.indexOf(ev.type), ev.seq, s(ev.sessionId), s(ev.screen), s(ev.name), p]
111
+ const row: PackedEvent = [dt, TYPES.indexOf(ev.type), ev.seq, s(ev.sessionId), s(ev.screen), s(ev.name), p]
112
+ if (ev.kind === 'test') row.push(1)
113
+ return row
93
114
  })
94
115
  return { v: 1, a: b.anonymousId, u: b.userId ?? null, f: b.firstSeen, c: b.device, t0, d, e }
95
116
  }
@@ -97,14 +118,14 @@ export function pack(b: Batch): PackedBatch {
97
118
  export function unpack(p: PackedBatch): Batch {
98
119
  const str = (i: number) => (i >= 0 && i < p.d.length ? p.d[i] : undefined)
99
120
  let ts = p.t0
100
- const events = p.e.map(([dt, type, seq, sess, screen, name, props]): WireEvent => {
121
+ const events = p.e.map(([dt, type, seq, sess, screen, name, props, test]): WireEvent => {
101
122
  ts += dt
102
123
  let pr: Record<string, unknown> | undefined
103
124
  if (props) {
104
125
  pr = {}
105
126
  for (const k in props) pr[k] = PACKED_PROPS.includes(k) && typeof props[k] === 'number' ? str(props[k] as number) : props[k]
106
127
  }
107
- return { seq, ts, type: TYPES[type] ?? 'custom', sessionId: str(sess) ?? '', screen: str(screen), name: str(name), props: pr }
128
+ return { seq, ts, type: TYPES[type] ?? 'custom', sessionId: str(sess) ?? '', screen: str(screen), name: str(name), props: pr, ...(test === 1 && { kind: 'test' as const }) }
108
129
  })
109
130
  return { anonymousId: p.a, userId: p.u ?? null, firstSeen: p.f, device: p.c, events }
110
131
  }
@@ -121,3 +142,73 @@ export interface Wireframe {
121
142
  dark?: boolean
122
143
  nodes: WireNode[]
123
144
  }
145
+
146
+ // Wireframe replay (PROTOCOL.md 4.7): POST /analytics/v1/replay. A keyframe per screen, then diffs of changed nodes keyed by
147
+ // a stable key (base36 FNV-1a of kind + host index path). KeyedNode: [key, kind, x, y, w, h, fill?, radius?, in?]; with in
148
+ // (a scroll container's key) x, y are in that container's content space. Kinds as WireNode plus w (web view).
149
+ export type KeyedNode = [string, string, number, number, number, number, (string | null)?, (number | null)?, (string | null)?]
150
+ export interface ReplayScroll {
151
+ node: string
152
+ y: number
153
+ x?: number
154
+ }
155
+ export interface ReplayRun {
156
+ after: string | null
157
+ nodes: KeyedNode[]
158
+ }
159
+ export interface ReplayChunk {
160
+ sess: string
161
+ seq: number
162
+ t: number
163
+ keyframe?: { screen: string; w: number; h: number; nodes: KeyedNode[] }
164
+ diff?: { add?: ReplayRun[]; rm?: string[]; mv?: [string, number, number][] }
165
+ scroll?: ReplayScroll[]
166
+ }
167
+ export type ReplayWhy = 'sample' | 'rage' | 'dead' | 'unresponsive' | 'errtap' | 'error' | 'crash'
168
+ export interface ReplayUpload {
169
+ v: 1
170
+ a: string
171
+ why: ReplayWhy
172
+ chunks: ReplayChunk[]
173
+ }
174
+
175
+ // The picture after applying a chunk to the previous one (PROTOCOL.md 4.7): draw-ordered nodes and scroll offsets. Shared
176
+ // by the SDK tests and the server's player.
177
+ export interface ReplayPicture {
178
+ screen: string
179
+ w: number
180
+ h: number
181
+ nodes: KeyedNode[]
182
+ scroll: Record<string, { x: number; y: number }>
183
+ }
184
+
185
+ export function applyChunk(prev: ReplayPicture | null, c: ReplayChunk): ReplayPicture | null {
186
+ let pic: ReplayPicture | null
187
+ if (c.keyframe) pic = { screen: c.keyframe.screen, w: c.keyframe.w, h: c.keyframe.h, nodes: c.keyframe.nodes.slice(), scroll: {} }
188
+ else if (prev) pic = { ...prev, nodes: prev.nodes.slice(), scroll: { ...prev.scroll } }
189
+ else return null
190
+ const d = c.diff
191
+ if (d) {
192
+ const gone = new Set(d.rm ?? [])
193
+ for (const r of d.add ?? []) for (const n of r.nodes) gone.add(n[0])
194
+ let nodes = pic.nodes.filter((n) => !gone.has(n[0]))
195
+ for (const r of d.add ?? []) {
196
+ const i = r.after === null ? 0 : nodes.findIndex((n) => n[0] === r.after) + 1
197
+ nodes = nodes.slice(0, i).concat(r.nodes, nodes.slice(i))
198
+ }
199
+ if (d.mv?.length) {
200
+ const mv = new Map(d.mv.map((m) => [m[0], m]))
201
+ nodes = nodes.map((n) => {
202
+ const m = mv.get(n[0])
203
+ if (!m) return n
204
+ const k = n.slice() as KeyedNode
205
+ k[2] = m[1]
206
+ k[3] = m[2]
207
+ return k
208
+ })
209
+ }
210
+ pic.nodes = nodes
211
+ }
212
+ for (const s of c.scroll ?? []) pic.scroll[s.node] = { x: s.x ?? 0, y: s.y }
213
+ return pic
214
+ }