@vllnt/convex-analytics 0.1.0 → 0.1.1-canary.879bde1
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/CHANGELOG.md +125 -0
- package/README.md +99 -38
- package/dist/component/crons.js +1 -1
- package/dist/component/crons.js.map +1 -1
- package/dist/component/http.d.ts +5 -0
- package/dist/component/http.d.ts.map +1 -1
- package/dist/component/http.js +76 -21
- package/dist/component/http.js.map +1 -1
- package/dist/component/internal_mutations.js +4 -4
- package/dist/component/internal_mutations.js.map +1 -1
- package/dist/component/mutations.d.ts.map +1 -1
- package/dist/component/mutations.js +28 -13
- package/dist/component/mutations.js.map +1 -1
- package/dist/component/queries.d.ts.map +1 -1
- package/dist/component/queries.js +57 -58
- package/dist/component/queries.js.map +1 -1
- package/dist/component/schema.d.ts +2 -4
- package/dist/component/schema.js +10 -5
- package/dist/component/schema.js.map +1 -1
- package/dist/component/validators.d.ts +27 -0
- package/dist/component/validators.d.ts.map +1 -1
- package/dist/component/validators.js +54 -1
- package/dist/component/validators.js.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/dist/test.d.ts +2 -4
- package/dist/web/index.d.ts +2 -2
- package/dist/web/index.js +2 -2
- package/docs/api-reference.md +132 -0
- package/docs/architecture.md +70 -0
- package/docs/client-sdk.md +249 -0
- package/docs/multi-product.md +69 -0
- package/docs/quick-start.md +115 -0
- package/docs/schema.md +135 -0
- package/docs/web-preset.md +104 -0
- package/llms.txt +37 -0
- package/package.json +39 -27
- package/src/component/crons.ts +1 -1
- package/src/component/http.ts +78 -21
- package/src/component/internal_mutations.ts +5 -5
- package/src/component/mutations.ts +37 -15
- package/src/component/queries.ts +83 -64
- package/src/component/schema.ts +10 -5
- package/src/component/validators.ts +80 -1
- package/src/react/index.tsx +1 -1
- package/src/web/index.ts +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAK,MAAM,eAAe,CAAC;AAE/C,4FAA4F;AAC5F,eAAO,MAAM,eAAe,0SAK3B,CAAC;AAEF,sGAAsG;AACtG,eAAO,MAAM,cAAc,scAAwC,CAAC;AAEpE,oCAAoC;AACpC,eAAO,MAAM,cAAc;;;;;;6BAGzB,CAAC;AAEH,2EAA2E;AAC3E,eAAO,MAAM,cAAc;;;;;;6BAGzB,CAAC;AAEH,4EAA4E;AAC5E,eAAO,MAAM,oBAAoB,mPAIhC,CAAC;AAEF,2FAA2F;AAC3F,eAAO,MAAM,sBAAsB,8TAAgC,CAAC;AAEpE,wCAAwC;AACxC,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;mJAWpB,CAAC;AAEH,oDAAoD;AACpD,eAAO,MAAM,MAAM;;;;;;iCAAqD,CAAC;AAEzE,iDAAiD;AACjD,eAAO,MAAM,eAAe;;;;;;kCAAsD,CAAC;AAEnF,+CAA+C;AAC/C,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;+CAKtB,CAAC;AAEH,mCAAmC;AACnC,eAAO,MAAM,UAAU;;;;;;;;yCAIrB,CAAC;AAEH,qCAAqC;AACrC,eAAO,MAAM,eAAe;;;;;;;;8CAI1B,CAAC;AAEH,iEAAiE;AACjE,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oDAIpB,CAAC;AAEH,8EAA8E;AAC9E,eAAO,MAAM,eAAe;;;;;;iCAAqD,CAAC;AAElF,uFAAuF;AACvF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;qDAK3B,CAAC;AAEH,wEAAwE;AACxE,MAAM,MAAM,kBAAkB,GAC1B,cAAc,GACd,mBAAmB,GACnB,qBAAqB,GACrB,kBAAkB,GAClB,oBAAoB,GACpB,eAAe,GACf,gBAAgB,GAChB,iBAAiB,GACjB,gBAAgB,CAAC;AAErB,0EAA0E;AAC1E,wBAAgB,YAAY,CAC1B,IAAI,EAAE,kBAAkB,EACxB,OAAO,EAAE,MAAM,GACd,WAAW,CAAC;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAE5D;AAED,8EAA8E;AAC9E,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAI7E;AAED,0EAA0E;AAC1E,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAI7E;AAED,mEAAmE;AACnE,wBAAgB,WAAW,CAAC,KAAK,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,GAAG,IAAI,CAGnF;AAED,kEAAkE;AAClE,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAI1E;AAED,wFAAwF;AACxF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAIhE;AAKD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAehE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { v } from "convex/values";
|
|
1
|
+
import { ConvexError, v } from "convex/values";
|
|
2
2
|
/** A single property value — string, number, boolean, or null. No nested objects/arrays. */
|
|
3
3
|
export const scalarValidator = v.union(v.string(), v.number(), v.boolean(), v.null());
|
|
4
4
|
/** Event properties: a flat record of scalar values. The generic, typed default — never `v.any()`. */
|
|
@@ -68,4 +68,57 @@ export const distributionView = v.object({
|
|
|
68
68
|
count: v.number(),
|
|
69
69
|
sum: v.number(),
|
|
70
70
|
});
|
|
71
|
+
/** Typed input error: `ConvexError` whose data is `{ code, message }`. */
|
|
72
|
+
export function invalidInput(code, message) {
|
|
73
|
+
return new ConvexError({ code, message });
|
|
74
|
+
}
|
|
75
|
+
/** Reject an empty string. `undefined` (an omitted optional field) passes. */
|
|
76
|
+
export function assertNonEmpty(field, value) {
|
|
77
|
+
if (value === "") {
|
|
78
|
+
throw invalidInput("EMPTY_STRING", `${field} must not be empty`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** Reject NaN and +/-Infinity epoch-millis values. `undefined` passes. */
|
|
82
|
+
export function assertFiniteTs(field, value) {
|
|
83
|
+
if (value !== undefined && !Number.isFinite(value)) {
|
|
84
|
+
throw invalidInput("INVALID_TIMESTAMP", `${field} must be a finite number`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** Reject non-finite `from` / `to` bounds of an optional range. */
|
|
88
|
+
export function assertRange(range) {
|
|
89
|
+
assertFiniteTs("range.from", range?.from);
|
|
90
|
+
assertFiniteTs("range.to", range?.to);
|
|
91
|
+
}
|
|
92
|
+
/** Reject anything but a positive integer. `undefined` passes. */
|
|
93
|
+
export function assertCount(field, value) {
|
|
94
|
+
if (value !== undefined && !(Number.isInteger(value) && value > 0)) {
|
|
95
|
+
throw invalidInput("INVALID_COUNT", `${field} must be a positive integer`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** Reject a sample rate that is not a finite number in `[0, 1]`. `undefined` passes. */
|
|
99
|
+
export function assertSampleRate(value) {
|
|
100
|
+
if (value !== undefined && !(value >= 0 && value <= 1)) {
|
|
101
|
+
throw invalidInput("INVALID_SAMPLE_RATE", "sampleRate must be a number between 0 and 1");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** Convex field names: 1-1024 printable ASCII characters, not starting with `$` (or empty). */
|
|
105
|
+
const PROP_KEY = /^(?!\$)[\x20-\x7e]{0,1024}$/;
|
|
106
|
+
/**
|
|
107
|
+
* Reject NaN / +/-Infinity numbers and prop keys Convex cannot store (non-ASCII, control
|
|
108
|
+
* characters, leading `$`, over 1024 characters). Convex rejects bad keys before a mutation
|
|
109
|
+
* runs, so the key check matters for callers that validate first, such as the HTTP route.
|
|
110
|
+
*/
|
|
111
|
+
export function assertProps(props) {
|
|
112
|
+
for (const [key, value] of Object.entries(props)) {
|
|
113
|
+
if (!PROP_KEY.test(key)) {
|
|
114
|
+
throw invalidInput("INVALID_PROP_KEY", "props keys must be printable ASCII, at most 1024 characters, and not start with $");
|
|
115
|
+
}
|
|
116
|
+
if (value !== null && typeof value === "object") {
|
|
117
|
+
throw invalidInput("INVALID_PROP_VALUE", `props.${key} must be a scalar, not an object or array`);
|
|
118
|
+
}
|
|
119
|
+
if (typeof value === "number" && !Number.isFinite(value)) {
|
|
120
|
+
throw invalidInput("INVALID_PROP_VALUE", `props.${key} must be a finite number`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
71
124
|
//# sourceMappingURL=validators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAE/C,4FAA4F;AAC5F,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CACpC,CAAC,CAAC,MAAM,EAAE,EACV,CAAC,CAAC,MAAM,EAAE,EACV,CAAC,CAAC,OAAO,EAAE,EACX,CAAC,CAAC,IAAI,EAAE,CACT,CAAC;AAEF,sGAAsG;AACtG,MAAM,CAAC,MAAM,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;QACJ,CAAC;QACD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAChD,MAAM,YAAY,CAAC,oBAAoB,EAAE,SAAS,GAAG,2CAA2C,CAAC,CAAC;QACpG,CAAC;QACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACzD,MAAM,YAAY,CAAC,oBAAoB,EAAE,SAAS,GAAG,0BAA0B,CAAC,CAAC;QACnF,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Thin, tree-shakeable wrappers over `convex/react`'s `useQuery` for the
|
|
5
5
|
* component's **aggregate** read verbs (metric, timeseries, top, uniques).
|
|
6
6
|
* The backend core installs and runs with zero React — these hooks are an
|
|
7
|
-
* opt-in `./react` entry; `react`
|
|
7
|
+
* opt-in `./react` entry; `react` is an optional peer dep.
|
|
8
8
|
*
|
|
9
9
|
* No-leak: aggregates ONLY (no raw events) and every call is scope-gated, so a
|
|
10
10
|
* hook can never surface another scope's rows or a raw event payload on the
|
package/dist/react/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Thin, tree-shakeable wrappers over `convex/react`'s `useQuery` for the
|
|
5
5
|
* component's **aggregate** read verbs (metric, timeseries, top, uniques).
|
|
6
6
|
* The backend core installs and runs with zero React — these hooks are an
|
|
7
|
-
* opt-in `./react` entry; `react`
|
|
7
|
+
* opt-in `./react` entry; `react` is an optional peer dep.
|
|
8
8
|
*
|
|
9
9
|
* No-leak: aggregates ONLY (no raw events) and every call is scope-gated, so a
|
|
10
10
|
* hook can never surface another scope's rows or a raw event payload on the
|
package/dist/test.d.ts
CHANGED
|
@@ -40,8 +40,6 @@ declare const _default: {
|
|
|
40
40
|
}, "required", "dedupeKey" | "name" | "props" | "scope" | "seq" | "sessionRef" | "subjectRef" | "ts" | `props.${string}`>, {
|
|
41
41
|
by_dedupe: ["scope", "dedupeKey", "_creationTime"];
|
|
42
42
|
by_scope_name_ts: ["scope", "name", "ts", "_creationTime"];
|
|
43
|
-
by_scope_session_ts: ["scope", "sessionRef", "ts", "_creationTime"];
|
|
44
|
-
by_scope_subject_ts: ["scope", "subjectRef", "ts", "_creationTime"];
|
|
45
43
|
by_scope_ts: ["scope", "ts", "_creationTime"];
|
|
46
44
|
}, {}, {}>;
|
|
47
45
|
rollups: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
@@ -61,8 +59,8 @@ declare const _default: {
|
|
|
61
59
|
val: import("convex/values").VString<string, "required">;
|
|
62
60
|
count: import("convex/values").VFloat64<number, "required">;
|
|
63
61
|
}, "required", "bucket" | "count" | "dim" | "granularity" | "name" | "scope" | "val">, {
|
|
64
|
-
by_scope_name_dim_val: ["scope", "name", "dim", "val", "_creationTime"];
|
|
65
62
|
by_scope_name_gran_bucket_dim: ["scope", "name", "granularity", "bucket", "dim", "val", "_creationTime"];
|
|
63
|
+
by_scope_name_gran_dim_val_bucket: ["scope", "name", "granularity", "dim", "val", "bucket", "_creationTime"];
|
|
66
64
|
}, {}, {}>;
|
|
67
65
|
subjects: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
68
66
|
eventCount: number;
|
|
@@ -78,6 +76,7 @@ declare const _default: {
|
|
|
78
76
|
eventCount: import("convex/values").VFloat64<number, "required">;
|
|
79
77
|
}, "required", "eventCount" | "firstSeen" | "lastSeen" | "scope" | "subjectRef">, {
|
|
80
78
|
by_scope_firstSeen: ["scope", "firstSeen", "_creationTime"];
|
|
79
|
+
by_scope_lastSeen: ["scope", "lastSeen", "_creationTime"];
|
|
81
80
|
by_scope_subject: ["scope", "subjectRef", "_creationTime"];
|
|
82
81
|
}, {}, {}>;
|
|
83
82
|
sessions: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
@@ -98,7 +97,6 @@ declare const _default: {
|
|
|
98
97
|
eventCount: import("convex/values").VFloat64<number, "required">;
|
|
99
98
|
}, "required", "endTs" | "eventCount" | "lastTs" | "scope" | "sessionRef" | "startTs" | "subjectRef">, {
|
|
100
99
|
by_scope_endTs_lastTs: ["scope", "endTs", "lastTs", "_creationTime"];
|
|
101
|
-
by_scope_lastTs: ["scope", "lastTs", "_creationTime"];
|
|
102
100
|
by_scope_session: ["scope", "sessionRef", "_creationTime"];
|
|
103
101
|
}, {}, {}>;
|
|
104
102
|
scopes: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
package/dist/web/index.d.ts
CHANGED
|
@@ -99,7 +99,7 @@ export interface TrackPageviewOpts {
|
|
|
99
99
|
* Host-side convenience: the component never sees web concepts — this helper
|
|
100
100
|
* just assembles the `{@link webDimensions}`-shaped props and calls
|
|
101
101
|
* `client.track(ctx, "page_view", { props })`. Pair with
|
|
102
|
-
* `dimensions: webDimensions` on the client to get web rollups.
|
|
102
|
+
* `dimensions: [...webDimensions]` on the client to get web rollups.
|
|
103
103
|
*
|
|
104
104
|
* @typeParam C - The `AnalyticsClient` (structural) type.
|
|
105
105
|
* @param client - An `AnalyticsClient` (or compatible) instance.
|
|
@@ -108,7 +108,7 @@ export interface TrackPageviewOpts {
|
|
|
108
108
|
* @returns The `track` result passed through from the client.
|
|
109
109
|
* @example
|
|
110
110
|
* ```ts
|
|
111
|
-
* const analytics = new AnalyticsClient(components.analytics, { dimensions: webDimensions });
|
|
111
|
+
* const analytics = new AnalyticsClient(components.analytics, { dimensions: [...webDimensions] });
|
|
112
112
|
* await trackPageview(analytics, ctx, {
|
|
113
113
|
* path: "/pricing",
|
|
114
114
|
* ua: request.headers.get("user-agent") ?? undefined,
|
package/dist/web/index.js
CHANGED
|
@@ -112,7 +112,7 @@ export function geoFromHeaders(headers) {
|
|
|
112
112
|
* Host-side convenience: the component never sees web concepts — this helper
|
|
113
113
|
* just assembles the `{@link webDimensions}`-shaped props and calls
|
|
114
114
|
* `client.track(ctx, "page_view", { props })`. Pair with
|
|
115
|
-
* `dimensions: webDimensions` on the client to get web rollups.
|
|
115
|
+
* `dimensions: [...webDimensions]` on the client to get web rollups.
|
|
116
116
|
*
|
|
117
117
|
* @typeParam C - The `AnalyticsClient` (structural) type.
|
|
118
118
|
* @param client - An `AnalyticsClient` (or compatible) instance.
|
|
@@ -121,7 +121,7 @@ export function geoFromHeaders(headers) {
|
|
|
121
121
|
* @returns The `track` result passed through from the client.
|
|
122
122
|
* @example
|
|
123
123
|
* ```ts
|
|
124
|
-
* const analytics = new AnalyticsClient(components.analytics, { dimensions: webDimensions });
|
|
124
|
+
* const analytics = new AnalyticsClient(components.analytics, { dimensions: [...webDimensions] });
|
|
125
125
|
* await trackPageview(analytics, ctx, {
|
|
126
126
|
* path: "/pricing",
|
|
127
127
|
* ua: request.headers.get("user-agent") ?? undefined,
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# REST API
|
|
2
|
+
|
|
3
|
+
A lean, generic HTTP surface. Routes are namespaced under the host's chosen `httpPrefix`
|
|
4
|
+
when the component is mounted with one. Every route requires an `x-api-key` header matching
|
|
5
|
+
the JSON-array config at `(scope, "apiKeys")`, compared timing-safe.
|
|
6
|
+
|
|
7
|
+
Mount with `app.use(analytics, { httpPrefix: "/analytics" })`; `/metric` below then means
|
|
8
|
+
`https://<deployment>.convex.site/analytics/metric`. Without `httpPrefix`, these routes are not
|
|
9
|
+
exposed. See [Quick Start](quick-start.md#6-optional-rest-access) for key setup through the
|
|
10
|
+
component's `mutations.configSet` (there is no `AnalyticsClient.configSet` method).
|
|
11
|
+
|
|
12
|
+
Source: `src/component/http.ts` in the package (`packages/convex-analytics/src/component/http.ts`
|
|
13
|
+
in the repository).
|
|
14
|
+
|
|
15
|
+
## Endpoints
|
|
16
|
+
|
|
17
|
+
| Method | Path | Purpose |
|
|
18
|
+
| ------ | ----------- | ------------------- |
|
|
19
|
+
| POST | /track | Ingest an event |
|
|
20
|
+
| GET | /metric | Total count |
|
|
21
|
+
| GET | /top | Dimension breakdown |
|
|
22
|
+
| GET | /timeseries | Bucketed counts |
|
|
23
|
+
| GET | /uniques | DAU / WAU / MAU |
|
|
24
|
+
|
|
25
|
+
## POST /track
|
|
26
|
+
|
|
27
|
+
Ingest one event.
|
|
28
|
+
|
|
29
|
+
**Body** (JSON):
|
|
30
|
+
|
|
31
|
+
| Field | Required | Type | Description |
|
|
32
|
+
| --------------- | -------- | -------- | --------------------------------------------------- |
|
|
33
|
+
| `name` | Yes | string | Event name. |
|
|
34
|
+
| `dimensions` | Yes | string[] | Prop keys to roll up on. |
|
|
35
|
+
| `subjectRef` | No | string | Opaque subject id. |
|
|
36
|
+
| `sessionRef` | No | string | Opaque session id. |
|
|
37
|
+
| `props` | No | object | Flat scalar props. |
|
|
38
|
+
| `ts` | No | number | Event time (epoch ms). |
|
|
39
|
+
| `dedupeKey` | No | string | Idempotency key. |
|
|
40
|
+
| `granularities` | No | string[] | `["minute" \| "hour" \| "day"]`. Default `["day"]`. |
|
|
41
|
+
| `sampleRate` | No | number | `0..1`. |
|
|
42
|
+
| `scope` | No | string | Partition. Default `"default"`. |
|
|
43
|
+
|
|
44
|
+
**Response**: `201` with `{ "result": "tracked" | "dropped" | "duplicate" }`.
|
|
45
|
+
A 201 does not imply storage: inspect `result`. With `sessionRef`, a fixed token bucket per
|
|
46
|
+
`(scope, sessionRef)` refills at 100/minute with capacity 10; exhausted requests return
|
|
47
|
+
`"dropped"` (not HTTP 429). Sampling also returns `"dropped"`. No `sessionRef` means no
|
|
48
|
+
session rate-limit check.
|
|
49
|
+
|
|
50
|
+
## GET /metric
|
|
51
|
+
|
|
52
|
+
| Param | Required | Description |
|
|
53
|
+
| ------------ | -------- | ------------------------------------------------------- |
|
|
54
|
+
| `name` | Yes | Event name. |
|
|
55
|
+
| `from`, `to` | No | Range bounds (epoch ms). |
|
|
56
|
+
| `dim`, `val` | No | Filter to one dimension value (both required together). |
|
|
57
|
+
| `scope` | No | Partition. |
|
|
58
|
+
|
|
59
|
+
**Response**: `{ "name": "...", "count": N }`.
|
|
60
|
+
|
|
61
|
+
## GET /top
|
|
62
|
+
|
|
63
|
+
| Param | Required | Description |
|
|
64
|
+
| ------------ | -------- | ------------------------------- |
|
|
65
|
+
| `name` | Yes | Event name. |
|
|
66
|
+
| `dimension` | Yes | Dimension key to break down by. |
|
|
67
|
+
| `from`, `to` | No | Range bounds (epoch ms). |
|
|
68
|
+
| `limit` | No | Max rows (default 20, max 100). |
|
|
69
|
+
| `scope` | No | Partition. |
|
|
70
|
+
|
|
71
|
+
**Response**: `[{ "value": "...", "count": N }, ...]`.
|
|
72
|
+
|
|
73
|
+
## GET /timeseries
|
|
74
|
+
|
|
75
|
+
| Param | Required | Description |
|
|
76
|
+
| ------------- | -------- | -------------------------------------------- |
|
|
77
|
+
| `name` | Yes | Event name. |
|
|
78
|
+
| `granularity` | No | `minute` \| `hour` \| `day` (default `day`). |
|
|
79
|
+
| `from`, `to` | No | Range bounds (epoch ms). |
|
|
80
|
+
| `scope` | No | Partition. |
|
|
81
|
+
|
|
82
|
+
**Response**: `[{ "bucket": N, "count": N }, ...]`.
|
|
83
|
+
|
|
84
|
+
## GET /uniques
|
|
85
|
+
|
|
86
|
+
| Param | Required | Description |
|
|
87
|
+
| ------------- | -------- | -------------------------------------------- |
|
|
88
|
+
| `granularity` | No | `minute` \| `hour` \| `day` (default `day`). |
|
|
89
|
+
| `from`, `to` | No | Range bounds (epoch ms). |
|
|
90
|
+
| `scope` | No | Partition. |
|
|
91
|
+
|
|
92
|
+
**Response**: `{ "dau": N, "wau": N, "mau": N, "trend": [{ "bucket": N, "uniques": N }] }`.
|
|
93
|
+
|
|
94
|
+
## Auth & errors
|
|
95
|
+
|
|
96
|
+
- Configure keys by writing a JSON string array to config `(scope, "apiKeys")` (the `apiKeys` config key).
|
|
97
|
+
- Missing or invalid key → `401 { "error": "..." }`.
|
|
98
|
+
- Invalid input returns `400`. Typed errors from the table below (for example a non-numeric
|
|
99
|
+
`from`, `to`, or `limit`, nested or array `props` values, prop keys Convex cannot store)
|
|
100
|
+
return `{ "error": "...", "code": "..." }`. Checks done in the route itself return
|
|
101
|
+
`{ "error": "..." }` without `code`: a body that is not a JSON object, invalid JSON, missing
|
|
102
|
+
`name` / `dimensions` or a required query parameter, `dimensions` that is not a string array,
|
|
103
|
+
`props` that is not an object, and unknown `granularities` / `granularity`.
|
|
104
|
+
Any other failure (for example a Convex argument-validator error) still fails the action.
|
|
105
|
+
- A stored `apiKeys` value that is not a JSON array of strings returns `500 { "error": "API keys
|
|
106
|
+
misconfigured" }`.
|
|
107
|
+
|
|
108
|
+
## Input errors
|
|
109
|
+
|
|
110
|
+
Mutations and queries reject clearly invalid input with a `ConvexError` whose data is
|
|
111
|
+
`{ code, message }`. Catch it and branch on `code`:
|
|
112
|
+
|
|
113
|
+
| Code | Raised when |
|
|
114
|
+
| --------------------- | ------------------------------------------------------------------------------------------------- |
|
|
115
|
+
| `EMPTY_STRING` | `scope`, `name`, `subjectRef`, `sessionRef`, `dedupeKey`, a dimension, or a config `key` is `""`. |
|
|
116
|
+
| `INVALID_TIMESTAMP` | `ts`, or a range `from` / `to`, is `NaN` or infinite. |
|
|
117
|
+
| `INVALID_SAMPLE_RATE` | `sampleRate` is not a number from 0 to 1. |
|
|
118
|
+
| `INVALID_PROP_VALUE` | A prop is `NaN`, infinite, an object, or an array. |
|
|
119
|
+
| `INVALID_PROP_KEY` | A prop key is not printable ASCII, is over 1024 characters, or starts with `$` (HTTP). |
|
|
120
|
+
| `INVALID_COUNT` | `limit`, `periods`, or `numItems` is not a positive integer. |
|
|
121
|
+
| `INVALID_CURSOR` | A `list` cursor is not one returned by `list`. |
|
|
122
|
+
| `INVALID_BUCKETS` | A `distribution` bucket bound is `NaN` or infinite. |
|
|
123
|
+
| `INVALID_CONFIG` | `retentionDays` or `sessionIdleMs` is not a positive finite number. |
|
|
124
|
+
|
|
125
|
+
Everything the component stores comes from the host: `props`, `subjectRef`, and so on are
|
|
126
|
+
stored as given, and the component never logs event data. Keep personal data (emails, IP
|
|
127
|
+
addresses, tokens in URLs) out of `props` and refs; hash or omit it before calling `track`.
|
|
128
|
+
|
|
129
|
+
> `funnel`, `retention`, and raw `list` are exposed through the client SDK and component
|
|
130
|
+
> functions, not the REST surface. The earlier web-locked routes (events/count/summary,
|
|
131
|
+
> funnel, retention, breakdown, attribution, lifecycle, stickiness, live, search, user,
|
|
132
|
+
> session, GDPR delete, alias, schemas, config) no longer exist.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Architecture
|
|
2
|
+
|
|
3
|
+
## Write path — rollup-on-write
|
|
4
|
+
|
|
5
|
+
`track` aggregates as the event lands (no rollup lag). Unfiltered lifetime metrics read a
|
|
6
|
+
fixed-shard counter; ranged/filtered metrics, top values, and time series scan matching rollup
|
|
7
|
+
rows. They avoid raw-event scans but are not generally O(1).
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
track(ctx, name, opts)
|
|
11
|
+
|
|
|
12
|
+
+- 1. Rate limit (when sessionRef set: per-session token bucket) -> "dropped" if over
|
|
13
|
+
|
|
|
14
|
+
+- 2. Sampling (when sampleRate < 1) -> "dropped" for the sampled-out fraction
|
|
15
|
+
|
|
|
16
|
+
+- 3. Dedupe (when dedupeKey set + already exists in scope) -> "duplicate"
|
|
17
|
+
|
|
|
18
|
+
+- 4. Register the scope in `scopes` (first event only), insert raw event
|
|
19
|
+
| (seq derived from session.eventCount)
|
|
20
|
+
|
|
|
21
|
+
+- 5. Upsert session (when sessionRef set)
|
|
22
|
+
|
|
|
23
|
+
+- 6. Upsert subject (when subjectRef set: firstSeen/lastSeen/eventCount)
|
|
24
|
+
|
|
|
25
|
+
+- 7. Rollup-on-write: for each granularity bucket, increment the total row
|
|
26
|
+
| and one row per host-declared dimension present in props
|
|
27
|
+
|
|
|
28
|
+
+- 8. Sharded counter increment (keyed by (scope, name))
|
|
29
|
+
|
|
|
30
|
+
+- return "tracked"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Reads come straight from the pre-aggregated `rollups` table (or the sharded counter for an
|
|
34
|
+
unbounded total) — `metric`, `top`, and `timeseries` never scan raw events. `funnel`,
|
|
35
|
+
`distribution`, and `list` read the `events` table; `retention` and `uniques` read `subjects`.
|
|
36
|
+
|
|
37
|
+
## Child components
|
|
38
|
+
|
|
39
|
+
| Component | Package | Role |
|
|
40
|
+
| -------------- | ----------------------------- | -------------------------------------------------- |
|
|
41
|
+
| aggregate | `@convex-dev/aggregate` | Mounted for compatibility; not written or read. |
|
|
42
|
+
| shardedCounter | `@convex-dev/sharded-counter` | O(1) total per `(scope, name)` (16 shards). |
|
|
43
|
+
| rateLimiter | `@convex-dev/rate-limiter` | Per-`sessionRef` token bucket (100/min, burst 10). |
|
|
44
|
+
|
|
45
|
+
Mounted in `convex.config.ts`:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
const component = defineComponent("analytics");
|
|
49
|
+
component.use(aggregate);
|
|
50
|
+
component.use(shardedCounter);
|
|
51
|
+
component.use(rateLimiter);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Crons
|
|
55
|
+
|
|
56
|
+
Both run inside the component, are idempotent, and visit every scope in the `scopes` table.
|
|
57
|
+
|
|
58
|
+
| Cron | Schedule | What it does |
|
|
59
|
+
| --------------- | -------- | ----------------------------------------------------------------------------------------------- |
|
|
60
|
+
| `prune` | 24 hours | Deletes raw events older than `retentionDays` per scope (rollups kept forever). Capped per run. |
|
|
61
|
+
| `closeSessions` | 30 min | Sets `endTs` on sessions idle past `sessionIdleMs`. |
|
|
62
|
+
|
|
63
|
+
`backfill` is a non-cron internal mutation that re-derives a `(scope, name)`'s rollups from
|
|
64
|
+
the retained raw events — useful after changing dimensions.
|
|
65
|
+
|
|
66
|
+
## Isolation
|
|
67
|
+
|
|
68
|
+
Tables are sandboxed: the host reaches them only through the exported functions. The
|
|
69
|
+
component never reads host or sibling tables. Host data enters only as opaque strings
|
|
70
|
+
(`subjectRef`, `sessionRef`) or host-typed scalar `props` — never `v.any()`.
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# Client SDK
|
|
2
|
+
|
|
3
|
+
TypeScript API reference for the `AnalyticsClient<TProps>` class.
|
|
4
|
+
|
|
5
|
+
Source: `src/client/index.ts` in the package (`packages/convex-analytics/src/client/index.ts`
|
|
6
|
+
in the repository).
|
|
7
|
+
|
|
8
|
+
## Constructor
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
new AnalyticsClient<TProps>(component: unknown, config?: AnalyticsConfig)
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
`component` comes from `components.analytics` after mounting. `TProps` types the `props`
|
|
15
|
+
passed to `track` (defaults to `Record<string, Scalar>`). This is compile-time typing;
|
|
16
|
+
validate untrusted input in host functions. There is no `propsValidator` constructor option.
|
|
17
|
+
|
|
18
|
+
### AnalyticsConfig
|
|
19
|
+
|
|
20
|
+
Stored on the client and applied to every call. All optional.
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
interface AnalyticsConfig {
|
|
24
|
+
scope?: string; // default "default"
|
|
25
|
+
dimensions?: string[]; // default []
|
|
26
|
+
granularities?: ("minute" | "hour" | "day")[]; // default ["day"]
|
|
27
|
+
retentionDays?: number; // default 90
|
|
28
|
+
sampleRate?: number; // 0..1, default 1
|
|
29
|
+
sessionIdleMs?: number; // default 1_800_000 (30m)
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
| Option | Default | Applied | Purpose |
|
|
34
|
+
| --------------- | ----------- | --------------- | -------------------------------------------------------------- |
|
|
35
|
+
| `scope` | `"default"` | per call | Multi-tenant partition. Overridable per call via `opts.scope`. |
|
|
36
|
+
| `dimensions` | `[]` | per `track` | Prop keys to roll up on. Empty = count by event name only. |
|
|
37
|
+
| `granularities` | `["day"]` | per `track` | Rollup bucket sizes. `"minute"` for short live windows. |
|
|
38
|
+
| `retentionDays` | `90` | via `configure` | Raw-event TTL in days. Rollups kept forever. |
|
|
39
|
+
| `sampleRate` | `1` | per `track` | Fraction of events kept at ingest. |
|
|
40
|
+
| `sessionIdleMs` | `1_800_000` | via `configure` | Idle timeout before a session is closed. |
|
|
41
|
+
|
|
42
|
+
`top`, and `metric` with a `range` or `where`, read only `day` rollups: if `granularities`
|
|
43
|
+
leaves out `"day"`, they return `[]` and `0`. `timeseries` reads the granularity you ask for.
|
|
44
|
+
|
|
45
|
+
`dimensions`, `granularities`, and `sampleRate` are passed into each `track` call. The
|
|
46
|
+
cron-relevant values (`retentionDays`, `sampleRate`, `sessionIdleMs`) are persisted to the
|
|
47
|
+
`config` table by calling `configure` once.
|
|
48
|
+
|
|
49
|
+
## Mutations
|
|
50
|
+
|
|
51
|
+
### track
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
track(
|
|
55
|
+
ctx: MutationCtx,
|
|
56
|
+
name: string,
|
|
57
|
+
opts?: {
|
|
58
|
+
subjectRef?: string;
|
|
59
|
+
sessionRef?: string;
|
|
60
|
+
props?: TProps;
|
|
61
|
+
ts?: number;
|
|
62
|
+
scope?: string;
|
|
63
|
+
dedupeKey?: string;
|
|
64
|
+
},
|
|
65
|
+
): Promise<"tracked" | "dropped" | "duplicate">
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Ingest one event. Rollup-on-write: increments the total + each host-declared dimension
|
|
69
|
+
present in `props`, writes the raw event, and bumps the sharded counter.
|
|
70
|
+
|
|
71
|
+
- **Rate limit** — when `sessionRef` is set, a token bucket per `(scope, sessionRef)` refills at 100 events/minute with capacity 10; over-limit returns `"dropped"`. These limits are fixed in the component, not configurable through this client. Omitting `sessionRef` bypasses this limiter.
|
|
72
|
+
- **Sampling** — when `sampleRate < 1`, a fraction of events return `"dropped"`.
|
|
73
|
+
- **Dedupe** — when `dedupeKey` is set and an event already exists for it in the scope, returns `"duplicate"`.
|
|
74
|
+
- Otherwise returns `"tracked"`.
|
|
75
|
+
|
|
76
|
+
### configure
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
configure(
|
|
80
|
+
ctx: MutationCtx,
|
|
81
|
+
opts?: {
|
|
82
|
+
retentionDays?: number;
|
|
83
|
+
sampleRate?: number;
|
|
84
|
+
sessionIdleMs?: number;
|
|
85
|
+
scope?: string;
|
|
86
|
+
},
|
|
87
|
+
): Promise<void>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Persist cron-relevant config for the scope so the `prune` and `closeSessions` crons can read
|
|
91
|
+
it. Falls back to the client's constructor config when an option is omitted.
|
|
92
|
+
|
|
93
|
+
## Queries
|
|
94
|
+
|
|
95
|
+
### metric
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
metric(ctx, name, opts?: { range?: Range; where?: Where; scope?: string }): Promise<number>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Total count for an event. With no `range`/`where`, reads the O(1) sharded counter. With a
|
|
102
|
+
range or a `where` filter, sums the matching daily rollup rows.
|
|
103
|
+
|
|
104
|
+
### top
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
top(ctx, name, dimension, opts?: { range?: Range; limit?: number; scope?: string }): Promise<TopRow[]>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Top values of a dimension, ranked by count (default `limit` 20, max 100). Returns
|
|
111
|
+
`{ value, count }[]`.
|
|
112
|
+
|
|
113
|
+
### timeseries
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
timeseries(ctx, name, opts: { granularity: Granularity; range: Range; where?: Where; scope?: string }): Promise<TimeseriesPoint[]>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Bucketed counts. Returns `{ bucket, count }[]` sorted ascending by bucket.
|
|
120
|
+
|
|
121
|
+
### uniques
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
uniques(ctx, opts: { range: Range; granularity: Granularity; scope?: string }): Promise<UniquesView>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Distinct-subject counts. Returns `{ dau, wau, mau, trend }` where `trend` is
|
|
128
|
+
`{ bucket, uniques }[]`.
|
|
129
|
+
|
|
130
|
+
### funnel
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
funnel(ctx, steps: string[], opts: { range: Range; scope?: string }): Promise<FunnelStep[]>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Ordered step conversion, keyed by `subjectRef`. Requires at least 2 steps; scans up to
|
|
137
|
+
10,000 events per step. Returns `{ name, count, rate }[]` (rate relative to the first step).
|
|
138
|
+
|
|
139
|
+
### retention
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
retention(ctx, opts: { cohortRange: Range; periods: number; granularity?: Granularity; scope?: string }): Promise<RetentionCohort[]>
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Cohort return rates by first-seen period (default `granularity` `"day"`, `periods` capped at
|
|
146
|
+
30). Returns `{ cohort, size, retained }[]` where `retained[p]` is the return fraction for
|
|
147
|
+
period `p+1`.
|
|
148
|
+
|
|
149
|
+
### distribution
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
distribution(ctx, name, measure: string, opts: { buckets: number[]; range?: Range; where?: Where; scope?: string }): Promise<DistributionView>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Histogram of a numeric `props` measure. `buckets` are ascending upper bounds; a value falls in
|
|
156
|
+
the first bin whose `upper >= value`, and values above the last bound land in `overflow`.
|
|
157
|
+
Non-numeric measure values are ignored. Returns `{ bins, overflow, count, sum }` (so
|
|
158
|
+
`sum / count` is the mean). Computed from raw events in range (index-backed, bounded).
|
|
159
|
+
|
|
160
|
+
### list
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
list(ctx, name, paginationOpts: { numItems: number; cursor: string | null }, opts?: { scope?: string }): Promise<EventPage>
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Paginated raw events for an event name, newest first. Returns
|
|
167
|
+
`{ page, isDone, continueCursor }`.
|
|
168
|
+
|
|
169
|
+
## Identifying entities
|
|
170
|
+
|
|
171
|
+
The component stores no host id of its own. An "entity" or "instance" you slice by is a value
|
|
172
|
+
in `props` under a dimension you declare — `subjectRef`, `sessionRef`, dimension values, and
|
|
173
|
+
`dedupeKey` are all opaque strings you own.
|
|
174
|
+
|
|
175
|
+
- **One instance** — filter by its dimension value:
|
|
176
|
+
`metric(ctx, "play", { where: { dim: "puzzleId", val: "2026-06-15" } })` or
|
|
177
|
+
`timeseries(ctx, "play", { granularity: "hour", range, where: { dim: "puzzleId", val } })`.
|
|
178
|
+
- **Across instances (last N)** — break down by the dimension:
|
|
179
|
+
`top(ctx, "play", "puzzleId", { limit: 30 })`.
|
|
180
|
+
- **Once per outcome** — pass your own `dedupeKey` (e.g. `` `${puzzleId}:${userId}` ``) to
|
|
181
|
+
`track` so a refresh or retried mutation counts the outcome once.
|
|
182
|
+
|
|
183
|
+
## Types
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
type Scalar = string | number | boolean | null;
|
|
187
|
+
type Props = Record<string, Scalar>;
|
|
188
|
+
type Granularity = "minute" | "hour" | "day";
|
|
189
|
+
|
|
190
|
+
interface Range {
|
|
191
|
+
from?: number;
|
|
192
|
+
to?: number;
|
|
193
|
+
} // epoch ms
|
|
194
|
+
interface Where {
|
|
195
|
+
dim: string;
|
|
196
|
+
val: Scalar;
|
|
197
|
+
} // one dimension == one value
|
|
198
|
+
interface TopRow {
|
|
199
|
+
value: string;
|
|
200
|
+
count: number;
|
|
201
|
+
}
|
|
202
|
+
interface TimeseriesPoint {
|
|
203
|
+
bucket: number;
|
|
204
|
+
count: number;
|
|
205
|
+
}
|
|
206
|
+
interface UniquesView {
|
|
207
|
+
dau: number;
|
|
208
|
+
wau: number;
|
|
209
|
+
mau: number;
|
|
210
|
+
trend: Array<{ bucket: number; uniques: number }>;
|
|
211
|
+
}
|
|
212
|
+
interface FunnelStep {
|
|
213
|
+
name: string;
|
|
214
|
+
count: number;
|
|
215
|
+
rate: number;
|
|
216
|
+
}
|
|
217
|
+
interface RetentionCohort {
|
|
218
|
+
cohort: number;
|
|
219
|
+
size: number;
|
|
220
|
+
retained: number[];
|
|
221
|
+
}
|
|
222
|
+
interface DistributionBin {
|
|
223
|
+
upper: number;
|
|
224
|
+
count: number;
|
|
225
|
+
}
|
|
226
|
+
interface DistributionView {
|
|
227
|
+
bins: DistributionBin[];
|
|
228
|
+
overflow: number;
|
|
229
|
+
count: number;
|
|
230
|
+
sum: number;
|
|
231
|
+
}
|
|
232
|
+
interface EventView {
|
|
233
|
+
_id: string;
|
|
234
|
+
_creationTime: number;
|
|
235
|
+
scope: string;
|
|
236
|
+
name: string;
|
|
237
|
+
subjectRef?: string;
|
|
238
|
+
sessionRef?: string;
|
|
239
|
+
props: Props;
|
|
240
|
+
ts: number;
|
|
241
|
+
seq: number;
|
|
242
|
+
dedupeKey?: string;
|
|
243
|
+
}
|
|
244
|
+
interface EventPage {
|
|
245
|
+
page: EventView[];
|
|
246
|
+
isDone: boolean;
|
|
247
|
+
continueCursor: string;
|
|
248
|
+
}
|
|
249
|
+
```
|