@shotik/mcp 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/LICENSE +21 -0
- package/README.md +38 -2
- package/README.ru.md +38 -0
- package/data/PROTOCOL.md +381 -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 +347 -0
- package/data/react-native/README.md +193 -0
- package/data/react-native/README.ru.md +191 -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/swift/README.md +326 -0
- package/data/swift/README.ru.md +332 -0
- package/data/swift/guide.json +189 -0
- package/data/swift/recipe.json +468 -0
- package/package.json +42 -4
- package/server.mjs +123 -0
- package/sources.json +85 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema": "shotik.recipe/1",
|
|
3
|
+
"id": "analytics-react-native",
|
|
4
|
+
"title": "Shotik analytics in a React Native / Expo app",
|
|
5
|
+
"package": "@shotik/react-native/analytics",
|
|
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
|
+
"Privacy: never pass text input values, emails, names or tokens in track() props. Wrap any view showing personal data (names, health numbers, messages) in <ShotikMask>.",
|
|
11
|
+
"Analytics must not change behavior or look: no new UI, no new screens. If something here would, stop and ask."
|
|
12
|
+
],
|
|
13
|
+
"variables": {
|
|
14
|
+
"APP_KEY": {
|
|
15
|
+
"required": true,
|
|
16
|
+
"desc": "Public SDK key from Shotik (Support → SDK), spk_…; the same key as Support, safe to ship"
|
|
17
|
+
},
|
|
18
|
+
"SERVER_URL": {
|
|
19
|
+
"required": true,
|
|
20
|
+
"desc": "Shotik server URL the phone can reach (simulator: http://127.0.0.1:4590)"
|
|
21
|
+
},
|
|
22
|
+
"SNAPSHOTS": {
|
|
23
|
+
"required": false,
|
|
24
|
+
"default": "0.2",
|
|
25
|
+
"desc": "Share of sessions that record privacy-safe wireframes (0..1)"
|
|
26
|
+
},
|
|
27
|
+
"METRO_PORT": {
|
|
28
|
+
"required": false,
|
|
29
|
+
"default": "8081",
|
|
30
|
+
"desc": "Port for the bundle check"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"detect": [
|
|
34
|
+
{
|
|
35
|
+
"id": "legacy",
|
|
36
|
+
"how": "package.json dependencies has \"@shotik/support-react-native\" (an older vendored copy, file:./vendor/…) → true",
|
|
37
|
+
"result": "true | false"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"id": "installed",
|
|
41
|
+
"how": "package.json dependencies has \"@shotik/react-native\" (Support already integrated) → true"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"id": "packageManager",
|
|
45
|
+
"how": "bun.lock or bun.lockb → bun; pnpm-lock.yaml → pnpm; yarn.lock → yarn; else npm"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"id": "router",
|
|
49
|
+
"how": "\"expo-router\" in dependencies → expo-router; \"@react-navigation/native\" → react-navigation; else none"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"id": "rootComponent",
|
|
53
|
+
"how": "expo-router: the root _layout.tsx; if it only re-exports, follow it to the file that renders the tree. Otherwise the component passed to registerRootComponent / AppRegistry."
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"id": "providers",
|
|
57
|
+
"how": "Outermost wrappers returned by rootComponent (GestureHandlerRootView, SafeAreaProvider, ShotikSupportProvider, …), outermost first"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"id": "navigationRef",
|
|
61
|
+
"when": "router == react-navigation",
|
|
62
|
+
"how": "The ref passed to <NavigationContainer ref=…>, or none"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"id": "purchases",
|
|
66
|
+
"how": "\"react-native-purchases\" in dependencies → the module where Purchases.configure(...) is called",
|
|
67
|
+
"optional": true
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"id": "auth",
|
|
71
|
+
"how": "Where the app learns the signed-in user and its sign-out path",
|
|
72
|
+
"optional": true
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"id": "keyActions",
|
|
76
|
+
"how": "Up to 5 core user actions worth naming (e.g. start a workout, finish a lesson, share): the handler where each completes",
|
|
77
|
+
"optional": true
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"id": "sensitive",
|
|
81
|
+
"how": "Views that render personal data (user name, email, health values, private messages)",
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"id": "typecheck",
|
|
86
|
+
"how": "package.json scripts.typecheck → \"<pm> run typecheck\"; else \"npx tsc --noEmit\" when tsconfig.json exists"
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
"steps": [
|
|
90
|
+
{
|
|
91
|
+
"id": "dependency",
|
|
92
|
+
"title": "Add the package",
|
|
93
|
+
"edits": [
|
|
94
|
+
{
|
|
95
|
+
"op": "json-set",
|
|
96
|
+
"file": "package.json",
|
|
97
|
+
"path": [
|
|
98
|
+
"dependencies",
|
|
99
|
+
"@shotik/react-native"
|
|
100
|
+
],
|
|
101
|
+
"value": "^0.1.0"
|
|
102
|
+
}
|
|
103
|
+
],
|
|
104
|
+
"run": {
|
|
105
|
+
"bun": "bun install",
|
|
106
|
+
"pnpm": "pnpm install",
|
|
107
|
+
"yarn": "yarn install",
|
|
108
|
+
"npm": "npm install"
|
|
109
|
+
},
|
|
110
|
+
"note": "One package for Support and Analytics: when detect.installed is true this step is already done.",
|
|
111
|
+
"done": "test -f node_modules/@shotik/react-native/dist/analytics/index.js",
|
|
112
|
+
"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/support-react-native' to '@shotik/react-native' (same exports, same subpaths)."
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"id": "init",
|
|
116
|
+
"title": "Start analytics once, at module scope of the root",
|
|
117
|
+
"file": "{{detect.rootComponent}}",
|
|
118
|
+
"edits": [
|
|
119
|
+
{
|
|
120
|
+
"op": "add-import",
|
|
121
|
+
"code": "import { ShotikAnalytics, ShotikAnalyticsRoot } from '@shotik/react-native/analytics';"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"op": "insert-after",
|
|
125
|
+
"anchor": "the imports",
|
|
126
|
+
"code": "ShotikAnalytics.init({ appKey: '{{APP_KEY}}', serverUrl: '{{SERVER_URL}}', snapshots: {{SNAPSHOTS}} });"
|
|
127
|
+
}
|
|
128
|
+
],
|
|
129
|
+
"done": "grep -q 'ShotikAnalytics.init' {{detect.rootComponent}}"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"id": "root",
|
|
133
|
+
"title": "Wrap the tree for taps and wireframes",
|
|
134
|
+
"file": "{{detect.rootComponent}}",
|
|
135
|
+
"edits": [
|
|
136
|
+
{
|
|
137
|
+
"op": "wrap-jsx",
|
|
138
|
+
"target": "The children of the outermost element in detect.providers (inside GestureHandlerRootView), or the whole returned tree when there is none",
|
|
139
|
+
"open": "<ShotikAnalyticsRoot>",
|
|
140
|
+
"close": "</ShotikAnalyticsRoot>"
|
|
141
|
+
}
|
|
142
|
+
],
|
|
143
|
+
"done": "grep -q '<ShotikAnalyticsRoot>' {{detect.rootComponent}}"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"id": "screens",
|
|
147
|
+
"title": "Screen tracking",
|
|
148
|
+
"edits": [
|
|
149
|
+
{
|
|
150
|
+
"op": "add-import",
|
|
151
|
+
"file": "{{detect.rootComponent}}",
|
|
152
|
+
"when": "router == expo-router",
|
|
153
|
+
"code": "import { useShotikExpoRouter } from '@shotik/react-native/analytics';"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"op": "insert-after",
|
|
157
|
+
"file": "{{detect.rootComponent}}",
|
|
158
|
+
"when": "router == expo-router",
|
|
159
|
+
"anchor": "the first line inside the root layout component body (a hook call at top level, before any early return)",
|
|
160
|
+
"code": "useShotikExpoRouter();"
|
|
161
|
+
}
|
|
162
|
+
],
|
|
163
|
+
"otherwise": "react-navigation: after the container is ready call ShotikAnalytics.trackNavigation(detect.navigationRef); no router: ShotikAnalytics.screen('<name>') in each screen's mount effect",
|
|
164
|
+
"done": "grep -rqE 'useShotikExpoRouter\\(|trackNavigation\\(' {{detect.rootComponent}}"
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"id": "purchases",
|
|
168
|
+
"title": "Purchase events",
|
|
169
|
+
"when": "detect.purchases found",
|
|
170
|
+
"file": "{{detect.purchases}}",
|
|
171
|
+
"edits": [
|
|
172
|
+
{
|
|
173
|
+
"op": "add-import",
|
|
174
|
+
"code": "import { ShotikAnalytics } from '@shotik/react-native/analytics';"
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
"op": "insert-after",
|
|
178
|
+
"anchor": "Purchases.configure(...)",
|
|
179
|
+
"code": "ShotikAnalytics.trackRevenueCat(Purchases as unknown as Record<string, unknown>);"
|
|
180
|
+
}
|
|
181
|
+
],
|
|
182
|
+
"done": "grep -q 'trackRevenueCat' {{detect.purchases}}"
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"id": "identify",
|
|
186
|
+
"title": "Identify after sign-in",
|
|
187
|
+
"when": "detect.auth found",
|
|
188
|
+
"file": "{{detect.auth}}",
|
|
189
|
+
"edits": [
|
|
190
|
+
{
|
|
191
|
+
"op": "add-import",
|
|
192
|
+
"code": "import { ShotikAnalytics } from '@shotik/react-native/analytics';"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"op": "insert-after",
|
|
196
|
+
"anchor": "the point where a signed-in user id is known",
|
|
197
|
+
"code": "ShotikAnalytics.identify(user.id);"
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
"op": "insert-after",
|
|
201
|
+
"anchor": "the sign-out path",
|
|
202
|
+
"code": "void ShotikAnalytics.reset();"
|
|
203
|
+
}
|
|
204
|
+
]
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
"id": "events",
|
|
208
|
+
"title": "Name the core actions",
|
|
209
|
+
"when": "detect.keyActions found",
|
|
210
|
+
"edits": [
|
|
211
|
+
{
|
|
212
|
+
"op": "insert-after",
|
|
213
|
+
"anchor": "where each key action completes",
|
|
214
|
+
"code": "ShotikAnalytics.track('<snake_case_action>', { <non-personal props, e.g. minutes: 10> });"
|
|
215
|
+
}
|
|
216
|
+
],
|
|
217
|
+
"note": "At most 5. Names are snake_case verbs (walk_started, plan_completed). No personal data in props."
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
"id": "mask",
|
|
221
|
+
"title": "Mask personal data",
|
|
222
|
+
"when": "detect.sensitive found",
|
|
223
|
+
"edits": [
|
|
224
|
+
{
|
|
225
|
+
"op": "wrap-jsx",
|
|
226
|
+
"target": "each view in detect.sensitive",
|
|
227
|
+
"open": "<ShotikMask>",
|
|
228
|
+
"close": "</ShotikMask>",
|
|
229
|
+
"import": "import { ShotikMask } from '@shotik/react-native/analytics';"
|
|
230
|
+
}
|
|
231
|
+
]
|
|
232
|
+
}
|
|
233
|
+
],
|
|
234
|
+
"verify": [
|
|
235
|
+
{
|
|
236
|
+
"id": "wired",
|
|
237
|
+
"run": "grep -rlE 'ShotikAnalytics\\.(init|track|trackRevenueCat)|ShotikAnalyticsRoot|useShotikExpoRouter' --include=*.ts --include=*.tsx --exclude-dir=node_modules --exclude-dir=vendor .",
|
|
238
|
+
"expect": "lists the root component (and the purchases/auth files when found)"
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
"id": "typecheck",
|
|
242
|
+
"run": "{{detect.typecheck}}",
|
|
243
|
+
"expect": "exit 0, or no new errors in the files this recipe touched"
|
|
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 '{\"anonymousId\":\"recipe-check\",\"events\":[]}' {{SERVER_URL}}/analytics/v1/events",
|
|
248
|
+
"expect": "200; 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 '/analytics/v1/events'",
|
|
253
|
+
"expect": "≥ 1",
|
|
254
|
+
"needs": "Metro running: npx expo start --dev-client --port {{METRO_PORT}}"
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
"id": "device",
|
|
258
|
+
"run": "open the app on the shared simulator (device broker) and tap through two screens",
|
|
259
|
+
"expect": "Shotik → Insights shows the app's users and sessions within a minute",
|
|
260
|
+
"manual": true
|
|
261
|
+
}
|
|
262
|
+
]
|
|
263
|
+
}
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
# Shotik SDK for Swift
|
|
2
|
+
|
|
3
|
+
In-app support chat and product analytics for iOS and macOS apps that talk to a Shotik server. Users write from your
|
|
4
|
+
app and the conversation lands in Shotik's Support inbox on your Mac, where you (or the AI) answer. Analytics records
|
|
5
|
+
screens, taps, scroll depth, stalls, crashes and purchases, and draws wireframes for the screens it sees.
|
|
6
|
+
|
|
7
|
+
- Four SwiftPM libraries, so an app links only what it uses: `ShotikCore` (configure, identity, storage, transport),
|
|
8
|
+
`ShotikSupport` (the chat client), `ShotikSupportUI` (the SwiftUI widget) and `ShotikAnalytics`.
|
|
9
|
+
- iOS 15+ and macOS 12+, Swift 6 with strict concurrency, zero dependencies. No fonts, images or third-party code.
|
|
10
|
+
- `configure` returns in well under a millisecond. Storage, network and JSON run on one background queue, so nothing
|
|
11
|
+
touches disk or the network on the main thread.
|
|
12
|
+
- Automatic capture with no swizzling: one passive gesture recognizer per window, scene notifications, a 500 ms main
|
|
13
|
+
queue watchdog and StoreKit 2 transactions.
|
|
14
|
+
- Wire, state and storage compatible with the React Native SDK (`PROTOCOL.md`). Both SDKs read the same keys, so the
|
|
15
|
+
same server accepts both.
|
|
16
|
+
- Privacy manifest included (`PrivacyInfo.xcprivacy`, shipped in ShotikCore). There's no IDFA and no fingerprinting.
|
|
17
|
+
|
|
18
|
+
## 1. Install
|
|
19
|
+
|
|
20
|
+
**Xcode project.** Go to File → Add Package Dependencies…, paste `https://github.com/rahimwws/shotik-app` into the search field, keep
|
|
21
|
+
"Up to Next Major Version" from `0.1.0`, then add the libraries you want to your app target. Most apps want
|
|
22
|
+
`ShotikAnalytics`, `ShotikSupport` and `ShotikSupportUI`.
|
|
23
|
+
|
|
24
|
+
**Swift package.** In your own `Package.swift`:
|
|
25
|
+
|
|
26
|
+
```swift
|
|
27
|
+
dependencies: [.package(url: "https://github.com/rahimwws/shotik-app", from: "0.1.0")],
|
|
28
|
+
targets: [.target(name: "App", dependencies: [
|
|
29
|
+
.product(name: "ShotikSupportUI", package: "shotik-app"),
|
|
30
|
+
.product(name: "ShotikAnalytics", package: "shotik-app"),
|
|
31
|
+
])]
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The package lives in the Shotik repo: its `Package.swift` sits at the repo root and builds `sdk/swift/Sources`.
|
|
35
|
+
Releases are the repo's bare semver tags (`0.1.0`).
|
|
36
|
+
|
|
37
|
+
| You link | You get |
|
|
38
|
+
|---|---|
|
|
39
|
+
| `ShotikAnalytics` | Analytics only (Core comes with it) |
|
|
40
|
+
| `ShotikSupport` | The chat client without UI, for a chat screen of your own |
|
|
41
|
+
| `ShotikSupportUI` | The widget (it pulls in Support) |
|
|
42
|
+
|
|
43
|
+
## 2. Configure
|
|
44
|
+
|
|
45
|
+
Get the public key (`spk_…`) from Shotik → Support → SDK. It is a public app key, so it is safe to ship in the app.
|
|
46
|
+
Call configure once, as early as possible. It starts every module you linked.
|
|
47
|
+
|
|
48
|
+
```swift
|
|
49
|
+
import ShotikCore
|
|
50
|
+
import ShotikSupportUI
|
|
51
|
+
import SwiftUI
|
|
52
|
+
|
|
53
|
+
@main
|
|
54
|
+
struct MyApp: App {
|
|
55
|
+
init() {
|
|
56
|
+
Shotik.configure(appKey: "spk_…", serverUrl: "https://support.example.com")
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
var body: some Scene {
|
|
60
|
+
WindowGroup {
|
|
61
|
+
RootView().shotikSupportSheet() // presents the widget on ShotikSupport.open() and myapp://support
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**UIKit apps** call configure in `application(_:didFinishLaunchingWithOptions:)` and install the widget once the
|
|
68
|
+
window exists:
|
|
69
|
+
|
|
70
|
+
```swift
|
|
71
|
+
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options: UIScene.ConnectionOptions) {
|
|
72
|
+
// … your window setup
|
|
73
|
+
ShotikSupportWidget.install() // presents the widget over the top view controller on open()
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`ShotikConfig` has more options: `Shotik.configure(ShotikConfig(appKey:serverUrl:consent:snapshots:flushMs:sessionTimeoutMs:autoCapture:debug:))`.
|
|
78
|
+
|
|
79
|
+
| Option | Default | |
|
|
80
|
+
|---|---|---|
|
|
81
|
+
| `consent` | the persisted choice, else `.granted` | Analytics consent, see 5.7 |
|
|
82
|
+
| `snapshots` | `0.2` | Share of sessions that record wireframes (0…1) |
|
|
83
|
+
| `flushMs` | `10000` | Analytics upload interval while active |
|
|
84
|
+
| `sessionTimeoutMs` | 30 min | Inactivity that starts a new session |
|
|
85
|
+
| `autoCapture` | `true` | Taps, screens, stalls, crashes, StoreKit. Manual calls work either way |
|
|
86
|
+
| `debug` | `false` | Prints every event to the console |
|
|
87
|
+
|
|
88
|
+
Every call made before `configure` (identify, push token, track) is held and replayed in order once it runs. Analytics
|
|
89
|
+
holds up to 500 calls.
|
|
90
|
+
|
|
91
|
+
## 3. Support
|
|
92
|
+
|
|
93
|
+
### Open it
|
|
94
|
+
|
|
95
|
+
```swift
|
|
96
|
+
import ShotikSupport
|
|
97
|
+
|
|
98
|
+
Button("Help") { ShotikSupport.open() }
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The widget is a system sheet with a conversation list, a thread, receipts (sending, sent, delivered, seen), a typing
|
|
102
|
+
indicator while the AI drafts or you type in Shotik, quick-reply chips, "Talk to a person", and photos and screenshots
|
|
103
|
+
as attachments. It supports light and dark, Dynamic Type, VoiceOver and RTL. Copy is English or Russian, picked from the
|
|
104
|
+
device locale. The widget's views are built on the first open, so nothing exists before then except the launcher.
|
|
105
|
+
|
|
106
|
+
Add `.shotikSupportLauncher()` to a view for a floating button with the unread badge. For a badge on your own Help row:
|
|
107
|
+
|
|
108
|
+
```swift
|
|
109
|
+
struct HelpBadge: View {
|
|
110
|
+
@StateObject private var badge = ShotikSupportBadge()
|
|
111
|
+
var body: some View { if badge.unread > 0 { Text("\(badge.unread)") } }
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Brand it
|
|
116
|
+
|
|
117
|
+
```swift
|
|
118
|
+
RootView().shotikSupportSheet(SupportWidgetOptions(
|
|
119
|
+
title: "Walkito", // header (default "Support" / "Поддержка")
|
|
120
|
+
teamName: "Rahim", // label above your replies (default "Team" / "Команда")
|
|
121
|
+
quickReplies: ["Billing", "Report a bug"], // chips on a new conversation
|
|
122
|
+
theme: SupportTheme(accent: "#FF5A1F", radius: 18, font: "Inter-Regular", fontBold: "Inter-SemiBold"),
|
|
123
|
+
locale: "ru" // default: the device locale; en is the fallback
|
|
124
|
+
))
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
| `SupportTheme` | Default | |
|
|
128
|
+
|---|---|---|
|
|
129
|
+
| `accent` | iOS blue | Your bubbles, the send button, the launcher, links |
|
|
130
|
+
| `onAccent` | `#FFFFFF` | Text and glyphs on the accent |
|
|
131
|
+
| `radius` | `18` | Bubble radius. The sheet, chips and field follow it |
|
|
132
|
+
| `font`, `fontBold` | system | Font names for regular and semibold text |
|
|
133
|
+
| `scheme` | system | Force `.light` or `.dark` |
|
|
134
|
+
| `light`, `dark` | | `ShotikColors` overrides: `bg raised line text sub faint danger ok warn backdrop` |
|
|
135
|
+
|
|
136
|
+
### Deep link
|
|
137
|
+
|
|
138
|
+
Add a URL scheme to your target (Info → URL Types, for example `myapp`). Then `myapp://support` opens the chat over
|
|
139
|
+
the current screen, from push taps too. `.shotikSupportSheet()` handles it through `onOpenURL`. If your app handles
|
|
140
|
+
URLs itself, pass `handleLinks: false` and call `ShotikSupport.handle(url:)` first in your handler (it returns
|
|
141
|
+
`true` when the URL was for Support). UIKit apps call it from `scene(_:openURLContexts:)`.
|
|
142
|
+
|
|
143
|
+
### Identify after sign-in
|
|
144
|
+
|
|
145
|
+
```swift
|
|
146
|
+
ShotikSupport.identify(userId: user.id, name: user.name, email: user.email, attributes: ["plan": "pro"])
|
|
147
|
+
ShotikAnalytics.identify(user.id, traits: ["plan": "pro"])
|
|
148
|
+
// sign-out: a new anonymous id for Support and Analytics
|
|
149
|
+
Shotik.reset()
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Anonymous users get a persisted id. When they sign in, their chats move to the signed-in user. Every identify sends the
|
|
153
|
+
device context: platform, OS version, model, app version and build, locale and time zone.
|
|
154
|
+
|
|
155
|
+
### Push
|
|
156
|
+
|
|
157
|
+
```swift
|
|
158
|
+
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
|
|
159
|
+
ShotikSupport.setPushToken(deviceToken: deviceToken)
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
SwiftUI apps get this callback through `@UIApplicationDelegateAdaptor`. Another provider's token string works too:
|
|
164
|
+
`ShotikSupport.setPushToken(token, platform: "ios")`, and `nil` clears it. Every founder or AI reply is recorded as a
|
|
165
|
+
push-ready event (`GET /v1/support/events`) with the user's token and a preview.
|
|
166
|
+
|
|
167
|
+
### Your own chat UI
|
|
168
|
+
|
|
169
|
+
Link only `ShotikSupport`. `ShotikSupport.observe { state in … }` delivers `SupportState` on the main queue
|
|
170
|
+
(conversations, messages, unread, typing, status). `send`, `retry`, `handoff`, `markRead` and `receiptOf` do the
|
|
171
|
+
rest. `SupportClient` is the platform-free core and is what the tests drive.
|
|
172
|
+
|
|
173
|
+
## 4. Support API
|
|
174
|
+
|
|
175
|
+
| | |
|
|
176
|
+
|---|---|
|
|
177
|
+
| `Shotik.configure(appKey:serverUrl:)` | Starts every linked module. `ShotikSupport.configure` and `ShotikAnalytics.configure` do the same |
|
|
178
|
+
| `ShotikSupport.identify(userId:name:email:attributes:)`, `Shotik.reset()` | Signed-in user, sign-out |
|
|
179
|
+
| `ShotikSupport.setPushToken(deviceToken:)`, `setPushToken(_:platform:)` | APNs token (as hex) or any token string; `nil` clears it |
|
|
180
|
+
| `ShotikSupport.open(_ conversationId:)`, `close()`, `select(_:)` | Show or hide the widget, pick a conversation |
|
|
181
|
+
| `ShotikSupport.state.status` | `idle · identifying · connecting · live · offline · error` |
|
|
182
|
+
| `ShotikSupport.send(_:conversationId:attachments:)` | Optimistic and queued while offline. Without an id it starts a new conversation |
|
|
183
|
+
| `ShotikSupport.retry(_ localId:)` | Resend a message marked `.failed` |
|
|
184
|
+
| `ShotikSupport.handoff(_:)` | "Talk to a person": the conversation goes to your Needs-human list and the AI stops answering it |
|
|
185
|
+
| `ShotikSupport.observe(_:)` | State on the main queue; the first call delivers the current state |
|
|
186
|
+
| `receiptOf(_:in:conversation:offline:)` | `sending · queued · failed · sent · delivered · seen` for the user's messages |
|
|
187
|
+
| `ShotikImage.attachment(from:)` | A JPEG `LocalAttachment` (max 2048 px) from image data, for your own picker |
|
|
188
|
+
|
|
189
|
+
## 5. Analytics
|
|
190
|
+
|
|
191
|
+
Linking `ShotikAnalytics` and calling `Shotik.configure` is all it takes. Events are batched and uploaded at most
|
|
192
|
+
once every 10 seconds while the app is active, and once more when it goes to the background. Uploads are retried
|
|
193
|
+
with backoff while offline, and the queue survives restarts.
|
|
194
|
+
|
|
195
|
+
### 5.1 What is captured automatically
|
|
196
|
+
|
|
197
|
+
| Signal | How |
|
|
198
|
+
|---|---|
|
|
199
|
+
| Sessions, open, close | Scene and application notifications. A new session starts after 30 minutes away |
|
|
200
|
+
| Screens and time on screen | The top view controller after each transition, named by `.shotikScreen()`, the navigation title, or the class |
|
|
201
|
+
| Taps, dead taps, rage taps | One passive gesture recognizer per window (`cancelsTouchesInView = false`, it never recognizes). On touch end it only queues the point, the time, the current screen and the `.shotikTag` under the finger; the element is resolved right after. **UIKit:** automatic, from the hit-test chain: the control's `accessibilityIdentifier` (sent as `id` and as `#id` on `el`), its label and class. **SwiftUI:** the tap, its position, screen and rage are automatic, but the element is only named where you add `.shotikTag` (see 5.3); without it the tap is `el: "View"` with no label and no id, and it is never called dead. Taps in the Support widget count on a "Support" screen |
|
|
202
|
+
| Scroll depth | Sampled from the scroll view under a drag when the finger lifts |
|
|
203
|
+
| Stalls, slow screens | A background watchdog pings the main queue every 500 ms |
|
|
204
|
+
| Crashes | `NSSetUncaughtExceptionHandler`, chained to the previous handler |
|
|
205
|
+
| Purchases | StoreKit 2 `Transaction.updates` and a scan of `Transaction.all` on foreground |
|
|
206
|
+
| Wireframes | A view hierarchy walk on the sampled sessions, encoded off the main thread |
|
|
207
|
+
|
|
208
|
+
**Limits of swizzle-free capture.** Scroll depth is sampled when a drag ends, so momentum after the finger lifts is not
|
|
209
|
+
counted, and programmatic scrolling is not tracked at all. Screens are checked after touches end and on scene
|
|
210
|
+
activation, so a screen pushed by code without a touch is named on the next touch. Use `.shotikScreen()` or
|
|
211
|
+
`ShotikAnalytics.screen` for exact names. Swift runtime traps (`fatalError`, force unwraps) are not Objective-C
|
|
212
|
+
exceptions, so they stay with your crash reporter.
|
|
213
|
+
|
|
214
|
+
### 5.2 Screen names
|
|
215
|
+
|
|
216
|
+
```swift
|
|
217
|
+
PaywallView().shotikScreen("Paywall") // SwiftUI; wins over automatic names
|
|
218
|
+
ShotikAnalytics.screen("Paywall") // anywhere
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### 5.3 Element ids in SwiftUI
|
|
222
|
+
|
|
223
|
+
SwiftUI keeps its accessibility tree empty unless VoiceOver, another assistive technology or UI-test automation is
|
|
224
|
+
running, and there is no public API to make it vend the elements. That's why PostHog asks for `.postHogLabel`, and why
|
|
225
|
+
Amplitude and PostHog autocapture element interactions only in UIKit. So SwiftUI tap targets get their id from a tag:
|
|
226
|
+
|
|
227
|
+
```swift
|
|
228
|
+
Button("Continue") { next() }
|
|
229
|
+
.shotikTag("continue", label: "Continue") // el "Tag#continue", id "continue", label "Continue"
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Tag your CTAs, paywall plans and buttons, onboarding steps and the Help row. The tag adds a passive background marker
|
|
233
|
+
(no hit testing, hidden from VoiceOver), and the frames are read at touch time, so scrolling, sheets and navigation need
|
|
234
|
+
nothing extra. When tags overlap, the one in the front-most layer wins (a sheet over the screen), then the smallest.
|
|
235
|
+
Labels are your own text, so never put personal data in them. `accessibilityIdentifier` alone isn't enough in SwiftUI:
|
|
236
|
+
it only reaches the SDK while an assistive technology is running.
|
|
237
|
+
|
|
238
|
+
### 5.4 Masking
|
|
239
|
+
|
|
240
|
+
Inputs never send their value. Taps on text fields and secure fields carry `input: 1` and no label, and wireframes draw
|
|
241
|
+
them as empty boxes. To hide anything else from tap labels and wireframes:
|
|
242
|
+
|
|
243
|
+
```swift
|
|
244
|
+
BalanceView().shotikMask() // SwiftUI
|
|
245
|
+
cardView.shotikMasked = true // UIKit
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### 5.5 Custom events
|
|
249
|
+
|
|
250
|
+
```swift
|
|
251
|
+
ShotikAnalytics.track("Plan selected", ["plan": "annual", "step": 3])
|
|
252
|
+
ShotikAnalytics.error(error) // a handled error, with the top stack frames
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Custom props are free-form. Never put personal data in them (names, emails, free text the user typed).
|
|
256
|
+
|
|
257
|
+
### 5.6 Purchases
|
|
258
|
+
|
|
259
|
+
Purchases made through StoreKit 2 are recorded without any code. To also record the start and the cancel, wrap the
|
|
260
|
+
purchase call:
|
|
261
|
+
|
|
262
|
+
```swift
|
|
263
|
+
let result = try await ShotikAnalytics.purchase(product: product) { try await product.purchase() }
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
For another store or RevenueCat, use `ShotikAnalytics.purchase(product: "pro.annual", status: .done, price: 49.99, currency: "USD")`.
|
|
267
|
+
|
|
268
|
+
### 5.7 Consent
|
|
269
|
+
|
|
270
|
+
```swift
|
|
271
|
+
Shotik.configure(ShotikConfig(appKey: "spk_…", serverUrl: url, consent: .pending)) // hold events on the device
|
|
272
|
+
ShotikAnalytics.optIn() // .granted: upload what was held
|
|
273
|
+
ShotikAnalytics.optOut() // .denied: drop the queue and record nothing
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
The choice is persisted, so later launches can omit `consent`. Support is not affected by analytics consent.
|
|
277
|
+
|
|
278
|
+
## 6. Performance and size
|
|
279
|
+
|
|
280
|
+
| Budget (PROTOCOL.md §8) | Measured |
|
|
281
|
+
|---|---|
|
|
282
|
+
| `configure` on main < 5 ms cold, < 1 ms typical | 0.0006 ms median, 0.0019 ms p95, 0.025 ms first call (20 calls, macOS test run). The sample logs it on device |
|
|
283
|
+
| Tap handler on main < 0.1 ms p95 | Measured in the sample app (Settings → Tap handler p95); not measured on a device yet |
|
|
284
|
+
| Binary: Core + Analytics < 400 KB, everything < 900 KB (arm64, release, stripped) | Stripped file delta over the no-SDK sample: Core + Analytics +354,136 B (345.8 KiB), everything +925,240 B (903.6 KiB). Section bytes without 16 KiB segment padding: 291.4 KiB and 798.9 KiB |
|
|
285
|
+
|
|
286
|
+
Release builds of the SDK use `-Osize`. Core and Support also drop reflection metadata. The sample app in `Sample/`
|
|
287
|
+
has three targets built from the same screens (everything, Core + Analytics, and no SDK), so the size report is a
|
|
288
|
+
plain difference. It logs `[shotik-sample] configure_ms=…` and a `Shotik.configure` signpost on launch.
|
|
289
|
+
|
|
290
|
+
## Troubleshooting
|
|
291
|
+
|
|
292
|
+
- **Status stays `offline`.** The device can't reach `serverUrl`. The simulator reaches the Mac at
|
|
293
|
+
`http://127.0.0.1:<port>`, but a device needs the Mac's LAN address (`http://192.168.x.x:<port>`) or an HTTPS
|
|
294
|
+
deployment. Check with `curl <serverUrl>/health`.
|
|
295
|
+
- **Plain `http://` fails on a device.** App Transport Security blocks it. Use HTTPS, or for development only add
|
|
296
|
+
`NSAppTransportSecurity → NSAllowsLocalNetworking = YES` (LAN and `.local` hosts) or an exception domain for your
|
|
297
|
+
Mac. Don't ship `NSAllowsArbitraryLoads`.
|
|
298
|
+
- **Status is `error` with "unknown app key".** The key doesn't belong to this server. Create it again in Shotik.
|
|
299
|
+
- **`myapp://support` does nothing.** The URL scheme is missing from the target's URL Types, or the root view has no
|
|
300
|
+
`.shotikSupportSheet()` (UIKit: no `ShotikSupportWidget.install()`, or `handle(url:)` is not called).
|
|
301
|
+
- **The widget never opens.** `.shotikSupportSheet()` must sit on a view that is on screen. Put it on the root view
|
|
302
|
+
of the `WindowGroup`, not on a screen inside a navigation stack.
|
|
303
|
+
- **No analytics events.** Check that `ShotikAnalytics` is linked into the app target, not only imported somewhere:
|
|
304
|
+
Core finds modules by class name at configure time. Pass `debug: true` to print every event. Consent `.pending`
|
|
305
|
+
or `.denied` also holds uploads.
|
|
306
|
+
- **Screens are named after classes such as `UIHostingController<…>`.** SwiftUI screens need `.shotikScreen("Name")`
|
|
307
|
+
or a navigation title.
|
|
308
|
+
- **Messages sit at "Sending".** While offline they show "Queued" and the header counts them. They go out when the
|
|
309
|
+
server is reachable, and after 3 failed attempts they show "Not sent · Retry".
|
|
310
|
+
- **App Store privacy questions.** The privacy manifest ships in ShotikCore. Xcode merges it into the app's privacy
|
|
311
|
+
report (Product → Archive → Generate Privacy Report).
|
|
312
|
+
|
|
313
|
+
## Tests
|
|
314
|
+
|
|
315
|
+
```sh
|
|
316
|
+
cd sdk/swift && swift test
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
The suite covers every conformance case in PROTOCOL.md §9 with a manual clock, a fake transport and fake sockets. That
|
|
320
|
+
includes the packed wire example byte for byte, the outbox, backoff, the 4003 re-identify, receipts, typing, consent and
|
|
321
|
+
the network budget. The live test runs against a real Shotik server when `SHOTIK_LIVE_URL`, `SHOTIK_LIVE_KEY` and
|
|
322
|
+
`SHOTIK_LIVE_TOKEN` are set:
|
|
323
|
+
|
|
324
|
+
```sh
|
|
325
|
+
SHOTIK_LIVE_URL=http://127.0.0.1:4590 SHOTIK_LIVE_KEY=spk_… SHOTIK_LIVE_TOKEN=… swift test --filter LiveTests
|
|
326
|
+
```
|