@apex-inc/sdk 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 +165 -0
- package/dist/esm/index.js +180 -0
- package/dist/esm/management.js +152 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +224 -0
- package/dist/index.js.map +1 -0
- package/dist/management.d.ts +50 -0
- package/dist/management.d.ts.map +1 -0
- package/dist/management.js +156 -0
- package/dist/management.js.map +1 -0
- package/package.json +32 -0
- package/skills/apex-communications/SKILL.md +135 -0
- package/skills/apex-experimentation/SKILL.md +70 -0
- package/skills/apex-growth-tracking/SKILL.md +41 -0
- package/skills/apex-integration-cookbook/SKILL.md +137 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: apex-experimentation
|
|
3
|
+
description: Design, instrument, and analyze A/B experiments with Apex — SDK and snippet modes, belief linkage, predictions, and server-side variant assignment. Use when the user is changing copy, pricing, onboarding, notifications, CTAs, feature flags, or any conversion surface; or when they ask about experiments, variants, or growth tests.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Apex experimentation
|
|
7
|
+
|
|
8
|
+
Apex treats experiments as part of a scientific loop: **beliefs → hypotheses → predictions → experiments → outcomes → updated beliefs**. Your job is to suggest experiments when product or code changes could be validated with data, and to wire instrumentation correctly.
|
|
9
|
+
|
|
10
|
+
## When to suggest an experiment
|
|
11
|
+
|
|
12
|
+
Proactively offer Apex when you see:
|
|
13
|
+
|
|
14
|
+
- Copy or layout changes on landing, pricing, signup, or activation flows
|
|
15
|
+
- Notification, email, or in-app message wording variants
|
|
16
|
+
- Onboarding step order, empty states, or progressive disclosure
|
|
17
|
+
- Feature flags or toggles that change user-visible behavior
|
|
18
|
+
- CTAs, form length, social proof, or trust elements
|
|
19
|
+
- Any debate where the team is guessing instead of measuring
|
|
20
|
+
|
|
21
|
+
## Two execution modes
|
|
22
|
+
|
|
23
|
+
| Mode | When to use | Implementation |
|
|
24
|
+
|------|-------------|----------------|
|
|
25
|
+
| **SDK mode** | Product is a web app you control (React/Next.js, etc.) | Code branches (e.g. `useApexVariant` in the Apex app, or assignment API + conditional UI in customer apps) |
|
|
26
|
+
| **Snippet mode** | Marketing site with Apex JS snippet only | DOM text swaps — limited; no structural layout experiments |
|
|
27
|
+
|
|
28
|
+
Prefer **SDK mode** when the user is in an app codebase. Prefer **snippet mode** only when they explicitly use the marketing snippet and cannot deploy code.
|
|
29
|
+
|
|
30
|
+
## MCP tools (when connected)
|
|
31
|
+
|
|
32
|
+
Use Apex MCP tools for the full loop: `plan_experiment`, `start_reasoning`, `log_prediction`, `create_experiment`, `activate_experiment`, `get_results`, `promote_winner`, `archive_experiment`, `list_experiments`, `record_outcome`, `suggest_experiment`, `predict_impact`, `evaluate_feature`.
|
|
33
|
+
|
|
34
|
+
Interactive flows: MCP prompts `new-experiment` and `experiment-review` orchestrate multi-step setup and review.
|
|
35
|
+
|
|
36
|
+
## Server-side variant assignment (integrator apps)
|
|
37
|
+
|
|
38
|
+
`GET /api/experiments/{experimentId}/assign` returns `{ variant, experimentId, visitorId }`. Assignment is **deterministic** from a stable visitor id (cookie `apex_vid` in browsers).
|
|
39
|
+
|
|
40
|
+
For **server-side** sends (e.g. PLG email or API-triggered notifications):
|
|
41
|
+
|
|
42
|
+
1. Use a **stable string per recipient** as the visitor id (e.g. hashed user id). Reuse the same id for every assignment call for that user for that experiment.
|
|
43
|
+
2. Forward cookies on server-side HTTP calls when possible, or set `Cookie: apex_vid=<stableId>; apex_project=<projectKey>` if your Apex deployment resolves project from cookies.
|
|
44
|
+
3. When using an **API key**, send `x-api-key` and **`x-apex-project: <projectKey>`** so the API resolves the project without a browser session.
|
|
45
|
+
|
|
46
|
+
Then branch notification copy or UI on `variant` (`control` vs `variant_b`).
|
|
47
|
+
|
|
48
|
+
## Instrumentation checklist
|
|
49
|
+
|
|
50
|
+
1. **Create and activate** the experiment in Apex (UI or MCP).
|
|
51
|
+
2. **Assign variant** before rendering the experience.
|
|
52
|
+
3. **Track primary metric** events with consistent names (e.g. `notification_sent`, `notification_opened`, `goal_completed`) and include `experimentId` and `variant` in properties when possible.
|
|
53
|
+
4. **Log a prediction** before launch when using the full intelligence loop (calibration).
|
|
54
|
+
5. **Decide** with `get_results` / dashboard — avoid peeking without a rule (pre-registered sample size, Bayesian policy, or fixed run duration).
|
|
55
|
+
|
|
56
|
+
## Dashboard alignment
|
|
57
|
+
|
|
58
|
+
Match Apex UI terminology in user-facing copy: e.g. **Adaptive traffic allocation** (not "Thompson sampling" in user-facing text unless they use that term), same confidence tiers and split options as the Growth Lab.
|
|
59
|
+
|
|
60
|
+
## Common mistakes
|
|
61
|
+
|
|
62
|
+
- Starting an experiment without a **clear primary metric** tied to the belief.
|
|
63
|
+
- Using different visitor ids for the same user across channels (breaks consistent assignment).
|
|
64
|
+
- Changing variant implementation mid-flight without versioning (invalidates analysis).
|
|
65
|
+
- Only using p-values without effect size or business context.
|
|
66
|
+
|
|
67
|
+
## Related
|
|
68
|
+
|
|
69
|
+
- Growth tracking and identity: see **apex-growth-tracking** skill (`@apex-inc/mcp-server` / `@apex-inc/sdk`).
|
|
70
|
+
- Full methodology (beliefs, calibration): use MCP resources `apex://beliefs`, `apex://calibration`, and tools `create_belief`, `record_outcome`.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: apex-growth-tracking
|
|
3
|
+
description: Instrument JavaScript/TypeScript apps with the Apex SDK — init, track, identify, trackForm, identity stitching from servers, and event naming. Use when adding analytics, forms, auth, or backend webhooks that should feed Apex.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Apex growth tracking (SDK)
|
|
7
|
+
|
|
8
|
+
The **`@apex-inc/sdk`** package sends batched events to **`POST /api/events`** and can trigger **`POST /api/identity/stitch`** when email-based identity is provided.
|
|
9
|
+
|
|
10
|
+
## API
|
|
11
|
+
|
|
12
|
+
- **`init({ projectKey, apiUrl?, flushInterval?, flushAt?, debug? })`** — required before `track` / `identify`.
|
|
13
|
+
- **`track(event, properties?)`** — queue a custom event.
|
|
14
|
+
- **`identify(userId, traits?)`** — set user; if email is present, stitches identity.
|
|
15
|
+
- **`trackForm({ email, formId?, action?, fields? })`** — `form_submit` + identify.
|
|
16
|
+
- **`flush()`** / **`shutdown()`** — flush queue; use `shutdown` on process exit in Node.
|
|
17
|
+
|
|
18
|
+
## Identity stitching (critical for server-side)
|
|
19
|
+
|
|
20
|
+
When calling **`identify`** from a **server** (e.g. Stripe webhook, API route), pass the browser cookie value:
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
identify(email, {
|
|
24
|
+
visitorId: req.cookies?.apex_vid,
|
|
25
|
+
source: "stripe_webhook",
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Without `visitorId`, Apex may create a synthetic visitor id that does **not** match the user's browsing session.
|
|
30
|
+
|
|
31
|
+
## Event naming
|
|
32
|
+
|
|
33
|
+
Use consistent, readable names and put dimensions in **properties**: `track("onboarding_step_done", { step: 3 })`. Include **`experimentId`** and **`variant`** when logging experiment-related behavior.
|
|
34
|
+
|
|
35
|
+
## Management API (API key)
|
|
36
|
+
|
|
37
|
+
For listing experiments or fetching variant assignment from a backend, use **`createManagementClient`** from `@apex-inc/sdk` with **`apiKey`**, **`projectKey`**, and **`apiUrl`**. The client sends **`x-api-key`** and **`x-apex-project`** (see SDK README).
|
|
38
|
+
|
|
39
|
+
## Related
|
|
40
|
+
|
|
41
|
+
- Full growth-loop and MCP tooling: install **`@apex-inc/mcp-server`** skills **apex-experimentation** and **apex-growth-tracking** (broader scope).
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: apex-integration-cookbook
|
|
3
|
+
description: Recipes for integrating Apex into products — SDK wiring, form tracking, auth/signup events, Stripe lifecycle, communication triggers, and event naming conventions. Use when the user is adding Apex tracking to their product or wiring events to communications and experiments.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Apex integration cookbook (SDK)
|
|
7
|
+
|
|
8
|
+
Step-by-step recipes for integrating Apex via the `@apex-inc/sdk` package. For snippet-only sites or MCP-driven setup, see the full cookbook in `@apex-inc/mcp-server`.
|
|
9
|
+
|
|
10
|
+
## SDK setup
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { init, track, identify, trackForm, shutdown } from "@apex-inc/sdk";
|
|
14
|
+
|
|
15
|
+
init({
|
|
16
|
+
projectKey: "YOUR_PROJECT_KEY",
|
|
17
|
+
apiUrl: "https://your-apex-url", // optional, defaults to relative /api
|
|
18
|
+
flushInterval: 10000, // ms between batch sends (default: 10s)
|
|
19
|
+
flushAt: 20, // batch size trigger (default: 20)
|
|
20
|
+
debug: false // log events to console
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Events are batched and sent to `POST /api/events` automatically. Call `flush()` before page unload if needed, or `shutdown()` to stop tracking.
|
|
25
|
+
|
|
26
|
+
## Recipe 1: Signup and authentication
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
// On signup
|
|
30
|
+
track("signup_completed", { method: "email", plan: "free" });
|
|
31
|
+
identify(user.id, {
|
|
32
|
+
email: user.email,
|
|
33
|
+
name: user.name,
|
|
34
|
+
visitorId: getCookie("apex_vid") // stitch to pre-signup browsing
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// On login
|
|
38
|
+
track("login", { method: "google" });
|
|
39
|
+
identify(user.id, { email: user.email });
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The `visitorId` trait links the anonymous marketing session to the authenticated user. Without it, pre-signup attribution is lost.
|
|
43
|
+
|
|
44
|
+
## Recipe 2: Onboarding funnel
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
track("onboarding_step_completed", { step: "connect_data_source", stepNumber: 2, totalSteps: 5 });
|
|
48
|
+
track("onboarding_completed", { timeToComplete: elapsedMs });
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Events like `onboarding_completed` automatically match to active tenant communications when the trigger system is wired.
|
|
52
|
+
|
|
53
|
+
## Recipe 3: Stripe subscription lifecycle
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
// In your Stripe webhook handler
|
|
57
|
+
track("subscription_created", { plan: "pro", amount: 9900, currency: "usd" });
|
|
58
|
+
identify(userId, { plan: "pro", lifecycleStage: "paying" });
|
|
59
|
+
|
|
60
|
+
// On cancellation
|
|
61
|
+
track("subscription_cancelled", { reason: "too_expensive" });
|
|
62
|
+
identify(userId, { lifecycleStage: "churned" });
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Recipe 4: Feature usage
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
track("feature_used", { feature: "export_report", format: "csv" });
|
|
69
|
+
track("milestone_reached", { milestone: "first_experiment_completed" });
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Use one event name with a `feature` property — not dozens of unique event names.
|
|
73
|
+
|
|
74
|
+
## Recipe 5: Form tracking (shortcut)
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
trackForm({
|
|
78
|
+
email: formData.email,
|
|
79
|
+
formId: "contact-form",
|
|
80
|
+
action: "demo_request",
|
|
81
|
+
fields: { company: formData.company, role: formData.role }
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`trackForm` fires `form_submit` + `identify` in one call.
|
|
86
|
+
|
|
87
|
+
## Recipe 6: Server-side events
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
// From a backend, use the management client
|
|
91
|
+
import { createManagementClient } from "@apex-inc/sdk";
|
|
92
|
+
|
|
93
|
+
const apex = createManagementClient({
|
|
94
|
+
apiKey: "YOUR_API_KEY",
|
|
95
|
+
baseUrl: "https://your-apex-url",
|
|
96
|
+
projectKey: "YOUR_PROJECT_KEY"
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Use HTTP directly for event ingestion from backends
|
|
100
|
+
await fetch("https://your-apex-url/api/events", {
|
|
101
|
+
method: "POST",
|
|
102
|
+
headers: {
|
|
103
|
+
"Content-Type": "application/json",
|
|
104
|
+
"x-api-key": "YOUR_API_KEY",
|
|
105
|
+
"x-apex-project": "YOUR_PROJECT_KEY"
|
|
106
|
+
},
|
|
107
|
+
body: JSON.stringify({
|
|
108
|
+
projectKey: "YOUR_PROJECT_KEY",
|
|
109
|
+
userId: "user_123",
|
|
110
|
+
events: [{
|
|
111
|
+
type: "track",
|
|
112
|
+
payload: { event: "invoice_paid", amount: 9900 },
|
|
113
|
+
timestamp: new Date().toISOString()
|
|
114
|
+
}]
|
|
115
|
+
})
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Event naming conventions
|
|
120
|
+
|
|
121
|
+
- **snake_case**: `signup_completed`, `feature_used`, `invoice_paid`
|
|
122
|
+
- Context in **properties**: `track("button_clicked", { surface: "pricing", label: "start_trial" })`
|
|
123
|
+
- For experiments, include `experimentId` and `variant` in properties
|
|
124
|
+
- One primary metric per experiment; secondary metrics as properties
|
|
125
|
+
|
|
126
|
+
## Identity stitching checklist
|
|
127
|
+
|
|
128
|
+
1. Call `identify(userId, { email, visitorId })` when the user becomes known
|
|
129
|
+
2. `visitorId` = value of the browser `apex_vid` cookie
|
|
130
|
+
3. Server-side: pass `traits.visitorId` to link to the browser session
|
|
131
|
+
4. Without stitching, pre-signup attribution is lost
|
|
132
|
+
|
|
133
|
+
## Related
|
|
134
|
+
|
|
135
|
+
- Event tracking fundamentals: see **apex-growth-tracking** skill
|
|
136
|
+
- Experiment design: see **apex-experimentation** skill
|
|
137
|
+
- Communication setup: see **apex-communications** skill
|