@shotik/mcp 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +40 -2
- package/README.ru.md +40 -0
- package/data/PROTOCOL.md +386 -0
- package/data/flutter/INTEGRATION.md +197 -0
- package/data/flutter/README.md +112 -0
- package/data/flutter/README.ru.md +165 -0
- package/data/flutter/guide.json +190 -0
- package/data/flutter/recipe.json +364 -0
- package/data/react-native/README.md +194 -0
- package/data/react-native/README.ru.md +192 -0
- package/data/react-native/guide.json +136 -0
- package/data/react-native/recipe.json +263 -0
- package/data/react-native/src/analytics/README.md +32 -0
- package/data/react-native/src/analytics/recipe.json +263 -0
- package/data/storecheck/packs/ai.json +1 -0
- package/data/storecheck/packs/dating.json +1 -0
- package/data/storecheck/packs/education.json +1 -0
- package/data/storecheck/packs/finance.json +1 -0
- package/data/storecheck/packs/fitness.json +1 -0
- package/data/storecheck/packs/health.json +1 -0
- package/data/storecheck/packs/kids.json +1 -0
- package/data/storecheck/packs/language.json +1 -0
- package/data/storecheck/packs/mindfulness.json +1 -0
- package/data/storecheck/packs/music.json +1 -0
- package/data/storecheck/packs/nutrition.json +1 -0
- package/data/storecheck/packs/photo-video.json +1 -0
- package/data/storecheck/packs/productivity.json +1 -0
- package/data/storecheck/packs/spirituality.json +1 -0
- package/data/storecheck/packs/taxonomy.json +1 -0
- package/data/storecheck/packs/utilities.json +1 -0
- package/data/storecheck/storecheck.browser.js +314 -0
- package/data/swift/README.md +327 -0
- package/data/swift/README.ru.md +333 -0
- package/data/swift/guide.json +189 -0
- package/data/swift/recipe.json +506 -0
- package/package.json +42 -4
- package/server.mjs +144 -0
- package/sources.json +86 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# @shotik/react-native
|
|
2
|
+
|
|
3
|
+
SDK Shotik для React Native и Expo: чат поддержки внутри приложения и продуктовая аналитика в одном пакете. English:
|
|
4
|
+
[README.md](README.md).
|
|
5
|
+
|
|
6
|
+
Поддержка — это чат внутри вашего приложения. Пользователь пишет из приложения, разговор попадает во входящие Support в
|
|
7
|
+
Shotik на вашем Mac, а отвечаете вы или ИИ. Ответы приходят вживую, а для тех, кто закрыл приложение, записываются
|
|
8
|
+
события, готовые к пушу.
|
|
9
|
+
|
|
10
|
+
- Чистый TypeScript без нативного кода: работает в любом Expo dev client и в bare RN без пересборки.
|
|
11
|
+
- Peer-зависимости: `react`, `react-native`. Если в приложении уже есть `expo-device`, `expo-application`,
|
|
12
|
+
`expo-localization` (контекст устройства) и `@react-native-async-storage/async-storage` или `expo-secure-store`
|
|
13
|
+
(хранилище), SDK ими пользуется. Без них — `Platform`, `Intl` и память.
|
|
14
|
+
- Анонимный пользователь получает сохраняемый id. После входа его чаты переходят к вошедшему пользователю.
|
|
15
|
+
- Отправка оптимистичная и встаёт в очередь без сети. Поток переподключается с паузами и догоняет пропущенное, когда
|
|
16
|
+
приложение возвращается на передний план.
|
|
17
|
+
- Нативный по ощущениям лист чата: ручка, пружинное открытие и закрытие, обход клавиатуры, по желанию плавающая кнопка
|
|
18
|
+
со счётчиком непрочитанного, статусы (отправляется, отправлено, доставлено, прочитано), индикатор набора, быстрые
|
|
19
|
+
ответы, «Позвать человека», фото и скриншоты, светлая и тёмная темы, Dynamic Type, VoiceOver и RTL. Тексты на
|
|
20
|
+
английском или русском, по языку устройства.
|
|
21
|
+
- Небольшой: около 44 КБ минифицированного кода на весь SDK (14 КБ в gzip). До первого открытия рисуется только
|
|
22
|
+
кнопка, а все анимации идут на нативном драйвере.
|
|
23
|
+
|
|
24
|
+
## 1. Установка
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
npx expo install @shotik/react-native # или: npm install / bun add / pnpm add / yarn add @shotik/react-native
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Раньше SDK лежал копией в `vendor/shotik-support-react-native`? Удалите эту зависимость и папку и замените импорты
|
|
31
|
+
`@shotik/support-react-native` на `@shotik/react-native`. Экспорты те же.
|
|
32
|
+
|
|
33
|
+
## 2. Оберните корень
|
|
34
|
+
|
|
35
|
+
Публичный ключ (`spk_…`) возьмите в Shotik → Support → SDK. Это публичный ключ приложения, его можно класть в бандл.
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
// app/_layout.tsx (Expo Router) или App.tsx
|
|
39
|
+
import { ShotikSupportProvider } from '@shotik/react-native'
|
|
40
|
+
|
|
41
|
+
export default function RootLayout() {
|
|
42
|
+
return (
|
|
43
|
+
<GestureHandlerRootView style={{ flex: 1 }}>
|
|
44
|
+
<ShotikSupportProvider appKey="spk_…" serverUrl="https://support.example.com">
|
|
45
|
+
<Stack />
|
|
46
|
+
</ShotikSupportProvider>
|
|
47
|
+
</GestureHandlerRootView>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Провайдер анонимно определяет пользователя, держит поток открытым, пока приложение на переднем плане, и рисует
|
|
53
|
+
`<SupportWidget/>` — нижний лист, который монтируется при первом открытии. С `widget={false}` вы ставите
|
|
54
|
+
`<SupportWidget/>` сами, пропсы те же.
|
|
55
|
+
|
|
56
|
+
### Фирменный вид
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
<ShotikSupportProvider
|
|
60
|
+
appKey="spk_…"
|
|
61
|
+
serverUrl="https://support.example.com"
|
|
62
|
+
launcher // плавающая кнопка со счётчиком (по умолчанию выкл.)
|
|
63
|
+
title="Walkito" // заголовок (по умолчанию "Support" / "Поддержка")
|
|
64
|
+
teamName="Rahim" // подпись над вашими ответами (по умолчанию "Team" / "Команда")
|
|
65
|
+
quickReplies={['Оплата', 'Сообщить об ошибке']} // чипы в новом разговоре
|
|
66
|
+
theme={{ accent: '#FF5A1F', radius: 18, font: 'Inter-Regular', fontBold: 'Inter-SemiBold' }}
|
|
67
|
+
locale="ru" // по умолчанию язык устройства; запасной — en
|
|
68
|
+
>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
| `theme` | По умолчанию | |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| `accent` | синий iOS | Ваши пузыри, кнопка отправки, плавающая кнопка, ссылки |
|
|
74
|
+
| `onAccent` | `#FFFFFF` | Текст и значки на акцентном цвете |
|
|
75
|
+
| `radius` | `18` | Скругление пузырей; лист, чипы и поле следуют за ним |
|
|
76
|
+
| `font`, `fontBold` | системный | `fontFamily` для обычного и полужирного текста |
|
|
77
|
+
| `scheme` | системная | Принудительно `'light'` или `'dark'` |
|
|
78
|
+
| `light`, `dark` | | Свои цвета: `bg raised line text sub faint danger ok warn backdrop` |
|
|
79
|
+
|
|
80
|
+
### Вложения (необязательно)
|
|
81
|
+
|
|
82
|
+
Кнопка вложения появляется, только если в приложении уже есть один из пакетов (обоим нужна нативная сборка, поэтому SDK
|
|
83
|
+
сам их не добавляет):
|
|
84
|
+
|
|
85
|
+
- `expo-image-picker`: фото из галереи.
|
|
86
|
+
- `react-native-view-shot`: скриншот приложения (лист на это время отходит в сторону).
|
|
87
|
+
|
|
88
|
+
Картинки загружаются на сервер Shotik (до 8 МБ) и видны во входящих Shotik.
|
|
89
|
+
|
|
90
|
+
### Иконки (необязательно)
|
|
91
|
+
|
|
92
|
+
С `react-native-svg` (в Expo-приложениях он обычно есть) виджет рисует иконки из набора Hugeicons. Без него — простые
|
|
93
|
+
встроенные формы.
|
|
94
|
+
|
|
95
|
+
## 3. Откройте чат
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
import { ShotikSupport } from '@shotik/react-native'
|
|
99
|
+
|
|
100
|
+
<Row label="Помощь" onPress={() => ShotikSupport.open()} />
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Диплинк (и тап по пушу): в Expo Router добавьте `app/support.tsx`:
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
export { SupportRoute as default } from '@shotik/react-native'
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Тогда `myapp://support` открывает чат поверх текущего экрана.
|
|
110
|
+
|
|
111
|
+
## 4. Пользователь после входа
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
ShotikSupport.identify({ userId: user.id, email: user.email, name: user.name, attributes: { plan: 'pro' } })
|
|
115
|
+
// выход
|
|
116
|
+
ShotikSupport.reset()
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Вызывать можно где угодно, даже на уровне модуля до монтирования провайдера: вызовы до `configure` ждут его.
|
|
120
|
+
Каждый identify отправляет контекст устройства: платформу, версию ОС, модель, версию и сборку приложения, язык и
|
|
121
|
+
часовой пояс.
|
|
122
|
+
|
|
123
|
+
## 5. Пуши
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
const { data: token } = await Notifications.getExpoPushTokenAsync({ projectId })
|
|
127
|
+
ShotikSupport.setPushToken(token, Platform.OS)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Каждый ответ ваш или ИИ записывается как событие для пуша (`GET /v1/support/events`) с токеном пользователя и
|
|
131
|
+
превью. Ответ, уже доставленный по живому потоку, помечается доставленным.
|
|
132
|
+
|
|
133
|
+
## Хук и API
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
const { conversations, messages, unread, unreadBy, typing, status, open, send, retry, handoff, select, close } = useSupport()
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
| | |
|
|
140
|
+
|---|---|
|
|
141
|
+
| `ShotikSupport.configure({ appKey, serverUrl })` | Делает провайдер, когда получает пропсы. Вызовите сами, чтобы пользоваться хуком без пропсов провайдера. |
|
|
142
|
+
| `identify(user?)`, `reset()` | Вошедший пользователь / выход (новый анонимный id). |
|
|
143
|
+
| `setPushToken(token, platform?)` | Токен Expo или APNs/FCM; `null` очищает. |
|
|
144
|
+
| `open(conversationId?)`, `close()` | Показать или скрыть лист. |
|
|
145
|
+
| `status` | `idle · identifying · connecting · live · offline · error` |
|
|
146
|
+
| `send(body, conversationId?, attachments?)` | Оптимистично. Без id начинает новый разговор. `attachments`: `[{ uri, type?, width?, height? }]` (file:// или data:). Возвращает локальное сообщение. |
|
|
147
|
+
| `retry(localId)` | Повторить сообщение с `pending: 'failed'`. |
|
|
148
|
+
| `handoff(conversationId)` | «Позвать человека»: разговор уходит в список Needs human, ИИ перестаёт отвечать. |
|
|
149
|
+
| `typing` | `{ [conversationId]: 'ai' \| 'founder' }`, пока ИИ пишет черновик или вы печатаете в Shotik. |
|
|
150
|
+
| `receiptOf(message, list, conversation, offline?)` | `sending · queued · failed · sent · delivered · seen` для ваших сообщений. Доставлено = дошло до Shotik; прочитано = вы открыли его там. |
|
|
151
|
+
| `SupportClient` (`@shotik/react-native/client`) | Ядро без привязки к платформе, работает и вне React. |
|
|
152
|
+
|
|
153
|
+
## Аналитика
|
|
154
|
+
|
|
155
|
+
В том же пакете есть аналитика: `@shotik/react-native/analytics`, с тем же ключом.
|
|
156
|
+
|
|
157
|
+
```tsx
|
|
158
|
+
import { ShotikAnalytics, ShotikAnalyticsRoot, useShotikExpoRouter } from '@shotik/react-native/analytics'
|
|
159
|
+
|
|
160
|
+
ShotikAnalytics.init({ appKey: 'spk_…', serverUrl: 'https://…' })
|
|
161
|
+
|
|
162
|
+
export default function RootLayout() {
|
|
163
|
+
useShotikExpoRouter()
|
|
164
|
+
return <ShotikAnalyticsRoot>{/* ваши провайдеры и <Stack /> */}</ShotikAnalyticsRoot>
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Сама собирает сессии, экраны (шаблоны маршрутов, без параметров), тапы, rage-тапы, ошибки, медленные экраны, покупки
|
|
169
|
+
RevenueCat и для 20% сессий вайрфреймы экранов (`snapshots: 0.2`; `snapshots: 0` выключает). Вайрфреймы — только
|
|
170
|
+
прямоугольники без символов текста и без картинок. Значения полей ввода не читаются никогда, `<ShotikMask>` скрывает
|
|
171
|
+
вид целиком, а `init({ consent: 'pending' })` держит события на устройстве до согласия. Подробности —
|
|
172
|
+
[src/analytics/README.md](src/analytics/README.md).
|
|
173
|
+
|
|
174
|
+
## Если что-то не так
|
|
175
|
+
|
|
176
|
+
- **Статус остаётся `offline`.** Телефон не достаёт до `serverUrl`. Симулятор видит Mac по `http://127.0.0.1:<порт>`,
|
|
177
|
+
а устройству нужен адрес Mac в локальной сети (`http://192.168.x.x:<порт>`) или HTTPS. Проверьте
|
|
178
|
+
`curl <serverUrl>/health`.
|
|
179
|
+
- **Статус `error` и «unknown app key».** Ключ не от этого сервера. Создайте его заново в Shotik.
|
|
180
|
+
- **Обычный `http://` блокируется на устройстве.** App Transport Security в релизе пускает только HTTPS. Используйте
|
|
181
|
+
HTTPS или исключение ATS только для разработки.
|
|
182
|
+
- **Ничего не сохраняется между запусками.** Поставьте `expo-secure-store` или
|
|
183
|
+
`@react-native-async-storage/async-storage`. Без них анонимный id сбрасывается при каждом запуске.
|
|
184
|
+
- **TypeScript не находит типы.** Они лежат в `dist/` и подключаются через `exports`. Нужен
|
|
185
|
+
`moduleResolution: "bundler"` (по умолчанию в Expo). Metro читает исходники TypeScript из `src/`.
|
|
186
|
+
- **`myapp://support` показывает «not found».** Нет файла маршрута или корень роутера — `src/app`. Положите
|
|
187
|
+
`support.tsx` рядом с корневым `_layout.tsx`.
|
|
188
|
+
- **Сообщения висят в «Отправляется».** Без сети, а также пока сервер недоступен или отвечает 5xx/429, под ними
|
|
189
|
+
«Отправим, когда появится связь» (часы), а шапка показывает их число; уйдут сами, когда сервер станет доступен.
|
|
190
|
+
«Не отправлено · Повторить» появляется только при ответе 4xx.
|
|
191
|
+
- **Нет кнопки вложения.** В dev client нет ни `expo-image-picker`, ни `react-native-view-shot`. Поставьте один и
|
|
192
|
+
пересоберите dev client.
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema": "shotik.guide/1",
|
|
3
|
+
"sdk": "@shotik/react-native",
|
|
4
|
+
"variables": [
|
|
5
|
+
"APP_KEY",
|
|
6
|
+
"SERVER_URL"
|
|
7
|
+
],
|
|
8
|
+
"steps": [
|
|
9
|
+
{
|
|
10
|
+
"id": "install",
|
|
11
|
+
"title": "Add the SDK",
|
|
12
|
+
"body": "From npm. No native code: works in your current dev client, no rebuild.",
|
|
13
|
+
"code": {
|
|
14
|
+
"lang": "sh",
|
|
15
|
+
"file": "terminal",
|
|
16
|
+
"snippet": "npx expo install @shotik/react-native # or: npm install @shotik/react-native"
|
|
17
|
+
},
|
|
18
|
+
"check": {
|
|
19
|
+
"kind": "dependency",
|
|
20
|
+
"value": "@shotik/react-native"
|
|
21
|
+
},
|
|
22
|
+
"title_ru": "Добавьте SDK",
|
|
23
|
+
"body_ru": "Из npm. Без нативного кода: работает в текущем dev client, пересборка не нужна."
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"id": "provider",
|
|
27
|
+
"title": "Wrap your root",
|
|
28
|
+
"body": "Inside your outermost provider. It renders the chat sheet.",
|
|
29
|
+
"code": {
|
|
30
|
+
"lang": "tsx",
|
|
31
|
+
"file": "app/_layout.tsx",
|
|
32
|
+
"snippet": "import { ShotikSupportProvider } from '@shotik/react-native'\n\n<ShotikSupportProvider appKey=\"{{APP_KEY}}\" serverUrl=\"{{SERVER_URL}}\">\n <Stack />\n</ShotikSupportProvider>"
|
|
33
|
+
},
|
|
34
|
+
"check": {
|
|
35
|
+
"kind": "file-contains",
|
|
36
|
+
"value": "ShotikSupportProvider"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"id": "brand",
|
|
41
|
+
"title": "Match your brand",
|
|
42
|
+
"body": "Accent, radius and font. Light, dark and Russian come built in.",
|
|
43
|
+
"code": {
|
|
44
|
+
"lang": "tsx",
|
|
45
|
+
"file": "app/_layout.tsx",
|
|
46
|
+
"snippet": "<ShotikSupportProvider\n appKey=\"{{APP_KEY}}\"\n serverUrl=\"{{SERVER_URL}}\"\n launcher\n theme={{ accent: '#FF5A1F', radius: 18 }}\n quickReplies={['Billing', 'Report a bug']}\n>"
|
|
47
|
+
},
|
|
48
|
+
"check": {
|
|
49
|
+
"kind": "file-contains",
|
|
50
|
+
"value": "theme={{"
|
|
51
|
+
},
|
|
52
|
+
"optional": true
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"id": "attachments",
|
|
56
|
+
"title": "Photos and screenshots",
|
|
57
|
+
"body": "Shows the attach button when one is installed. Needs a dev client rebuild.",
|
|
58
|
+
"code": {
|
|
59
|
+
"lang": "sh",
|
|
60
|
+
"file": "terminal",
|
|
61
|
+
"snippet": "npx expo install expo-image-picker react-native-view-shot"
|
|
62
|
+
},
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"id": "help",
|
|
67
|
+
"title": "Open from Help",
|
|
68
|
+
"body": "Point your Help or Contact row at the chat.",
|
|
69
|
+
"code": {
|
|
70
|
+
"lang": "tsx",
|
|
71
|
+
"file": "settings screen",
|
|
72
|
+
"snippet": "import { ShotikSupport } from '@shotik/react-native'\n\n<Row label=\"Help\" onPress={() => ShotikSupport.open()} />"
|
|
73
|
+
},
|
|
74
|
+
"check": {
|
|
75
|
+
"kind": "file-contains",
|
|
76
|
+
"value": "ShotikSupport.open("
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"id": "route",
|
|
81
|
+
"title": "Deep link",
|
|
82
|
+
"body": "myapp://support opens the chat (push taps too).",
|
|
83
|
+
"code": {
|
|
84
|
+
"lang": "tsx",
|
|
85
|
+
"file": "app/support.tsx",
|
|
86
|
+
"snippet": "export { SupportRoute as default } from '@shotik/react-native'"
|
|
87
|
+
},
|
|
88
|
+
"check": {
|
|
89
|
+
"kind": "file-exists",
|
|
90
|
+
"value": "app/support.tsx"
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"id": "identify",
|
|
95
|
+
"title": "Identify after sign-in",
|
|
96
|
+
"body": "Anonymous chats move to the user.",
|
|
97
|
+
"code": {
|
|
98
|
+
"lang": "ts",
|
|
99
|
+
"file": "auth listener",
|
|
100
|
+
"snippet": "ShotikSupport.identify({ userId: user.id, email: user.email, name: user.name })\n// on sign-out\nShotikSupport.reset()"
|
|
101
|
+
},
|
|
102
|
+
"check": {
|
|
103
|
+
"kind": "file-contains",
|
|
104
|
+
"value": "ShotikSupport.identify("
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"id": "push",
|
|
109
|
+
"title": "Forward the push token",
|
|
110
|
+
"body": "Replies reach users who closed the app.",
|
|
111
|
+
"code": {
|
|
112
|
+
"lang": "ts",
|
|
113
|
+
"file": "notifications",
|
|
114
|
+
"snippet": "const { data: token } = await Notifications.getExpoPushTokenAsync({ projectId })\nShotikSupport.setPushToken(token, Platform.OS)"
|
|
115
|
+
},
|
|
116
|
+
"check": {
|
|
117
|
+
"kind": "push-token",
|
|
118
|
+
"value": "any user of this app"
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"id": "test",
|
|
123
|
+
"title": "Send a test message",
|
|
124
|
+
"body": "Open Help in the app and say hi.",
|
|
125
|
+
"code": {
|
|
126
|
+
"lang": "sh",
|
|
127
|
+
"file": "terminal",
|
|
128
|
+
"snippet": "xcrun simctl openurl booted \"myapp://support\""
|
|
129
|
+
},
|
|
130
|
+
"check": {
|
|
131
|
+
"kind": "first-message",
|
|
132
|
+
"value": "a conversation from this app"
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
}
|
|
@@ -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.
|