@analyticscli/sdk 0.1.0-preview.10
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 +239 -0
- package/dist/browser.cjs +1978 -0
- package/dist/browser.d.cts +1 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +36 -0
- package/dist/chunk-6EPJZLLK.js +1937 -0
- package/dist/index.cjs +1978 -0
- package/dist/index.d.cts +587 -0
- package/dist/index.d.ts +587 -0
- package/dist/index.js +36 -0
- package/dist/react-native.cjs +1978 -0
- package/dist/react-native.d.cts +1 -0
- package/dist/react-native.d.ts +1 -0
- package/dist/react-native.js +36 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) AnalyticsCLI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# @analyticscli/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript-first SDK for tenant developers sending onboarding, paywall, purchase, and survey analytics events to the AnalyticsCLI ingest API.
|
|
4
|
+
|
|
5
|
+
Using a coding agent: you can let it handle SDK integration and instrumentation end-to-end with the AnalyticsCLI skills repo:
|
|
6
|
+
https://github.com/Wotaso/analyticscli-skills
|
|
7
|
+
|
|
8
|
+
Use the same package in:
|
|
9
|
+
- React Native / Expo apps
|
|
10
|
+
- Browser React apps
|
|
11
|
+
- plain JavaScript and TypeScript codebases
|
|
12
|
+
|
|
13
|
+
Current npm release channel: preview / experimental beta.
|
|
14
|
+
If no stable release exists yet, `latest` points to the newest preview.
|
|
15
|
+
Once stable releases exist, `latest` is pinned to the newest stable.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @analyticscli/sdk@preview
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
When a stable release becomes available, install without a tag:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @analyticscli/sdk
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Dashboard Credentials
|
|
30
|
+
|
|
31
|
+
Before integrating, collect required values in [dash.analyticscli.com](https://dash.analyticscli.com):
|
|
32
|
+
|
|
33
|
+
- Select the target project.
|
|
34
|
+
- Open **API Keys** and copy the publishable ingest API key for SDK `apiKey`.
|
|
35
|
+
- If you validate with CLI, create/copy a CLI `readonly_token` in the same **API Keys** area.
|
|
36
|
+
- Optional for CLI verification: set a default project once with `analyticscli projects select` (arrow-key picker), or pass `--project <project_id>` per command.
|
|
37
|
+
|
|
38
|
+
## Usage (Low Boilerplate)
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { createAnalyticsContext } from '@analyticscli/sdk';
|
|
42
|
+
|
|
43
|
+
const analytics = createAnalyticsContext({
|
|
44
|
+
client: {
|
|
45
|
+
apiKey: '<YOUR_APP_KEY>',
|
|
46
|
+
identityTrackingMode: 'consent_gated', // explicit host-app default
|
|
47
|
+
},
|
|
48
|
+
onboarding: {
|
|
49
|
+
onboardingFlowId: 'onboarding_v1',
|
|
50
|
+
onboardingFlowVersion: '1.0.0',
|
|
51
|
+
isNewUser: true,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
analytics.onboarding.start();
|
|
56
|
+
analytics.onboarding.step('welcome', 0).view();
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`createAnalyticsContext(...)` gives you:
|
|
60
|
+
- `analytics.client` (raw `AnalyticsClient`)
|
|
61
|
+
- `analytics.onboarding` (pre-wired tracker instance)
|
|
62
|
+
- `analytics.paywall` (optional tracker instance)
|
|
63
|
+
- `analytics.consent.*` (collection + full-tracking controls)
|
|
64
|
+
- `analytics.user.*` (`set`, `clear`, `identify`)
|
|
65
|
+
|
|
66
|
+
For host-app integration, prefer explicit client config with
|
|
67
|
+
`identityTrackingMode: 'consent_gated'` unless you intentionally need another mode.
|
|
68
|
+
|
|
69
|
+
Optional runtime collection pause/resume:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { createAnalyticsContext } from '@analyticscli/sdk';
|
|
73
|
+
|
|
74
|
+
const analytics = createAnalyticsContext({
|
|
75
|
+
client: {
|
|
76
|
+
apiKey: '<YOUR_APP_KEY>',
|
|
77
|
+
identityTrackingMode: 'consent_gated',
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
analytics.consent.optOut(); // stop sending until optIn()
|
|
81
|
+
// ...
|
|
82
|
+
analytics.consent.optIn();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Optional full-tracking consent gate (recommended default):
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import { createAnalyticsContext } from '@analyticscli/sdk';
|
|
89
|
+
|
|
90
|
+
const analytics = createAnalyticsContext({
|
|
91
|
+
client: {
|
|
92
|
+
apiKey: '<YOUR_APP_KEY>',
|
|
93
|
+
identityTrackingMode: 'consent_gated',
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// user accepts full tracking in your consent UI
|
|
98
|
+
analytics.consent.setFullTracking(true);
|
|
99
|
+
|
|
100
|
+
// user rejects full tracking but you still keep strict anonymous analytics
|
|
101
|
+
analytics.consent.setFullTracking(false);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
If `apiKey` is missing, the SDK logs a console error and remains a safe no-op client.
|
|
105
|
+
|
|
106
|
+
## Optional Configuration
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import * as Application from 'expo-application';
|
|
110
|
+
import { Platform } from 'react-native';
|
|
111
|
+
import { createAnalyticsContext } from '@analyticscli/sdk';
|
|
112
|
+
|
|
113
|
+
const analytics = createAnalyticsContext({
|
|
114
|
+
client: {
|
|
115
|
+
apiKey: process.env.EXPO_PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY,
|
|
116
|
+
debug: __DEV__,
|
|
117
|
+
platform: Platform.OS,
|
|
118
|
+
projectSurface: 'app',
|
|
119
|
+
appVersion: Application.nativeApplicationVersion,
|
|
120
|
+
initialConsentGranted: true,
|
|
121
|
+
identityTrackingMode: 'consent_gated',
|
|
122
|
+
initialFullTrackingConsentGranted: false,
|
|
123
|
+
dedupeOnboardingStepViewsPerSession: true,
|
|
124
|
+
dedupeScreenViewsPerSession: true,
|
|
125
|
+
screenViewDedupeWindowMs: 1200,
|
|
126
|
+
},
|
|
127
|
+
onboarding: {
|
|
128
|
+
onboardingFlowId: 'onboarding_main',
|
|
129
|
+
onboardingFlowVersion: '1',
|
|
130
|
+
isNewUser: true,
|
|
131
|
+
stepCount: 7,
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The SDK normalizes React Native/Expo platform values to canonical ingest values
|
|
137
|
+
(`macos` -> `mac`, `win32` -> `windows`) and accepts `null` for optional
|
|
138
|
+
`appVersion` inputs.
|
|
139
|
+
Use `projectSurface` for product/channel separation (`landing`, `dashboard`, `app`)
|
|
140
|
+
without overloading runtime `platform` (`web`, `ios`, `android`, ...).
|
|
141
|
+
|
|
142
|
+
`dedupeOnboardingStepViewsPerSession` dedupes duplicate `onboarding:step_view`
|
|
143
|
+
events for the same step in the same session.
|
|
144
|
+
`dedupeScreenViewsPerSession` dedupes immediate duplicate `screen(...)` calls
|
|
145
|
+
for the same screen key in the same session (for example, when focus and mount
|
|
146
|
+
hooks both fire for one transition). `screenViewDedupeWindowMs` controls this
|
|
147
|
+
window (default `1200` ms).
|
|
148
|
+
Neither setting dedupes paywall or purchase events.
|
|
149
|
+
|
|
150
|
+
For paywall funnels with stable `source` + `paywallId`, create one tracker per
|
|
151
|
+
flow context and reuse it:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
const paywall = analytics.createPaywall({
|
|
155
|
+
source: 'onboarding',
|
|
156
|
+
paywallId: 'default_paywall',
|
|
157
|
+
offering: 'rc_main', // RevenueCat example
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
paywall.shown({ fromScreen: 'onboarding_offer' });
|
|
161
|
+
paywall.purchaseSuccess({ packageId: 'annual' });
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Do not create a new `createPaywall(...)` instance for every paywall callback/event.
|
|
165
|
+
If your paywall provider exposes it, pass `offering` in tracker defaults
|
|
166
|
+
(RevenueCat offering id, Adapty paywall/placement id, Superwall placement/paywall id).
|
|
167
|
+
|
|
168
|
+
For onboarding surveys, avoid repeating unchanged flow metadata at every callsite.
|
|
169
|
+
Create one onboarding tracker with defaults and emit minimal survey payloads:
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
const onboarding = analytics.createOnboarding({
|
|
173
|
+
onboardingFlowId: 'onboarding_main',
|
|
174
|
+
onboardingFlowVersion: '1',
|
|
175
|
+
stepCount: 7,
|
|
176
|
+
isNewUser: true,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
onboarding.step('budget-survey', 6).surveyResponse({
|
|
180
|
+
surveyKey: 'onboarding_main',
|
|
181
|
+
questionKey: 'budget',
|
|
182
|
+
answerType: 'single_choice',
|
|
183
|
+
responseKey: '100-500',
|
|
184
|
+
});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
For RevenueCat correlation, keep identity and paywall purchase metadata aligned:
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
analytics.user.set(appUserId); // same id passed to Purchases.logIn(appUserId)
|
|
191
|
+
// in purchase callbacks, prefer provider-native ids
|
|
192
|
+
paywall.purchaseStarted({ packageId: packageBeingPurchased.identifier });
|
|
193
|
+
// on sign-out
|
|
194
|
+
analytics.user.clear();
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Identity tracking modes:
|
|
198
|
+
- `consent_gated` (default): starts strict (no persistent identity), enables persistence/linkage only after full-tracking consent is granted
|
|
199
|
+
- `always_on`: enables persistence/linkage immediately (`enableFullTrackingWithoutConsent: true` is a boolean shortcut)
|
|
200
|
+
- `strict`: keeps strict anonymous behavior permanently
|
|
201
|
+
|
|
202
|
+
Recommendation for global tenant apps:
|
|
203
|
+
- keep `consent_gated` as default, especially when EU/EEA/UK traffic is in scope
|
|
204
|
+
|
|
205
|
+
In strict phase (and in `strict` mode):
|
|
206
|
+
- no persistent SDK identity across app/browser restarts
|
|
207
|
+
- no cookie-domain identity continuity
|
|
208
|
+
- `analytics.user.identify(...)` / `analytics.user.set(...)` are ignored
|
|
209
|
+
|
|
210
|
+
`initialConsentGranted` is optional:
|
|
211
|
+
- default: `true` when `apiKey` is present
|
|
212
|
+
- you can still pause/resume collection at runtime with consent APIs when your app needs that
|
|
213
|
+
|
|
214
|
+
Runtime collection control APIs:
|
|
215
|
+
- `analytics.consent.get()` -> current in-memory consent
|
|
216
|
+
- `analytics.consent.getState()` -> `'granted' | 'denied' | 'unknown'`
|
|
217
|
+
- `analytics.consent.optIn()` / `analytics.consent.optOut()`
|
|
218
|
+
- `analytics.consent.set(true|false)`
|
|
219
|
+
|
|
220
|
+
Full-tracking control APIs:
|
|
221
|
+
- `analytics.consent.setFullTracking(true|false)`
|
|
222
|
+
- `analytics.consent.optInFullTracking()` / `analytics.consent.optOutFullTracking()`
|
|
223
|
+
- `analytics.consent.isFullTrackingEnabled()`
|
|
224
|
+
|
|
225
|
+
`analytics.ready()` / `analytics.client.ready()` do not "start" tracking. With default settings, tracking
|
|
226
|
+
starts on `createAnalyticsContext(...)`.
|
|
227
|
+
|
|
228
|
+
Use your project-specific publishable API key from the AnalyticsCLI dashboard in your workspace.
|
|
229
|
+
Only the publishable API key (`apiKey`) is needed for SDK setup calls.
|
|
230
|
+
The SDK uses the default collector endpoint internally.
|
|
231
|
+
In host apps, do not pass `endpoint` and do not add `ANALYTICSCLI_ENDPOINT` env vars.
|
|
232
|
+
|
|
233
|
+
Browser cookie-domain continuity is disabled while strict mode is active.
|
|
234
|
+
For redirects across different domains, use a backend-issued short-lived handoff token rather than relying on third-party cookies.
|
|
235
|
+
|
|
236
|
+
## Releases
|
|
237
|
+
|
|
238
|
+
Use npm package versions and GitHub Releases in the public SDK repository as
|
|
239
|
+
the source for release history.
|