@traqio/web 0.4.1 → 0.5.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/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 and is never counted,
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, scroll depth and
43
- * front-end errors, read in the console's Analytics section. `true` turns all four
44
- * on; an object picks. Default off. Never billed and never sent to an ad network:
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;
@@ -71,6 +74,14 @@ export declare class TraqioWeb {
71
74
  private earlyCaptures;
72
75
  /** `init()` has finished (or will never run here): early captures are no longer kept. */
73
76
  private ready;
77
+ /** `register()`: properties added to every analytics event, kept in `traq_super`. */
78
+ private superProps;
79
+ /** `identify()` calls with traits made before `init()` — replayed once the tracker exists. */
80
+ private earlyIdentifies;
81
+ /** `group()`: the accounts every analytics event is stamped with, kept in `traq_groups`. */
82
+ private groups;
83
+ /** Group entries made before `init()` — replayed once the tracker exists. */
84
+ private earlyGroups;
74
85
  /**
75
86
  * Call once, as early as possible on every page (or once in a single-page app).
76
87
  * Reads the trackID from the current URL first, synchronously, so even a visitor
@@ -86,7 +97,8 @@ export declare class TraqioWeb {
86
97
  * A product-analytics event — `search_performed`, `pricing_toggled`… — read in the
87
98
  * console's Analytics section (events, funnels). NOT a conversion: it is never
88
99
  * billed nor sent to an ad network. A conversion (sign-up, purchase) is `track()`.
89
- * Needs `analytics` at init; names starting with `$` are reserved.
100
+ * Needs `analytics` at init; names starting with `$` are reserved, but for an
101
+ * experiment exposure: `capture("$exposure", { experiment, variant })`.
90
102
  */
91
103
  capture(name: string, props?: Record<string, unknown>): void;
92
104
  /**
@@ -96,6 +108,49 @@ export declare class TraqioWeb {
96
108
  pageview(): void;
97
109
  /** Set the user id once known (after sign-in). */
98
110
  setUserId(id: string): void;
111
+ /**
112
+ * Who the user is, and what they are: sets the user id (like `setUserId`) and, with
113
+ * traits, the user's PROPERTIES — `plan`, `role`, `company_size` — read in the
114
+ * console as a breakdown, a report dimension and a cohort condition. Needs
115
+ * `analytics` at init for the traits.
116
+ *
117
+ * Traqio.identify("u_123", { plan: "pro", seats: 12 }, { signup_source: "webinar" });
118
+ *
119
+ * `traits` overwrite what was set before; `traitsOnce` are written only where the
120
+ * user has no value yet. Text, numbers, booleans — never an email or a name. At most 50 keys.
121
+ */
122
+ identify(userId: string, traits?: Record<string, unknown>, traitsOnce?: Record<string, unknown>): void;
123
+ /**
124
+ * Super-properties: added to EVERY analytics event from now on, on this page and the
125
+ * next ones — an A/B arm, a pricing variant, a theme. An event's own property of the
126
+ * same name wins. Kept with the visitor id (same consent rules). `unregister(key)` removes one.
127
+ *
128
+ * Traqio.register({ pricing_variant: "b" });
129
+ */
130
+ register(props: Record<string, unknown>): void;
131
+ /** Stop adding one super-property to the events. */
132
+ unregister(key: string): void;
133
+ /** The super-properties `register()` set — a copy. */
134
+ getSuperProperties(): Traits;
135
+ /**
136
+ * The B2B ACCOUNT the visitor works in (group analytics): every analytics event from
137
+ * now on — on this page and the next ones — counts for it, so the console can count
138
+ * accounts (unique accounts, funnels, retention, cohorts « by company ») and list them
139
+ * with their traits. Call it after sign-in, and again on an account switch. Needs
140
+ * `analytics` at init.
141
+ *
142
+ * Traqio.group("company", "acc_42", { plan: "enterprise", seats: 40 });
143
+ *
144
+ * `groupType` is lowercase (`company`, `workspace`; 5 types at most), `groupKey` your
145
+ * own account id — never an email. Traits follow identify's rules.
146
+ */
147
+ group(groupType: string, groupKey: string | number, traits?: Record<string, unknown>, traitsOnce?: Record<string, unknown>): void;
148
+ /** Stop stamping the events with any account — call it on sign-out. */
149
+ resetGroups(): void;
150
+ /** The accounts `group()` set, by type — a copy. */
151
+ getGroups(): Groups;
152
+ private persistGroups;
153
+ private persistSuperProps;
99
154
  /**
100
155
  * The visitor's consent answer. Governs sharing with ad networks, and — with
101
156
  * `waitForConsent` — whether anything may be stored: `true` writes out what the