@traqio/web 0.5.0 → 0.6.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.
- package/README.md +24 -1
- package/build/analytics.d.ts +28 -0
- package/build/index.cjs +383 -18
- package/build/index.cjs.map +3 -3
- package/build/index.d.ts +49 -0
- package/build/index.js +383 -18
- package/build/index.js.map +3 -3
- package/build/storage.d.ts +6 -0
- package/build/traqio.min.js +1 -1
- package/build/traqio.min.js.map +3 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -130,6 +130,12 @@ Traqio.capture("search_performed", { results: 12 }); // an analytics event, for
|
|
|
130
130
|
defaults to `0.5` (half the loads); `webVitals: { sampleRate: 1 }` measures every load,
|
|
131
131
|
`webVitals: false` none.
|
|
132
132
|
- URLs are stored **without their query string**: tokens and emails live there.
|
|
133
|
+
- **Your own visits** — open your site once with `?traqio_internal=1` at the end of the
|
|
134
|
+
address: from then on that browser's analytics events are flagged as internal traffic
|
|
135
|
+
(on every page and subdomain), left out of the console's figures by default and shown
|
|
136
|
+
under « Internal traffic only ». `?traqio_internal=0` undoes it;
|
|
137
|
+
`Traqio.setInternal(true | false)` does the same from code, `Traqio.isInternal` reads it.
|
|
138
|
+
Conversions (`track()`) are not affected.
|
|
133
139
|
- **User properties** — `Traqio.identify(user.id, { plan: "pro", seats: 12 }, { signup_source: "webinar" })`
|
|
134
140
|
sets the user id and the user's properties: the second object overwrites, the third is
|
|
135
141
|
written only where the user has no value yet. Read them as a breakdown (`user:plan`), a
|
|
@@ -154,7 +160,7 @@ your accounts with their properties. Needs `analytics` at init.
|
|
|
154
160
|
```ts
|
|
155
161
|
Traqio.group("company", account.id, { plan: "enterprise", seats: 40 }); // traits optional
|
|
156
162
|
Traqio.getGroups(); // { company: "acc_42" }
|
|
157
|
-
Traqio.resetGroups(); // on sign-out
|
|
163
|
+
Traqio.resetGroups(); // an account switch; on sign-out, reset() clears them too
|
|
158
164
|
```
|
|
159
165
|
|
|
160
166
|
The type is lowercase (`company`, `workspace`, `team`: a letter, then letters, digits or
|
|
@@ -163,6 +169,23 @@ characters — never an email. Traits follow the identify rules (a 4th argument
|
|
|
163
169
|
what is unset). The same key again with no traits sends nothing new, so calling it on
|
|
164
170
|
every page is free. `forgetMe()` forgets the groups too; an invalid call is ignored.
|
|
165
171
|
|
|
172
|
+
## Alias, sign-out and experiments
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
Traqio.identify("u_123");
|
|
176
|
+
Traqio.alias("guest_8f2c"); // the guest id IS u_123: history and properties merged
|
|
177
|
+
Traqio.reset(); // on sign-out
|
|
178
|
+
Traqio.exposure("paywall_copy", "b"); // $exposure { experiment, variant }
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
`alias(previousId)` merges what THIS browser sent under `previousId` (a guest id, an id
|
|
182
|
+
from before sign-up) into the current user — the current user's properties win; ignored
|
|
183
|
+
without a current user id. A backend (`@traqio/node`, secret key) merges everything.
|
|
184
|
+
`reset()` forgets the user id, the super-properties and the groups and ends the analytics
|
|
185
|
+
session; events already queued keep their user, and the visitor id is kept (it carries the
|
|
186
|
+
attribution). `exposure(experiment, variant, props?)` sends `$exposure`, what the console's
|
|
187
|
+
experiment analysis reads — your site assigns the variant itself.
|
|
188
|
+
|
|
166
189
|
## Frameworks
|
|
167
190
|
|
|
168
191
|
- **React / Next.js** — call `init()` in a `useEffect` of a client component mounted
|
package/build/analytics.d.ts
CHANGED
|
@@ -67,6 +67,7 @@ export interface AnalyticsDeps {
|
|
|
67
67
|
store: KeyValueStore & {
|
|
68
68
|
getSync(key: string): string | null;
|
|
69
69
|
setSync(key: string, value: string): void;
|
|
70
|
+
removeSync(key: string): void;
|
|
70
71
|
};
|
|
71
72
|
endpoint: string;
|
|
72
73
|
sdkKey: string;
|
|
@@ -78,9 +79,27 @@ export interface AnalyticsDeps {
|
|
|
78
79
|
superProps?: () => Traits;
|
|
79
80
|
isDebug: () => boolean;
|
|
80
81
|
isForgotten: () => boolean;
|
|
82
|
+
/** The browser opted itself out as the team's own (`?traqio_internal=1`): batches say so. */
|
|
83
|
+
isInternal?: () => boolean;
|
|
81
84
|
options: AnalyticsOptions;
|
|
82
85
|
}
|
|
83
86
|
export declare const SESSION_KEY = "traq_session";
|
|
87
|
+
/** A user id as the server takes it (alias.ts): trimmed text (or a number) of 1–256 characters, or null. */
|
|
88
|
+
export declare function cleanUserId(v: unknown): string | null;
|
|
89
|
+
/** `exposure()`'s properties — `{ ...props, experiment, variant }`, the two named ones winning — or null to ignore the call. */
|
|
90
|
+
export declare function exposureProps(experiment: unknown, variant: unknown, props?: Record<string, unknown>): Record<string, unknown> | null;
|
|
91
|
+
/**
|
|
92
|
+
* Takes (splices) the next batch off `queue`: the leading events captured under ONE
|
|
93
|
+
* user (`asUser`, else `current`) — entries ride with any batch — and that user. The
|
|
94
|
+
* events keep their stamp, so a requeued batch still knows its user; the request drops it.
|
|
95
|
+
*/
|
|
96
|
+
export declare function takeBatch<T extends {
|
|
97
|
+
kind: string;
|
|
98
|
+
asUser?: string;
|
|
99
|
+
}>(queue: T[], current: string | undefined, max: number): {
|
|
100
|
+
events: T[];
|
|
101
|
+
userId: string | undefined;
|
|
102
|
+
};
|
|
84
103
|
/** 30 minutes without activity end a session — the convention PostHog and GA share. */
|
|
85
104
|
export declare const SESSION_IDLE_MS: number;
|
|
86
105
|
/** The landing's source: the URL's utm_* and click ids, and the referrer when it is another site. */
|
|
@@ -108,6 +127,8 @@ export declare class AnalyticsTracker {
|
|
|
108
127
|
private scrollUrl;
|
|
109
128
|
private errorsThisPage;
|
|
110
129
|
private stopped;
|
|
130
|
+
/** This page is driven by a mail link scanner: every later batch says so (the server keeps it out of the figures). */
|
|
131
|
+
private scanner;
|
|
111
132
|
private readonly rage;
|
|
112
133
|
private vitals;
|
|
113
134
|
private vitalsUrl;
|
|
@@ -123,6 +144,13 @@ export declare class AnalyticsTracker {
|
|
|
123
144
|
identify(userId: string, set: Traits, setOnce: Traits): void;
|
|
124
145
|
/** An account's properties (`group(type, key, traits)`): one entry in the batch. Not activity either. */
|
|
125
146
|
group(groupType: string, groupKey: string, set: Traits, setOnce: Traits): void;
|
|
147
|
+
/** Two ids, one person (`alias(previousId)`): one entry in the batch, under the current user. Not activity. */
|
|
148
|
+
alias(userId: string, previousId: string): void;
|
|
149
|
+
/**
|
|
150
|
+
* Sign-out (`reset()`): what is queued keeps `userId`, the user it was captured
|
|
151
|
+
* under, and the session ends — the next event opens a new one.
|
|
152
|
+
*/
|
|
153
|
+
reset(userId: string | undefined): void;
|
|
126
154
|
/** Records a page view of the current URL. Called by itself on route changes; exposed for routers that need it. */
|
|
127
155
|
pageview(): void;
|
|
128
156
|
/** Sends what is queued. `leaving` = the page is going away: keepalive, so the request outlives it. */
|