@shotik/react-native 0.0.0-stage → 0.1.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.
package/package.json CHANGED
@@ -1,6 +1,116 @@
1
1
  {
2
2
  "name": "@shotik/react-native",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Shotik SDK for React Native and Expo: in-app support chat answered from Shotik, and product analytics.",
5
+ "keywords": [
6
+ "react-native",
7
+ "expo",
8
+ "support",
9
+ "chat",
10
+ "analytics",
11
+ "shotik"
12
+ ],
13
+ "homepage": "https://github.com/rahimwws/shotik-app/tree/main/sdk/react-native#readme",
14
+ "bugs": "https://github.com/rahimwws/shotik-app/issues",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/rahimwws/shotik-app.git",
18
+ "directory": "sdk/react-native"
19
+ },
20
+ "license": "MIT",
21
+ "type": "module",
22
+ "main": "dist/index.js",
23
+ "types": "dist/index.d.ts",
24
+ "react-native": "src/index.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "react-native": "./src/index.ts",
29
+ "default": "./dist/index.js"
30
+ },
31
+ "./client": {
32
+ "types": "./dist/client.d.ts",
33
+ "react-native": "./src/client.ts",
34
+ "default": "./dist/client.js"
35
+ },
36
+ "./analytics": {
37
+ "types": "./dist/analytics/index.d.ts",
38
+ "react-native": "./src/analytics/index.ts",
39
+ "default": "./dist/analytics/index.js"
40
+ },
41
+ "./package.json": "./package.json"
42
+ },
43
+ "files": [
44
+ "dist",
45
+ "src",
46
+ "README.md",
47
+ "README.ru.md",
48
+ "LICENSE",
49
+ "guide.json",
50
+ "recipe.json"
51
+ ],
52
+ "sideEffects": false,
53
+ "peerDependencies": {
54
+ "react": ">=18",
55
+ "react-native": ">=0.72",
56
+ "@react-native-async-storage/async-storage": "*",
57
+ "expo-application": "*",
58
+ "expo-device": "*",
59
+ "expo-image-picker": "*",
60
+ "expo-localization": "*",
61
+ "expo-router": "*",
62
+ "expo-secure-store": "*",
63
+ "react-native-mmkv": "*",
64
+ "react-native-safe-area-context": "*",
65
+ "react-native-svg": ">=13",
66
+ "react-native-view-shot": "*"
67
+ },
68
+ "peerDependenciesMeta": {
69
+ "@react-native-async-storage/async-storage": {
70
+ "optional": true
71
+ },
72
+ "expo-application": {
73
+ "optional": true
74
+ },
75
+ "expo-device": {
76
+ "optional": true
77
+ },
78
+ "expo-image-picker": {
79
+ "optional": true
80
+ },
81
+ "expo-localization": {
82
+ "optional": true
83
+ },
84
+ "expo-router": {
85
+ "optional": true
86
+ },
87
+ "expo-secure-store": {
88
+ "optional": true
89
+ },
90
+ "react-native-mmkv": {
91
+ "optional": true
92
+ },
93
+ "react-native-safe-area-context": {
94
+ "optional": true
95
+ },
96
+ "react-native-svg": {
97
+ "optional": true
98
+ },
99
+ "react-native-view-shot": {
100
+ "optional": true
101
+ }
102
+ },
103
+ "devDependencies": {
104
+ "@types/react": "^19.1.0",
105
+ "react-native": "^0.81.0",
106
+ "typescript": "^5.9.0"
107
+ },
108
+ "scripts": {
109
+ "build": "rm -rf dist && tsc -p tsconfig.build.json",
110
+ "prepack": "npm run build",
111
+ "test": "node --disable-warning=ExperimentalWarning --test ../../server/test/support.test.ts"
112
+ },
113
+ "publishConfig": {
114
+ "access": "public"
115
+ }
116
+ }
package/recipe.json ADDED
@@ -0,0 +1,263 @@
1
+ {
2
+ "schema": "shotik.recipe/1",
3
+ "id": "support-react-native",
4
+ "title": "Shotik Support SDK in a React Native / Expo app",
5
+ "package": "@shotik/react-native",
6
+ "rules": [
7
+ "Follow the repo's own conventions (AGENTS.md, CLAUDE.md, lint, import aliases, file layout) when placing code.",
8
+ "Edit only the files a step names or detects; never change native projects (ios/, android/): the SDK has no native code.",
9
+ "Replace {{VARS}} before writing. Keep edits minimal and idempotent: skip a step whose `done` check already passes.",
10
+ "The SDK has no dependencies beyond react and react-native; never add packages for it (optional peers are the app's choice)."
11
+ ],
12
+ "variables": {
13
+ "APP_KEY": {
14
+ "required": true,
15
+ "desc": "Public SDK key from Shotik (Support → SDK), spk_…; safe to ship in the app"
16
+ },
17
+ "SERVER_URL": {
18
+ "required": true,
19
+ "desc": "Shotik server URL the phone can reach (simulator: http://127.0.0.1:4590; device: the Mac's LAN address or your deployment)"
20
+ },
21
+ "METRO_PORT": {
22
+ "required": false,
23
+ "default": "8081",
24
+ "desc": "Port for the bundle check"
25
+ }
26
+ },
27
+ "detect": [
28
+ {
29
+ "id": "legacy",
30
+ "how": "package.json dependencies has \"@shotik/support-react-native\" (an older vendored copy, file:./vendor/…) → true",
31
+ "result": "true | false"
32
+ },
33
+ {
34
+ "id": "expo",
35
+ "how": "package.json dependencies has \"expo\"",
36
+ "result": "true | false"
37
+ },
38
+ {
39
+ "id": "packageManager",
40
+ "how": "bun.lock or bun.lockb → bun; pnpm-lock.yaml → pnpm; yarn.lock → yarn; else npm"
41
+ },
42
+ {
43
+ "id": "router",
44
+ "how": "\"expo-router\" in dependencies → expo-router; \"@react-navigation/native\" → react-navigation; else none"
45
+ },
46
+ {
47
+ "id": "routerRoot",
48
+ "when": "router == expo-router",
49
+ "how": "app.json/app.config expo.extra.router.root if set, else src/app when it exists, else app"
50
+ },
51
+ {
52
+ "id": "entry",
53
+ "how": "package.json \"main\" (index.js, expo-router/entry, …); bundle path = main with .js/.ts dropped + \".bundle\""
54
+ },
55
+ {
56
+ "id": "rootComponent",
57
+ "how": "expo-router: {{routerRoot}}/_layout.tsx; if it only re-exports (`export { X as default } from …`), follow it to the file that renders the tree. Otherwise the component passed to registerRootComponent / AppRegistry (App.tsx)."
58
+ },
59
+ {
60
+ "id": "providers",
61
+ "how": "Outermost wrappers returned by rootComponent (GestureHandlerRootView, SafeAreaProvider, ThemeProvider, …), outermost first"
62
+ },
63
+ {
64
+ "id": "scheme",
65
+ "how": "expo.scheme in app.json / app.config.*; with per-variant schemes use the one the current build uses (CFBundleURLSchemes in the dev client)"
66
+ },
67
+ {
68
+ "id": "auth",
69
+ "how": "Where the app learns the signed-in user: onAuthStateChange / auth listener, session hook, or the sign-in success handler; also its sign-out path",
70
+ "optional": true
71
+ },
72
+ {
73
+ "id": "push",
74
+ "how": "Call to Notifications.getExpoPushTokenAsync / getDevicePushTokenAsync / messaging().getToken()",
75
+ "optional": true
76
+ },
77
+ {
78
+ "id": "helpEntry",
79
+ "how": "Every existing contact row on settings/profile screens (grep mailto:, \"Contact\", \"Write to us\", \"Help\", \"Support\"), else the list a new row belongs in"
80
+ },
81
+ {
82
+ "id": "typecheck",
83
+ "how": "package.json scripts.typecheck → \"<pm> run typecheck\"; else \"npx tsc --noEmit\" when tsconfig.json exists"
84
+ },
85
+ {
86
+ "id": "brand",
87
+ "how": "The app's primary/accent color, base corner radius and font family from its theme (tokens, tailwind config, constants/colors); omit what you cannot find",
88
+ "optional": true
89
+ },
90
+ {
91
+ "id": "attachPeers",
92
+ "how": "Which of expo-image-picker / react-native-view-shot are already in dependencies",
93
+ "result": "list, possibly empty"
94
+ },
95
+ {
96
+ "id": "i18n",
97
+ "how": "The app's languages (locales/, i18n config); the widget ships en and ru and follows the device locale",
98
+ "optional": true
99
+ }
100
+ ],
101
+ "steps": [
102
+ {
103
+ "id": "dependency",
104
+ "title": "Add the package",
105
+ "edits": [
106
+ {
107
+ "op": "json-set",
108
+ "file": "package.json",
109
+ "path": [
110
+ "dependencies",
111
+ "@shotik/react-native"
112
+ ],
113
+ "value": "^0.1.0"
114
+ }
115
+ ],
116
+ "run": {
117
+ "bun": "bun install",
118
+ "pnpm": "pnpm install",
119
+ "yarn": "yarn install",
120
+ "npm": "npm install"
121
+ },
122
+ "done": "test -f node_modules/@shotik/react-native/package.json",
123
+ "migrate": "When detect.legacy is true: delete dependencies[\"@shotik/support-react-native\"] and the vendor/shotik-support-react-native folder, and change every import from '@shotik/react-native' to '@shotik/react-native' (same exports, same subpaths).",
124
+ "note": "Installs from npm (npmjs.com/package/@shotik/react-native). No native code, so no pod install or dev-client rebuild."
125
+ },
126
+ {
127
+ "id": "provider",
128
+ "title": "Wrap the root with the provider",
129
+ "file": "{{detect.rootComponent}}",
130
+ "edits": [
131
+ {
132
+ "op": "add-import",
133
+ "code": "import { ShotikSupportProvider } from '@shotik/react-native';"
134
+ },
135
+ {
136
+ "op": "wrap-jsx",
137
+ "target": "The children of the outermost element in detect.providers (inside GestureHandlerRootView / SafeAreaProvider), or the whole returned tree when there is none",
138
+ "open": "<ShotikSupportProvider appKey=\"{{APP_KEY}}\" serverUrl=\"{{SERVER_URL}}\"{{brandProps}}>",
139
+ "close": "</ShotikSupportProvider>"
140
+ }
141
+ ],
142
+ "done": "grep -q ShotikSupportProvider {{detect.rootComponent}}",
143
+ "note": "brandProps: add theme={{ accent: '<detect.brand color>', radius: <detect.brand radius>, font: '<detect.brand font>' }} with only the values found; title=\"<app name>\"; add launcher only if the app has no Help/Contact row. Never pass locale unless the app forces a language in-app (then pass its current language)."
144
+ },
145
+ {
146
+ "id": "route",
147
+ "title": "Deep link <scheme>://support",
148
+ "when": "router == expo-router",
149
+ "edits": [
150
+ {
151
+ "op": "create",
152
+ "file": "{{detect.routerRoot}}/support.tsx",
153
+ "code": "export { SupportRoute as default } from '@shotik/react-native';\n"
154
+ }
155
+ ],
156
+ "otherwise": "React Navigation: map a linking path \"support\" to a screen that renders <SupportRoute />; no router: call ShotikSupport.open() from the Linking handler for that URL",
157
+ "done": "test -f {{detect.routerRoot}}/support.tsx"
158
+ },
159
+ {
160
+ "id": "help",
161
+ "title": "Help entry opens the chat",
162
+ "file": "{{detect.helpEntry}}",
163
+ "edits": [
164
+ {
165
+ "op": "add-import",
166
+ "code": "import { ShotikSupport } from '@shotik/react-native';"
167
+ },
168
+ {
169
+ "op": "set-handler",
170
+ "target": "Each contact row's onPress (replace the mailto / web form call), else a new row labelled Help built with the screen's own row component and the app's i18n",
171
+ "code": "ShotikSupport.open()"
172
+ }
173
+ ],
174
+ "done": "grep -rq 'ShotikSupport.open(' {{detect.helpEntry}}"
175
+ },
176
+ {
177
+ "id": "identify",
178
+ "title": "Identify after the app's own sign-in",
179
+ "when": "detect.auth found",
180
+ "file": "{{detect.auth}}",
181
+ "edits": [
182
+ {
183
+ "op": "add-import",
184
+ "code": "import { ShotikSupport } from '@shotik/react-native';"
185
+ },
186
+ {
187
+ "op": "insert-after",
188
+ "anchor": "the point where a signed-in user (id, email, name) is known",
189
+ "code": "ShotikSupport.identify({ userId: user.id, email: user.email ?? undefined, name: user.name ?? undefined });"
190
+ },
191
+ {
192
+ "op": "insert-after",
193
+ "anchor": "the sign-out path",
194
+ "code": "ShotikSupport.reset();"
195
+ }
196
+ ],
197
+ "note": "Safe at module scope: calls before the provider mounts are held. Anonymous users are identified automatically and keep their chats after sign-in."
198
+ },
199
+ {
200
+ "id": "push",
201
+ "title": "Forward the push token",
202
+ "when": "detect.push found",
203
+ "file": "{{detect.push}}",
204
+ "edits": [
205
+ {
206
+ "op": "add-import",
207
+ "code": "import { ShotikSupport } from '@shotik/react-native';"
208
+ },
209
+ {
210
+ "op": "add-import",
211
+ "code": "import { Platform } from 'react-native';",
212
+ "unless": "Platform is already imported"
213
+ },
214
+ {
215
+ "op": "insert-after",
216
+ "anchor": "the line that obtains the token (e.g. const { data: token } = await Notifications.getExpoPushTokenAsync(…))",
217
+ "code": "ShotikSupport.setPushToken(token, Platform.OS).catch(() => {});"
218
+ }
219
+ ]
220
+ },
221
+ {
222
+ "id": "attachments",
223
+ "title": "Photos and screenshots",
224
+ "when": "detect.attachPeers is not empty",
225
+ "edits": [],
226
+ "note": "Nothing to edit: the attach button appears for the installed peers. Never install expo-image-picker or react-native-view-shot yourself: both need a native rebuild; tell the founder instead."
227
+ }
228
+ ],
229
+ "verify": [
230
+ {
231
+ "id": "wired",
232
+ "run": "grep -rlE 'ShotikSupportProvider|ShotikSupport\\.(open|identify|setPushToken)' --include=*.ts --include=*.tsx --exclude-dir=node_modules --exclude-dir=vendor .",
233
+ "expect": "lists the root component and the help entry"
234
+ },
235
+ {
236
+ "id": "typecheck",
237
+ "run": "{{detect.typecheck}}",
238
+ "expect": "exit 0, or no new errors in the files this recipe touched"
239
+ },
240
+ {
241
+ "id": "server",
242
+ "run": "curl -sf {{SERVER_URL}}/health",
243
+ "expect": "\"ok\":true"
244
+ },
245
+ {
246
+ "id": "key",
247
+ "run": "curl -s -o /dev/null -w '%{http_code}' -X POST -H 'x-shotik-key: {{APP_KEY}}' -H 'content-type: application/json' -d '{}' {{SERVER_URL}}/support/v1/identify",
248
+ "expect": "400 (key known, empty body refused); 401 means a wrong key"
249
+ },
250
+ {
251
+ "id": "bundle",
252
+ "run": "curl -sf 'http://127.0.0.1:{{METRO_PORT}}/{{detect.entry}}.bundle?platform=ios&dev=true' | grep -c '/support/v1/identify'",
253
+ "expect": "≥ 1",
254
+ "needs": "Metro running: npx expo start --dev-client --port {{METRO_PORT}}"
255
+ },
256
+ {
257
+ "id": "device",
258
+ "run": "xcrun simctl openurl booted '{{detect.scheme}}://support'",
259
+ "expect": "The Support sheet opens; a sent message shows in Shotik → Support",
260
+ "manual": true
261
+ }
262
+ ]
263
+ }
@@ -0,0 +1,32 @@
1
+ # Shotik analytics for React Native and Expo
2
+
3
+ See how people really use your app (what they tap, where they get stuck, which screens they come back to) and get facts with a proposed fix in Shotik → Insights. There's no native code: it works in any Expo dev client, and it adds about 16 KB of minified JS.
4
+
5
+ ```tsx
6
+ import { ShotikAnalytics, ShotikAnalyticsRoot, ShotikMask, useShotikExpoRouter } from '@shotik/react-native/analytics'
7
+
8
+ ShotikAnalytics.init({ appKey: 'spk_…', serverUrl: 'https://…' }) // the same key as Support
9
+ ShotikAnalytics.trackRevenueCat(Purchases) // optional: purchase start / done / cancel / fail
10
+
11
+ export default function RootLayout() {
12
+ useShotikExpoRouter() // React Navigation: ShotikAnalytics.trackNavigation(ref)
13
+ return <ShotikAnalyticsRoot>{/* your providers and <Stack /> */}</ShotikAnalyticsRoot>
14
+ }
15
+
16
+ ShotikAnalytics.track('walk_started', { minutes: 10 }) // your own events (no personal data)
17
+ ShotikAnalytics.identify(user.id) // after sign-in; ShotikAnalytics.reset() on sign-out
18
+ ```
19
+
20
+ **What it captures on its own:** sessions, app open and close, screens (route patterns, never params), time on screen and scroll depth, taps with the element and position (for heatmaps), rage taps and taps that do nothing, JS errors and crashes, slow screens and JS stalls, purchases (RevenueCat) and, for 20% of sessions, wireframes of each screen.
21
+
22
+ **Privacy by default:**
23
+ - It never reads text input values.
24
+ - Tap labels keep only short control text, with digits and emails masked.
25
+ - Wireframes are on for 20% of sessions by default (`snapshots: 0.2`; `snapshots: 0` turns them off). They hold boxes only (kind and position), draw text as bars with no characters, and contain no images.
26
+ - `<ShotikMask>` hides a view from both.
27
+ - `init({ consent: 'pending' })` keeps events on the device until `ShotikAnalytics.setConsent('granted')`. `optOut()` drops them.
28
+ - The server deletes an install's data on `POST /analytics/v1/forget`.
29
+
30
+ **Footprint:** a single capture-phase touch listener, a 500 ms stall timer, and batched uploads (up to 300 events every 10 s and on background). Batches are dictionary-packed, and the queue persists offline. Nothing runs on the touch path except an O(depth) walk up the tree.
31
+
32
+ **For agents:** recipe.json in this folder is the machine-readable integration that Shotik's coding chats follow.