@apex-inc/sdk 0.1.0 → 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.
Files changed (2) hide show
  1. package/README.md +10 -140
  2. package/package.json +3 -7
package/README.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # @apex-inc/sdk
2
2
 
3
- Lightweight SDK for sending events and user data to Apex Growth Intelligence. Works in **Node.js** (18+) and **browser** environments. Zero runtime dependencies.
3
+ Event tracking and identity SDK for Apex — currently in **private beta**.
4
+
5
+ Works in Node.js 18+ and browser environments. Zero runtime dependencies.
6
+
7
+ ## Access
8
+
9
+ Apex is invite-only during the private-beta period. If you received an invite, your onboarding email contains your `projectKey` and `apiUrl`. Full API documentation is available in-app once your account is active.
10
+
11
+ Not in the beta yet? Request access at [apex.inc](https://apex.inc) (coming soon).
4
12
 
5
13
  ## Install
6
14
 
@@ -13,153 +21,15 @@ npm install @apex-inc/sdk
13
21
  ```typescript
14
22
  import { init, track, identify } from "@apex-inc/sdk";
15
23
 
16
- // Initialize (once, at app startup)
17
24
  init({
18
25
  projectKey: "your-project-key",
19
26
  apiUrl: "https://your-apex-instance.com",
20
27
  });
21
28
 
22
- // Identify a user
23
- identify("user_123", {
24
- email: "jane@example.com",
25
- plan: "starter",
26
- });
27
-
28
- // Track events
29
+ identify("user_123", { email: "jane@example.com" });
29
30
  track("page_viewed", { path: "/pricing" });
30
- track("button_clicked", { label: "Start Trial", section: "hero" });
31
- track("form_submitted", { formId: "signup", fields: 3 });
32
- ```
33
-
34
- ## API
35
-
36
- ### `init(config)`
37
-
38
- | Option | Type | Default | Description |
39
- |-----------------|----------|--------------------------|-----------------------------------|
40
- | `projectKey` | string | **required** | Your Apex project key |
41
- | `apiUrl` | string | `window.location.origin` | Apex API URL |
42
- | `flushInterval` | number | `5000` | Auto-flush interval (ms) |
43
- | `flushAt` | number | `20` | Max queued events before flush |
44
- | `debug` | boolean | `false` | Log SDK activity to console |
45
-
46
- ### `track(event, properties?)`
47
-
48
- Send a named event with optional properties.
49
-
50
- ```typescript
51
- track("page_viewed", { path: "/pricing", referrer: "google" });
52
- ```
53
-
54
- ### `identify(userId, traits?)`
55
-
56
- Associate subsequent events with a user. Also performs **identity stitching** — linking an anonymous visitor to a known email address.
57
-
58
- ```typescript
59
- identify("jane@example.com", {
60
- name: "Jane Smith",
61
- plan: "growth",
62
- company: "Acme Inc",
63
- });
64
- ```
65
-
66
- #### Identity Stitching
67
-
68
- When the `userId` contains `@` (or `traits.email` is set), the SDK automatically calls the `/api/identity/stitch` endpoint to link the email to a visitor profile. This connects anonymous browsing behavior (from the Apex snippet) to a known user.
69
-
70
- For **server-side** identify calls (e.g., from a webhook handler), pass the browser's `apex_vid` cookie as `traits.visitorId` to ensure the stitch connects to the real browser session:
71
-
72
- ```typescript
73
- identify("jane@example.com", {
74
- visitorId: req.cookies.apex_vid, // From the browser cookie
75
- plan: "growth",
76
- });
77
- ```
78
-
79
- Without `visitorId`, a synthetic visitor ID is created that won't connect to marketing touchpoints.
80
-
81
- ### `trackForm(formData)`
82
-
83
- Track a form submission and identify the user in one call. Combines `track("form_submit", ...)` with `identify(email, ...)`.
84
-
85
- ```typescript
86
- trackForm({
87
- email: "jane@example.com",
88
- formId: "signup-form",
89
- action: "/api/register",
90
- fields: { name: "Jane", company: "Acme" },
91
- });
92
- ```
93
-
94
- | Option | Type | Required | Description |
95
- |----------|--------|----------|----------------------------------|
96
- | `email` | string | Yes | User's email address |
97
- | `formId` | string | No | Form identifier |
98
- | `action` | string | No | Form action URL |
99
- | `fields` | object | No | Additional form field data |
100
-
101
- ### `flush()`
102
-
103
- Immediately send all queued events.
104
-
105
- ### `shutdown()`
106
-
107
- Flush remaining events and stop the background timer.
108
-
109
- ## Node.js Usage
110
-
111
- The SDK works in Node.js 18+ (which includes global `fetch`). For older Node.js versions, install `node-fetch`:
112
-
113
- ```bash
114
- npm install node-fetch
115
31
  ```
116
32
 
117
- ```typescript
118
- import { init, track, identify, shutdown } from "@apex-inc/sdk";
119
-
120
- init({
121
- projectKey: "your-project-key",
122
- apiUrl: "https://your-apex-instance.com",
123
- });
124
-
125
- // In your webhook handler or API route:
126
- identify("new-signup@example.com", { source: "stripe_webhook" });
127
- track("subscription_created", { plan: "growth", mrr: 99 });
128
-
129
- // On process exit:
130
- shutdown();
131
- ```
132
-
133
- ## Management API (API key)
134
-
135
- For **server-side** access to experiments (same auth model as the Apex MCP server), use `createManagementClient` with your **`APEX_API_KEY`** and project key. The client sends **`x-api-key`** and **`x-apex-project`** so routes resolve the tenant without a browser session.
136
-
137
- ```typescript
138
- import { createManagementClient, init, track } from "@apex-inc/sdk";
139
-
140
- const apex = createManagementClient({
141
- projectKey: "your-project-key",
142
- apiKey: process.env.APEX_API_KEY!,
143
- apiUrl: "https://your-apex-instance.com",
144
- });
145
-
146
- const experiments = await apex.listExperiments();
147
- const { variant } = await apex.assignVariant("experiment-id-123", "stable-visitor-id-per-user");
148
-
149
- init({ projectKey: "your-project-key", apiUrl: "https://your-apex-instance.com" });
150
- track("notification_sent", { experimentId: "experiment-id-123", variant });
151
- ```
152
-
153
- `assignVariant` uses a stable **visitor id** per end user (e.g. hashed internal user id) so variant assignment stays deterministic. Pass the same id on every call for that user and experiment.
154
-
155
- ## Shipped skills (AI assistants)
156
-
157
- Cursor-style skills live in **`skills/apex-growth-tracking/SKILL.md`**. Copy that folder into `.cursor/skills/` so your AI assistant gets Apex tracking conventions in context.
158
-
159
- ## How It Works
160
-
161
- Events are queued in memory and flushed in batches to `POST /api/events`. The SDK auto-flushes on a timer, when the queue hits `flushAt`, and on `beforeunload` / `visibilitychange` in browsers.
162
-
163
33
  ## License
164
34
 
165
35
  MIT — see [LICENSE](./LICENSE)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@apex-inc/sdk",
3
- "version": "0.1.0",
4
- "description": "Apex Growth Intelligence SDK — track events, identify users, and run experiments from any JavaScript runtime.",
3
+ "version": "0.1.1",
4
+ "description": "Event tracking and identity SDK for Apex — currently in private beta.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -17,12 +17,8 @@
17
17
  "build": "tsc && tsc -p tsconfig.esm.json",
18
18
  "dev": "tsc --watch"
19
19
  },
20
- "keywords": ["apex", "growth", "analytics", "experiments", "ab-testing", "sdk"],
20
+ "keywords": ["apex", "sdk"],
21
21
  "license": "MIT",
22
- "repository": {
23
- "type": "git",
24
- "url": "https://github.com/apex-inc/sdk"
25
- },
26
22
  "publishConfig": {
27
23
  "access": "public"
28
24
  },