@analyticscli/sdk 0.1.0-preview.4

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 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,116 @@
1
+ # @analyticscli/sdk
2
+
3
+ TypeScript SDK for tenant developers sending onboarding, paywall, purchase, and survey analytics events to the AnalyticsCLI ingest API.
4
+
5
+ Current npm release channel: preview / experimental beta.
6
+ If no stable release exists yet, `latest` points to the newest preview.
7
+ Once stable releases exist, `latest` is pinned to the newest stable.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @analyticscli/sdk@preview
13
+ ```
14
+
15
+ When a stable release becomes available, install without a tag:
16
+
17
+ ```bash
18
+ npm install @analyticscli/sdk
19
+ ```
20
+
21
+ ## Usage (Low Boilerplate)
22
+
23
+ ```ts
24
+ import { init, ONBOARDING_EVENTS } from '@analyticscli/sdk';
25
+
26
+ const analytics = init('<YOUR_APP_KEY>'); // short form
27
+
28
+ analytics.trackOnboardingEvent(ONBOARDING_EVENTS.START, {
29
+ onboardingFlowId: 'onboarding_v1',
30
+ });
31
+ ```
32
+
33
+ `init(...)` accepts either:
34
+
35
+ - `init('<YOUR_APP_KEY>')`
36
+ - `init({ ...allOptionsOptional })`
37
+
38
+ `initFromEnv()` remains available and resolves credentials from these env keys:
39
+
40
+ - `ANALYTICSCLI_WRITE_KEY`
41
+ - `NEXT_PUBLIC_ANALYTICSCLI_WRITE_KEY`
42
+ - `EXPO_PUBLIC_ANALYTICSCLI_WRITE_KEY`
43
+ - `VITE_ANALYTICSCLI_WRITE_KEY`
44
+
45
+ Runtime-specific env helpers are also available:
46
+
47
+ - `@analyticscli/sdk` -> `initBrowserFromEnv(...)`
48
+ - adds `PUBLIC_ANALYTICSCLI_WRITE_KEY` lookup for Astro/browser-first setups
49
+ - `@analyticscli/sdk` -> `initReactNativeFromEnv(...)`
50
+ - defaults to native-friendly env key lookup
51
+ - optional compatibility subpaths:
52
+ - `@analyticscli/sdk/browser`
53
+ - `@analyticscli/sdk/react-native`
54
+
55
+ If config is missing, the client is a safe no-op (default behavior).
56
+ When `apiKey` is missing, the SDK logs a console error and remains no-op.
57
+ Use strict mode if you want hard failure:
58
+
59
+ ```ts
60
+ const analytics = initFromEnv({
61
+ missingConfigMode: 'throw',
62
+ });
63
+ ```
64
+
65
+ ## Optional Configuration
66
+
67
+ ```ts
68
+ import AsyncStorage from '@react-native-async-storage/async-storage';
69
+ import * as Application from 'expo-application';
70
+ import { Platform } from 'react-native';
71
+ import { init } from '@analyticscli/sdk';
72
+
73
+ const analytics = init({
74
+ apiKey: process.env.EXPO_PUBLIC_ANALYTICSCLI_WRITE_KEY,
75
+ debug: typeof __DEV__ === 'boolean' ? __DEV__ : false,
76
+ platform:
77
+ Platform.OS === 'ios' ||
78
+ Platform.OS === 'android' ||
79
+ Platform.OS === 'windows' ||
80
+ Platform.OS === 'macos'
81
+ ? Platform.OS === 'macos'
82
+ ? 'mac'
83
+ : Platform.OS
84
+ : undefined,
85
+ appVersion: Application.nativeApplicationVersion ?? undefined,
86
+ dedupeOnboardingStepViewsPerSession: true,
87
+ storage: {
88
+ getItem: (key) => AsyncStorage.getItem(key),
89
+ setItem: (key, value) => AsyncStorage.setItem(key, value),
90
+ removeItem: (key) => AsyncStorage.removeItem(key),
91
+ },
92
+ });
93
+
94
+ void analytics.ready();
95
+ ```
96
+
97
+ Use your project-specific write key from the AnalyticsCLI dashboard in your workspace.
98
+ Only the write key (`apiKey`) is needed for SDK init calls.
99
+ The SDK uses the default collector endpoint internally.
100
+ In host apps, do not pass `endpoint` and do not add `ANALYTICSCLI_ENDPOINT` env vars.
101
+
102
+ For browser subdomain continuity, set `cookieDomain` (for example `.analyticscli.com`).
103
+ For redirects across different domains, use a backend-issued short-lived handoff token rather than relying on third-party cookies.
104
+
105
+ ## Releases
106
+
107
+ Versioning is managed in the private monorepo via Changesets.
108
+ Every SDK change should include a changeset entry (`pnpm changeset`), and CI creates
109
+ the release version PR (`chore(release): version sdk-ts`) automatically on `main`.
110
+
111
+ After that release PR is merged, the public mirror repository can run `Release to npm`.
112
+ Each successful run creates or updates the matching GitHub Release
113
+ (`v<package.json version>`) and links to the published npm version.
114
+
115
+ Source of truth for this package is the private monorepo path `packages/sdk-ts`.
116
+ Public mirror source prefix: `packages/sdk-ts`.