@growth-loop/sdk 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 +202 -0
- package/dist/browser.d.ts +13 -0
- package/dist/browser.js +4512 -0
- package/dist/browser.js.map +1 -0
- package/dist/client-CC-8sBba.d.ts +60 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +4381 -0
- package/dist/index.js.map +1 -0
- package/dist/node.d.ts +10 -0
- package/dist/node.js +4345 -0
- package/dist/node.js.map +1 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 growth-loop.dev
|
|
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,202 @@
|
|
|
1
|
+
# @growth-loop/sdk
|
|
2
|
+
|
|
3
|
+
Browser / Node / edge SDK for [growth-loop.dev](https://growth-loop.dev) —
|
|
4
|
+
Claude Code-native product analytics for vibe-coded SaaS.
|
|
5
|
+
|
|
6
|
+
Pairs with [`@growth-loop/mcp-server`](../mcp-server) so Claude Code can ask
|
|
7
|
+
your funnels, retention, and revenue questions directly with citations.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
pnpm add @growth-loop/sdk
|
|
13
|
+
# or
|
|
14
|
+
npm i @growth-loop/sdk
|
|
15
|
+
# or
|
|
16
|
+
yarn add @growth-loop/sdk
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick start — Browser (Next.js, Vite, anything web)
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
// src/lib/growth.ts
|
|
23
|
+
'use client';
|
|
24
|
+
import { instrument } from '@growth-loop/sdk';
|
|
25
|
+
import { createBrowserClient } from '@growth-loop/sdk/browser';
|
|
26
|
+
|
|
27
|
+
export const growth = instrument(
|
|
28
|
+
createBrowserClient({
|
|
29
|
+
apiKey: process.env.NEXT_PUBLIC_GROWTH_KEY!,
|
|
30
|
+
host: process.env.NEXT_PUBLIC_GROWTH_HOST ?? 'https://api.growth-loop.dev',
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
// any client component
|
|
37
|
+
import { growth } from '@/lib/growth';
|
|
38
|
+
|
|
39
|
+
<button onClick={growth.button('cta_clicked', onClick, { location: 'hero' })}>
|
|
40
|
+
Sign up
|
|
41
|
+
</button>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`createBrowserClient` enables `autoCapture` by default — page views, clicks,
|
|
45
|
+
rage-clicks, JS errors, and navigation timing all flow without ceremony.
|
|
46
|
+
Disable with `autoCapture: false` if you prefer manual control.
|
|
47
|
+
|
|
48
|
+
## Quick start — Node / server actions / route handlers
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
// src/lib/growth.server.ts
|
|
52
|
+
import { instrument } from '@growth-loop/sdk';
|
|
53
|
+
import { createServerClient } from '@growth-loop/sdk/node';
|
|
54
|
+
|
|
55
|
+
export const growth = instrument(
|
|
56
|
+
createServerClient({
|
|
57
|
+
apiKey: process.env.GROWTH_KEY!,
|
|
58
|
+
host: process.env.GROWTH_HOST ?? 'https://api.growth-loop.dev',
|
|
59
|
+
environment: (process.env.NODE_ENV ?? 'development') as
|
|
60
|
+
| 'production' | 'preview' | 'development',
|
|
61
|
+
release: process.env.GIT_COMMIT_SHA,
|
|
62
|
+
}),
|
|
63
|
+
);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
// in a route handler / server action
|
|
68
|
+
await growth.identify({ distinctId: user.id, properties: { plan: user.plan } });
|
|
69
|
+
growth.step('signup_completed', { source: 'organic' });
|
|
70
|
+
await growth.flush(); // important on serverless — request can finish before queue drains
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Quick start — Edge / Cloudflare Workers / Deno
|
|
74
|
+
|
|
75
|
+
The default transport uses `fetch`, which works in any modern runtime. For
|
|
76
|
+
queue-backed delivery (e.g. Cloudflare Queues), pass a custom transport:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { createClient } from '@growth-loop/sdk';
|
|
80
|
+
|
|
81
|
+
const growth = createClient({
|
|
82
|
+
apiKey: env.GROWTH_KEY,
|
|
83
|
+
transport: {
|
|
84
|
+
async send(url, payload, headers) {
|
|
85
|
+
await env.GROWTH_QUEUE.send({ url, payload, headers });
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Core API
|
|
92
|
+
|
|
93
|
+
### `Growth` / `createClient(options)`
|
|
94
|
+
|
|
95
|
+
The low-level client. Use `createClient` for a factory or `new Growth(options)`
|
|
96
|
+
directly.
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
interface GrowthOptions {
|
|
100
|
+
apiKey: string;
|
|
101
|
+
host?: string; // default: 'https://api.growth-loop.dev'
|
|
102
|
+
flushInterval?: number; // default: 5000ms
|
|
103
|
+
batchSize?: number; // default: 50
|
|
104
|
+
environment?: string;
|
|
105
|
+
release?: string; // git commit SHA — annotates events for `/diagnose`
|
|
106
|
+
transport?: Transport;
|
|
107
|
+
autoCapture?: boolean; // browser only; default: true
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Methods:
|
|
112
|
+
|
|
113
|
+
| Method | What it does |
|
|
114
|
+
|---|---|
|
|
115
|
+
| `track(name, properties?, options?)` | Enqueue one event. Non-blocking. |
|
|
116
|
+
| `identify({ distinctId, properties? })` | Set the current distinct ID + emit `$identify`. Subsequent events inherit the ID. |
|
|
117
|
+
| `flush()` | Force-send any queued events. Returns a Promise. **Always await on serverless.** |
|
|
118
|
+
| `shutdown()` | Flush + stop the worker. Called automatically on `beforeunload` / `process.exit`. |
|
|
119
|
+
| `setDistinctId(id)` | Set the ID without emitting `$identify`. |
|
|
120
|
+
|
|
121
|
+
### Helpers — `instrument(client)`
|
|
122
|
+
|
|
123
|
+
Wraps a `GrowthClient` and adds three high-leverage helpers used by
|
|
124
|
+
`/init` (the MCP slash-prompt that auto-instruments your repo):
|
|
125
|
+
|
|
126
|
+
#### `growth.span(name, fn, options?)`
|
|
127
|
+
|
|
128
|
+
Wraps an async function. Emits `<name>.started`, `<name>.completed` (with
|
|
129
|
+
`duration_ms`), or `<name>.failed` (with `error_message`, `error_name`). Use
|
|
130
|
+
on anything > 500ms or with non-trivial failure rate.
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
const checkout = growth.span('checkout', async (items: Item[]) => {
|
|
134
|
+
return await stripe.charge(items);
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### `growth.step(name, properties?)`
|
|
139
|
+
|
|
140
|
+
Single funnel-step event. Use for activation milestones.
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
growth.step('onboarding.connected_repo', { provider: 'github' });
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
#### `growth.button(name, onClick, properties?)`
|
|
147
|
+
|
|
148
|
+
Returns a wrapped click handler — emits the event, then runs the original.
|
|
149
|
+
Built for React onClick props.
|
|
150
|
+
|
|
151
|
+
```tsx
|
|
152
|
+
<button onClick={growth.button('cta_clicked', signUp, { location: 'hero' })}>
|
|
153
|
+
Sign up
|
|
154
|
+
</button>
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Recommended event taxonomy
|
|
158
|
+
|
|
159
|
+
The MCP server's `/diagnose` and `/weekly` prompts know these names natively.
|
|
160
|
+
Use them when they fit.
|
|
161
|
+
|
|
162
|
+
| Stage | Events |
|
|
163
|
+
|---|---|
|
|
164
|
+
| Identity | `signup_completed`, `login_completed`, `$identify` |
|
|
165
|
+
| Activation | `onboarding.started`, `onboarding.completed`, `first_<thing>_created` |
|
|
166
|
+
| Revenue | `checkout_started`, `checkout_completed`, `subscription_created`, `subscription_canceled`, `payment_failed` |
|
|
167
|
+
| Engagement | wrap key clicks with `growth.button(...)` — limit to 5–10 |
|
|
168
|
+
| Performance | `growth.span('checkout', ...)`, `growth.span('ai.generate', ...)` |
|
|
169
|
+
|
|
170
|
+
## Privacy
|
|
171
|
+
|
|
172
|
+
- **Never put PII in `properties`** (email, raw IP, full address, payment
|
|
173
|
+
details). Use `distinctId` for identity. The dashboard explicitly does not
|
|
174
|
+
decrypt or display anything in `properties` as identity.
|
|
175
|
+
- ClickHouse TTL is 12 months by default — events older than that are
|
|
176
|
+
dropped automatically.
|
|
177
|
+
- Browser SDK respects DNT (Do Not Track) and skips ingestion when set.
|
|
178
|
+
|
|
179
|
+
## Environment variables read by the SDK
|
|
180
|
+
|
|
181
|
+
| Var | Where | Default |
|
|
182
|
+
|---|---|---|
|
|
183
|
+
| `GROWTH_KEY` / `NEXT_PUBLIC_GROWTH_KEY` | Node / Browser | required |
|
|
184
|
+
| `GROWTH_HOST` / `NEXT_PUBLIC_GROWTH_HOST` | both | `https://api.growth-loop.dev` |
|
|
185
|
+
| `GIT_COMMIT_SHA` | Node | unset (passed via `release`) |
|
|
186
|
+
|
|
187
|
+
## Going deeper
|
|
188
|
+
|
|
189
|
+
The SDK is the ingest layer. The agent layer (Claude Code + MCP) is what
|
|
190
|
+
makes growth-loop different — install the MCP server too:
|
|
191
|
+
|
|
192
|
+
```sh
|
|
193
|
+
claude mcp add growth-loop -- npx -y @growth-loop/mcp-server \
|
|
194
|
+
-e GROWTH_API_KEY=pk_live_<your-key>
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Then in Claude Code: `/init` (auto-instrument), `/diagnose <metric>`,
|
|
198
|
+
`/weekly`, `/pmf`, `/icp`, `/strategy`, `/pivot`.
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
MIT
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { b as GrowthOptions, G as GrowthClient } from './client-CC-8sBba.js';
|
|
2
|
+
import '@growth/shared';
|
|
3
|
+
|
|
4
|
+
interface BrowserOptions extends GrowthOptions {
|
|
5
|
+
autoCapture?: boolean;
|
|
6
|
+
capturePageViews?: boolean;
|
|
7
|
+
captureClicks?: boolean;
|
|
8
|
+
captureRageClicks?: boolean;
|
|
9
|
+
capturePerformance?: boolean;
|
|
10
|
+
}
|
|
11
|
+
declare function createBrowserClient(options: BrowserOptions): GrowthClient;
|
|
12
|
+
|
|
13
|
+
export { type BrowserOptions, GrowthClient, createBrowserClient };
|