@shotik/react-native 0.1.1 → 0.2.2
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.
- package/CHANGELOG.md +20 -0
- package/LICENSE +26 -0
- package/README.md +36 -1
- package/README.ru.md +37 -1
- package/dist/analytics/core.d.ts +111 -12
- package/dist/analytics/core.js +303 -22
- package/dist/analytics/privacy.d.ts +4 -0
- package/dist/analytics/privacy.js +46 -0
- package/dist/analytics/replay.d.ts +41 -0
- package/dist/analytics/replay.js +192 -0
- package/dist/analytics/rn.d.ts +53 -2
- package/dist/analytics/rn.js +687 -63
- package/dist/analytics/wire.d.ts +54 -2
- package/dist/analytics/wire.js +44 -4
- package/dist/client.d.ts +93 -0
- package/dist/client.js +247 -9
- package/dist/flow.d.ts +48 -0
- package/dist/flow.js +56 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/parts.d.ts +42 -1
- package/dist/parts.js +72 -14
- package/dist/react.d.ts +24 -3
- package/dist/react.js +42 -15
- package/dist/sheet.d.ts +2 -1
- package/dist/sheet.js +206 -15
- package/dist/support.js +2 -2
- package/dist/theme.d.ts +43 -0
- package/dist/theme.js +88 -2
- package/package.json +15 -2
- package/recipe.json +1 -1
- package/src/analytics/README.md +10 -6
- package/src/analytics/core.ts +324 -25
- package/src/analytics/privacy.ts +50 -0
- package/src/analytics/recipe.json +1 -1
- package/src/analytics/replay.ts +190 -0
- package/src/analytics/rn.tsx +636 -64
- package/src/analytics/wire.ts +101 -8
- package/src/client.ts +334 -9
- package/src/flow.ts +100 -0
- package/src/index.ts +4 -4
- package/src/parts.tsx +102 -14
- package/src/react.tsx +57 -16
- package/src/sheet.tsx +422 -19
- package/src/support.ts +2 -2
- package/src/theme.ts +88 -2
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// Wireframe replay (PROTOCOL.md 4.7): turns walks into keyframe / diff chunks and decides where they go. A sampled session
|
|
2
|
+
// sends every chunk; any other session keeps the last 30 s in a ring (<= 1 MB, starting at a keyframe) and releases it
|
|
3
|
+
// only when a signal fires (rage, dead, unresponsive or error tap, error, crash). Platform-free, like core.ts.
|
|
4
|
+
export const RING_MS = 30000;
|
|
5
|
+
export const MAX_BYTES = 1 << 20;
|
|
6
|
+
const TAIL_MS = 5000;
|
|
7
|
+
const BODY = 64 * 1024;
|
|
8
|
+
const KEY_SHARE = 0.6;
|
|
9
|
+
const REKEY_MS = RING_MS / 2;
|
|
10
|
+
// A later signal inside the 5 s tail relabels its release when it ranks higher (a rage burst first releases on its
|
|
11
|
+
// unresponsive taps).
|
|
12
|
+
const RANK = ['sample', 'unresponsive', 'dead', 'errtap', 'rage', 'error', 'crash'];
|
|
13
|
+
const same = (a, b) => a[1] === b[1] && a[4] === b[4] && a[5] === b[5] && (a[6] ?? null) === (b[6] ?? null) && (a[7] ?? null) === (b[7] ?? null) && (a[8] ?? null) === (b[8] ?? null);
|
|
14
|
+
const at = (s) => (s.x ?? 0) + ',' + s.y;
|
|
15
|
+
export class Replay {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.out = [];
|
|
18
|
+
this.off = false;
|
|
19
|
+
this.ring = [];
|
|
20
|
+
this.why = 'sample';
|
|
21
|
+
this.sess = '';
|
|
22
|
+
this.seq = 0;
|
|
23
|
+
this.prev = null;
|
|
24
|
+
this.screen = '';
|
|
25
|
+
this.offsets = new Map();
|
|
26
|
+
this.lastKey = 0;
|
|
27
|
+
this.tail = 0;
|
|
28
|
+
}
|
|
29
|
+
// One capture. Returns the chunk it built, or null when nothing changed since the last one.
|
|
30
|
+
frame(sess, sampled, w, t) {
|
|
31
|
+
if (this.off)
|
|
32
|
+
return null;
|
|
33
|
+
if (sess !== this.sess) {
|
|
34
|
+
this.sess = sess;
|
|
35
|
+
this.seq = 0;
|
|
36
|
+
this.prev = null;
|
|
37
|
+
this.ring = [];
|
|
38
|
+
this.tail = 0;
|
|
39
|
+
}
|
|
40
|
+
const ring = !sampled && t > this.tail;
|
|
41
|
+
const next = new Map();
|
|
42
|
+
for (const n of w.nodes)
|
|
43
|
+
next.set(n[0], n);
|
|
44
|
+
let key = !this.prev || w.screen !== this.screen || (ring && t - this.lastKey > REKEY_MS);
|
|
45
|
+
let c = null;
|
|
46
|
+
if (!key) {
|
|
47
|
+
const prev = this.prev;
|
|
48
|
+
const scroll = w.scroll.filter((s) => this.offsets.get(s.node) !== at(s) && (this.offsets.has(s.node) || s.y || s.x));
|
|
49
|
+
const rm = [];
|
|
50
|
+
for (const k of prev.keys())
|
|
51
|
+
if (!next.has(k))
|
|
52
|
+
rm.push(k);
|
|
53
|
+
const add = [];
|
|
54
|
+
const mv = [];
|
|
55
|
+
let run = null;
|
|
56
|
+
let adds = 0;
|
|
57
|
+
for (let i = 0; i < w.nodes.length; i++) {
|
|
58
|
+
const n = w.nodes[i];
|
|
59
|
+
const p = prev.get(n[0]);
|
|
60
|
+
if (p && same(p, n)) {
|
|
61
|
+
if (p[2] !== n[2] || p[3] !== n[3])
|
|
62
|
+
mv.push([n[0], n[2], n[3]]);
|
|
63
|
+
run = null;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
adds++;
|
|
67
|
+
if (!run)
|
|
68
|
+
add.push((run = { after: i ? w.nodes[i - 1][0] : null, nodes: [] }));
|
|
69
|
+
run.nodes.push(n);
|
|
70
|
+
}
|
|
71
|
+
if (adds > KEY_SHARE * w.nodes.length)
|
|
72
|
+
key = true;
|
|
73
|
+
else if (adds || rm.length || mv.length || scroll.length) {
|
|
74
|
+
const diff = {};
|
|
75
|
+
if (add.length)
|
|
76
|
+
diff.add = add;
|
|
77
|
+
if (rm.length)
|
|
78
|
+
diff.rm = rm;
|
|
79
|
+
if (mv.length)
|
|
80
|
+
diff.mv = mv;
|
|
81
|
+
c = { sess, seq: this.seq + 1, t, ...(adds || rm.length || mv.length ? { diff } : {}), ...(scroll.length ? { scroll } : {}) };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (key) {
|
|
85
|
+
const sc = w.scroll.filter((s) => s.y || s.x);
|
|
86
|
+
c = { sess, seq: this.seq + 1, t, keyframe: { screen: w.screen, w: w.w, h: w.h, nodes: w.nodes }, ...(sc.length ? { scroll: sc } : {}) };
|
|
87
|
+
this.lastKey = t;
|
|
88
|
+
}
|
|
89
|
+
this.prev = next;
|
|
90
|
+
this.screen = w.screen;
|
|
91
|
+
this.offsets.clear();
|
|
92
|
+
for (const s of w.scroll)
|
|
93
|
+
this.offsets.set(s.node, at(s));
|
|
94
|
+
if (!c)
|
|
95
|
+
return null;
|
|
96
|
+
this.seq = c.seq;
|
|
97
|
+
const b = { c, s: JSON.stringify(c), key, why: sampled ? 'sample' : this.why };
|
|
98
|
+
if (ring) {
|
|
99
|
+
this.ring.push(b);
|
|
100
|
+
this.trimRing(t);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
this.out.push(b);
|
|
104
|
+
this.cap(this.out);
|
|
105
|
+
}
|
|
106
|
+
return c;
|
|
107
|
+
}
|
|
108
|
+
// A signal releases the ring to the outbox; chunks built in the next 5 s follow it.
|
|
109
|
+
signal(why, t) {
|
|
110
|
+
if (this.off)
|
|
111
|
+
return;
|
|
112
|
+
if (t <= this.tail) {
|
|
113
|
+
if (RANK.indexOf(why) <= RANK.indexOf(this.why))
|
|
114
|
+
return;
|
|
115
|
+
for (const b of this.out)
|
|
116
|
+
if (b.why === this.why && b.c.sess === this.sess)
|
|
117
|
+
b.why = why;
|
|
118
|
+
this.why = why;
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
this.why = why;
|
|
122
|
+
this.tail = t + TAIL_MS;
|
|
123
|
+
for (const b of this.ring)
|
|
124
|
+
this.out.push({ ...b, why });
|
|
125
|
+
this.ring = [];
|
|
126
|
+
this.cap(this.out);
|
|
127
|
+
}
|
|
128
|
+
// Ring: drop everything before the newest keyframe that is at least 30 s old (a keyframe is re-taken every 15 s, so the
|
|
129
|
+
// ring spans 30-45 s), then keep it under 1 MB.
|
|
130
|
+
trimRing(t) {
|
|
131
|
+
let k = -1;
|
|
132
|
+
for (let i = 0; i < this.ring.length; i++)
|
|
133
|
+
if (this.ring[i].key && this.ring[i].c.t <= t - RING_MS)
|
|
134
|
+
k = i;
|
|
135
|
+
if (k > 0)
|
|
136
|
+
this.ring.splice(0, k);
|
|
137
|
+
this.cap(this.ring);
|
|
138
|
+
}
|
|
139
|
+
// Over 1 MB: drop the oldest chunks, then up to the next keyframe, so what stays starts decodable. Emptied: the next
|
|
140
|
+
// capture is a keyframe.
|
|
141
|
+
cap(list) {
|
|
142
|
+
let bytes = 0;
|
|
143
|
+
for (const b of list)
|
|
144
|
+
bytes += b.s.length;
|
|
145
|
+
if (bytes <= MAX_BYTES)
|
|
146
|
+
return;
|
|
147
|
+
let i = 0;
|
|
148
|
+
while (i < list.length && bytes > MAX_BYTES)
|
|
149
|
+
bytes -= list[i++].s.length;
|
|
150
|
+
while (i < list.length && !list[i].key)
|
|
151
|
+
i++;
|
|
152
|
+
list.splice(0, i);
|
|
153
|
+
if (!list.length)
|
|
154
|
+
this.prev = null;
|
|
155
|
+
}
|
|
156
|
+
get ringBytes() {
|
|
157
|
+
let n = 0;
|
|
158
|
+
for (const b of this.ring)
|
|
159
|
+
n += b.s.length;
|
|
160
|
+
return n;
|
|
161
|
+
}
|
|
162
|
+
// The next request: consecutive outbox chunks with one why, up to 64 KB (a larger single chunk goes alone).
|
|
163
|
+
take() {
|
|
164
|
+
if (!this.out.length)
|
|
165
|
+
return null;
|
|
166
|
+
const why = this.out[0].why;
|
|
167
|
+
const items = [];
|
|
168
|
+
let n = 0;
|
|
169
|
+
for (const b of this.out) {
|
|
170
|
+
if (b.why !== why || (items.length && n + b.s.length > BODY))
|
|
171
|
+
break;
|
|
172
|
+
items.push(b);
|
|
173
|
+
n += b.s.length;
|
|
174
|
+
}
|
|
175
|
+
return { why, items };
|
|
176
|
+
}
|
|
177
|
+
done(items) {
|
|
178
|
+
const sent = new Set(items);
|
|
179
|
+
this.out = this.out.filter((b) => !sent.has(b));
|
|
180
|
+
}
|
|
181
|
+
restore(why, chunks) {
|
|
182
|
+
this.out = chunks.map((c) => ({ c, s: JSON.stringify(c), key: !!c.keyframe, why })).concat(this.out);
|
|
183
|
+
}
|
|
184
|
+
// Consent denied, or stop (a 403: replay off or over quota) until the next launch.
|
|
185
|
+
clear(stop = false) {
|
|
186
|
+
this.out = [];
|
|
187
|
+
this.ring = [];
|
|
188
|
+
this.prev = null;
|
|
189
|
+
if (stop)
|
|
190
|
+
this.off = true;
|
|
191
|
+
}
|
|
192
|
+
}
|
package/dist/analytics/rn.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { ReactNode } from 'react';
|
|
|
3
3
|
import { View } from 'react-native';
|
|
4
4
|
import { Analytics } from './core';
|
|
5
5
|
import type { AnalyticsConfig, Consent, Storage } from './core';
|
|
6
|
+
import type { KeyedNode, ReplayScroll } from './wire';
|
|
6
7
|
type Fiber = {
|
|
7
8
|
type: unknown;
|
|
8
9
|
tag: number;
|
|
@@ -12,29 +13,76 @@ type Fiber = {
|
|
|
12
13
|
sibling: Fiber | null;
|
|
13
14
|
index: number;
|
|
14
15
|
stateNode: unknown;
|
|
16
|
+
alternate?: Fiber | null;
|
|
17
|
+
memoizedState?: unknown;
|
|
15
18
|
};
|
|
16
|
-
|
|
19
|
+
type Labels = NonNullable<AnalyticsConfig['labels']>;
|
|
20
|
+
export declare function describeTarget(target: Fiber | null, labels?: Labels): {
|
|
17
21
|
el: string;
|
|
18
22
|
id: string;
|
|
19
23
|
label?: string;
|
|
20
24
|
dead: boolean;
|
|
21
25
|
input: boolean;
|
|
26
|
+
masked: boolean;
|
|
27
|
+
secure: boolean;
|
|
22
28
|
scroll: Fiber | null;
|
|
23
29
|
};
|
|
30
|
+
export declare function uiFingerprint(root: Fiber | null, W: number, H: number): {
|
|
31
|
+
h: string;
|
|
32
|
+
n: number;
|
|
33
|
+
} | null;
|
|
34
|
+
type HostEl = {
|
|
35
|
+
tagName?: string;
|
|
36
|
+
children?: ArrayLike<HostEl>;
|
|
37
|
+
getBoundingClientRect?: () => {
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
width: number;
|
|
41
|
+
height: number;
|
|
42
|
+
};
|
|
43
|
+
__internalInstanceHandle?: Fiber;
|
|
44
|
+
};
|
|
45
|
+
export declare function replayWalk(root: HostEl | null, W: number, H: number): {
|
|
46
|
+
nodes: KeyedNode[];
|
|
47
|
+
scroll: ReplayScroll[];
|
|
48
|
+
} | null;
|
|
24
49
|
interface RootProps {
|
|
25
50
|
children?: ReactNode;
|
|
26
51
|
}
|
|
27
52
|
export declare class ShotikAnalyticsRoot extends Component<RootProps> {
|
|
28
53
|
private root;
|
|
29
54
|
private start;
|
|
55
|
+
private capTimer;
|
|
56
|
+
private capAt;
|
|
57
|
+
private capAgain;
|
|
58
|
+
private lastCap;
|
|
59
|
+
private capGap;
|
|
60
|
+
private settling;
|
|
61
|
+
private lastOff;
|
|
30
62
|
private snapTimer;
|
|
31
|
-
private
|
|
63
|
+
private walkTimer;
|
|
64
|
+
private firstKick;
|
|
65
|
+
private lastWalk;
|
|
66
|
+
private gap;
|
|
67
|
+
private loud;
|
|
68
|
+
private focus;
|
|
32
69
|
private unsub;
|
|
33
70
|
componentDidMount(): void;
|
|
34
71
|
componentWillUnmount(): void;
|
|
72
|
+
private kick;
|
|
73
|
+
private walk;
|
|
74
|
+
private capture;
|
|
75
|
+
private snap;
|
|
76
|
+
private onFocus;
|
|
77
|
+
private onChange;
|
|
78
|
+
private onBlur;
|
|
79
|
+
private endField;
|
|
35
80
|
private queueSnapshot;
|
|
36
81
|
private onStart;
|
|
82
|
+
private onMove;
|
|
83
|
+
private onCancel;
|
|
37
84
|
private onEnd;
|
|
85
|
+
private settle;
|
|
38
86
|
render(): import("react").CElement<import("react-native").ViewProps, View>;
|
|
39
87
|
}
|
|
40
88
|
export declare function ShotikMask({ children, style }: {
|
|
@@ -72,11 +120,14 @@ export declare const ShotikAnalytics: {
|
|
|
72
120
|
screen: typeof screen;
|
|
73
121
|
identify: (userId: string | null, traits?: Record<string, unknown>) => void | undefined;
|
|
74
122
|
purchase: (p: Parameters<Analytics["purchase"]>[0]) => void | undefined;
|
|
123
|
+
sheet: (p: Parameters<Analytics["sheet"]>[0]) => void | undefined;
|
|
75
124
|
setConsent: (c: Consent) => void | undefined;
|
|
76
125
|
optOut: () => void | undefined;
|
|
77
126
|
optIn: () => void | undefined;
|
|
78
127
|
reset: () => Promise<void> | undefined;
|
|
128
|
+
forget: () => Promise<boolean>;
|
|
79
129
|
flush: () => Promise<void> | undefined;
|
|
130
|
+
sendTestEvent: () => Promise<void>;
|
|
80
131
|
trackNavigation: typeof trackNavigation;
|
|
81
132
|
trackRevenueCat: typeof trackRevenueCat;
|
|
82
133
|
stop(): void;
|