@traqio/web 0.4.1 → 0.6.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/README.md +63 -3
- package/build/analytics.d.ts +102 -0
- package/build/index.cjs +990 -31
- package/build/index.cjs.map +4 -4
- package/build/index.d.ts +111 -7
- package/build/index.js +990 -31
- package/build/index.js.map +4 -4
- package/build/storage.d.ts +6 -0
- package/build/traqio.min.js +1 -1
- package/build/traqio.min.js.map +4 -4
- package/build/vitals.d.ts +58 -0
- package/package.json +2 -2
package/build/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type WebSource } from "./source";
|
|
2
|
-
import { type AnalyticsOptions } from "./analytics";
|
|
2
|
+
import { type AnalyticsOptions, type Groups, type Traits } from "./analytics";
|
|
3
3
|
export type { WebSource } from "./source";
|
|
4
|
-
export type { AnalyticsOptions } from "./analytics";
|
|
4
|
+
export type { AnalyticsOptions, Groups, Traits, TraitValue } from "./analytics";
|
|
5
|
+
export type { WebVitalsOptions } from "./vitals";
|
|
5
6
|
export declare const DEFAULT_ENDPOINT = "https://api.traqio.app";
|
|
6
7
|
export interface WebInitOptions {
|
|
7
8
|
/** The site's WEB key (`tq_web_…`), from the console. Public by design: it is held to the site's origins. */
|
|
@@ -33,15 +34,17 @@ export interface WebInitOptions {
|
|
|
33
34
|
/**
|
|
34
35
|
* Debug mode. Omitted = on when the page is served from your machine (`localhost`,
|
|
35
36
|
* `127.0.0.1`, `*.localhost`, `*.local`, `file:`), off everywhere else. Debug
|
|
36
|
-
* traffic shows in the console's Live events › Debug view
|
|
37
|
+
* traffic shows in the console's Live events › Debug view (its analytics events in
|
|
38
|
+
* Analytics › Realtime › Debug, kept 24 h) and is never counted,
|
|
37
39
|
* attributed, sent to an ad network or a webhook, or billed. `true` for a staging
|
|
38
40
|
* site, `false` to count a local page.
|
|
39
41
|
*/
|
|
40
42
|
debug?: boolean;
|
|
41
43
|
/**
|
|
42
|
-
* Product analytics — page views (route changes included), clicks,
|
|
43
|
-
* front-end errors
|
|
44
|
-
*
|
|
44
|
+
* Product analytics — page views (route changes included), clicks, rage clicks,
|
|
45
|
+
* scroll depth, front-end errors and the Core Web Vitals of a sample of page loads,
|
|
46
|
+
* read in the console's Analytics section. `true` turns them all on; an object picks
|
|
47
|
+
* (`{ webVitals: { sampleRate: 0.1 } }`). Default off. Never billed and never sent to an ad network:
|
|
45
48
|
* analytics events have their own route and table, apart from conversions.
|
|
46
49
|
*/
|
|
47
50
|
analytics?: boolean | AnalyticsOptions;
|
|
@@ -56,6 +59,11 @@ export interface WebTrackProps {
|
|
|
56
59
|
/** Where the payment went through — `"stripe"` for Stripe. */
|
|
57
60
|
store?: "stripe" | "app_store" | "play_store" | "mac_app_store" | "amazon";
|
|
58
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* `traqio_internal` in a URL's query: `1`/`true` → true, `0`/`false` → false, absent or
|
|
64
|
+
* anything else → null (left as it was).
|
|
65
|
+
*/
|
|
66
|
+
export declare function internalParam(href: string): boolean | null;
|
|
59
67
|
export declare class TraqioWeb {
|
|
60
68
|
private readonly core;
|
|
61
69
|
private store;
|
|
@@ -71,6 +79,18 @@ export declare class TraqioWeb {
|
|
|
71
79
|
private earlyCaptures;
|
|
72
80
|
/** `init()` has finished (or will never run here): early captures are no longer kept. */
|
|
73
81
|
private ready;
|
|
82
|
+
/** `register()`: properties added to every analytics event, kept in `traq_super`. */
|
|
83
|
+
private superProps;
|
|
84
|
+
/** `identify()` calls with traits made before `init()` — replayed once the tracker exists. */
|
|
85
|
+
private earlyIdentifies;
|
|
86
|
+
/** `group()`: the accounts every analytics event is stamped with, kept in `traq_groups`. */
|
|
87
|
+
private groups;
|
|
88
|
+
/** Group entries made before `init()` — replayed once the tracker exists. */
|
|
89
|
+
private earlyGroups;
|
|
90
|
+
/** `alias()` calls made before `init()`: [userId, previousId]. */
|
|
91
|
+
private earlyAliases;
|
|
92
|
+
/** A `reset()` before `init()`: what earlier pages kept (super-properties, accounts) is dropped, not restored. */
|
|
93
|
+
private resetBeforeInit;
|
|
74
94
|
/**
|
|
75
95
|
* Call once, as early as possible on every page (or once in a single-page app).
|
|
76
96
|
* Reads the trackID from the current URL first, synchronously, so even a visitor
|
|
@@ -78,6 +98,16 @@ export declare class TraqioWeb {
|
|
|
78
98
|
* does nothing there.
|
|
79
99
|
*/
|
|
80
100
|
init(opts: WebInitOptions): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Mark this browser as the team's own (`true`) or as a visitor again (`false`) — what
|
|
103
|
+
* opening the site with `?traqio_internal=1` / `=0` does. Its analytics events are
|
|
104
|
+
* still sent, flagged: the console leaves them out of every figure by default and
|
|
105
|
+
* shows them under « Internal traffic only ». Conversions (`track()`) are not
|
|
106
|
+
* affected. Kept on the device, like the visitor id (and under the same consent).
|
|
107
|
+
*/
|
|
108
|
+
setInternal(on: boolean): void;
|
|
109
|
+
/** True when this browser opted itself out as internal traffic — see `setInternal()`. */
|
|
110
|
+
get isInternal(): boolean;
|
|
81
111
|
/** Whether this page runs in debug mode — see `WebInitOptions.debug`. Settled by `init()`. */
|
|
82
112
|
get isDebug(): boolean;
|
|
83
113
|
/** Record an event — `signup`, `purchase`, `add_to_cart`… Batched, retried, kept across page loads. */
|
|
@@ -86,7 +116,8 @@ export declare class TraqioWeb {
|
|
|
86
116
|
* A product-analytics event — `search_performed`, `pricing_toggled`… — read in the
|
|
87
117
|
* console's Analytics section (events, funnels). NOT a conversion: it is never
|
|
88
118
|
* billed nor sent to an ad network. A conversion (sign-up, purchase) is `track()`.
|
|
89
|
-
* Needs `analytics` at init; names starting with `$` are reserved
|
|
119
|
+
* Needs `analytics` at init; names starting with `$` are reserved, but for an
|
|
120
|
+
* experiment exposure: `capture("$exposure", { experiment, variant })`.
|
|
90
121
|
*/
|
|
91
122
|
capture(name: string, props?: Record<string, unknown>): void;
|
|
92
123
|
/**
|
|
@@ -96,6 +127,79 @@ export declare class TraqioWeb {
|
|
|
96
127
|
pageview(): void;
|
|
97
128
|
/** Set the user id once known (after sign-in). */
|
|
98
129
|
setUserId(id: string): void;
|
|
130
|
+
/**
|
|
131
|
+
* Who the user is, and what they are: sets the user id (like `setUserId`) and, with
|
|
132
|
+
* traits, the user's PROPERTIES — `plan`, `role`, `company_size` — read in the
|
|
133
|
+
* console as a breakdown, a report dimension and a cohort condition. Needs
|
|
134
|
+
* `analytics` at init for the traits.
|
|
135
|
+
*
|
|
136
|
+
* Traqio.identify("u_123", { plan: "pro", seats: 12 }, { signup_source: "webinar" });
|
|
137
|
+
*
|
|
138
|
+
* `traits` overwrite what was set before; `traitsOnce` are written only where the
|
|
139
|
+
* user has no value yet. Text, numbers, booleans — never an email or a name. At most 50 keys.
|
|
140
|
+
*/
|
|
141
|
+
identify(userId: string, traits?: Record<string, unknown>, traitsOnce?: Record<string, unknown>): void;
|
|
142
|
+
/**
|
|
143
|
+
* Super-properties: added to EVERY analytics event from now on, on this page and the
|
|
144
|
+
* next ones — an A/B arm, a pricing variant, a theme. An event's own property of the
|
|
145
|
+
* same name wins. Kept with the visitor id (same consent rules). `unregister(key)` removes one.
|
|
146
|
+
*
|
|
147
|
+
* Traqio.register({ pricing_variant: "b" });
|
|
148
|
+
*/
|
|
149
|
+
register(props: Record<string, unknown>): void;
|
|
150
|
+
/** Stop adding one super-property to the events. */
|
|
151
|
+
unregister(key: string): void;
|
|
152
|
+
/** The super-properties `register()` set — a copy. */
|
|
153
|
+
getSuperProperties(): Traits;
|
|
154
|
+
/**
|
|
155
|
+
* The B2B ACCOUNT the visitor works in (group analytics): every analytics event from
|
|
156
|
+
* now on — on this page and the next ones — counts for it, so the console can count
|
|
157
|
+
* accounts (unique accounts, funnels, retention, cohorts « by company ») and list them
|
|
158
|
+
* with their traits. Call it after sign-in, and again on an account switch. Needs
|
|
159
|
+
* `analytics` at init.
|
|
160
|
+
*
|
|
161
|
+
* Traqio.group("company", "acc_42", { plan: "enterprise", seats: 40 });
|
|
162
|
+
*
|
|
163
|
+
* `groupType` is lowercase (`company`, `workspace`; 5 types at most), `groupKey` your
|
|
164
|
+
* own account id — never an email. Traits follow identify's rules.
|
|
165
|
+
*/
|
|
166
|
+
group(groupType: string, groupKey: string | number, traits?: Record<string, unknown>, traitsOnce?: Record<string, unknown>): void;
|
|
167
|
+
/** Stop stamping the events with any account — call it on sign-out. */
|
|
168
|
+
resetGroups(): void;
|
|
169
|
+
/** The accounts `group()` set, by type — a copy. */
|
|
170
|
+
getGroups(): Groups;
|
|
171
|
+
/**
|
|
172
|
+
* Two ids, one person: the user known so far as `previousId` (a guest id, an id
|
|
173
|
+
* from before sign-up) IS the current user (`setUserId` / `identify`). Their
|
|
174
|
+
* analytics history and properties are merged under the current id — its own
|
|
175
|
+
* properties win. From the browser only what THIS visitor sent under `previousId`
|
|
176
|
+
* is merged; a backend (`@traqio/node`, secret key) merges everything.
|
|
177
|
+
*
|
|
178
|
+
* Traqio.identify("u_123");
|
|
179
|
+
* Traqio.alias("guest_8f2c");
|
|
180
|
+
*
|
|
181
|
+
* Ignored without a current user id, or when `previousId` is the current one. Needs `analytics` at init.
|
|
182
|
+
*/
|
|
183
|
+
alias(previousId: string): void;
|
|
184
|
+
/**
|
|
185
|
+
* Sign-out: forget who the user was in this browser — the user id, the
|
|
186
|
+
* super-properties, the accounts — and end the analytics session, so the next
|
|
187
|
+
* person's visit starts clean. Events already queued keep the user they were
|
|
188
|
+
* captured under. The visitor id is KEPT: it carries the visitor's attribution
|
|
189
|
+
* (the click, the campaign) for the next sign-up.
|
|
190
|
+
*/
|
|
191
|
+
reset(): void;
|
|
192
|
+
/**
|
|
193
|
+
* An experiment exposure: the visitor SAW `variant` of `experiment` — what the
|
|
194
|
+
* console's experiment analysis reads (uplift, significance per variant). Your site
|
|
195
|
+
* assigns the variant (its own flags, an edge split, a cookie); call this where the
|
|
196
|
+
* visitor first meets it. Sends `$exposure { experiment, variant, ...props }`.
|
|
197
|
+
*
|
|
198
|
+
* Traqio.exposure("pricing_page", "annual_first");
|
|
199
|
+
*/
|
|
200
|
+
exposure(experiment: string, variant: string | number | boolean, props?: Record<string, unknown>): void;
|
|
201
|
+
private persistGroups;
|
|
202
|
+
private persistSuperProps;
|
|
99
203
|
/**
|
|
100
204
|
* The visitor's consent answer. Governs sharing with ad networks, and — with
|
|
101
205
|
* `waitForConsent` — whether anything may be stored: `true` writes out what the
|