@vllnt/analytics 0.1.1 → 0.2.0-canary.8064ae0
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 +48 -0
- package/README.md +99 -61
- package/dist/analytics-DdAxcZwX.d.cts +166 -0
- package/dist/analytics-DdAxcZwX.d.ts +166 -0
- package/dist/chunk-6RHY2BTB.js +256 -0
- package/dist/chunk-MVOBIOKZ.cjs +256 -0
- package/dist/index.cjs +62 -0
- package/dist/index.d.cts +55 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +62 -0
- package/dist/react.cjs +166 -0
- package/dist/react.d.cts +33 -0
- package/dist/react.d.ts +33 -0
- package/dist/react.js +166 -0
- package/docs/API.md +384 -0
- package/llms.txt +56 -0
- package/package.json +69 -34
- package/src/analytics.ts +12 -35
- package/src/consent.ts +5 -1
package/src/analytics.ts
CHANGED
|
@@ -49,18 +49,11 @@ function debugLog(type: string, data: unknown): void {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
52
|
+
* Central tracking point. The library has no transport: events are only
|
|
53
|
+
* logged in debug mode and are not sent anywhere.
|
|
54
54
|
*/
|
|
55
55
|
function sendEvent(name: string, properties?: Record<string, unknown>): void {
|
|
56
56
|
debugLog("track", { name, properties });
|
|
57
|
-
|
|
58
|
-
// Integration point: Forward to Vercel Analytics or other services
|
|
59
|
-
// Vercel Analytics integration is handled by the React provider
|
|
60
|
-
// This function serves as the central tracking point
|
|
61
|
-
|
|
62
|
-
// For custom backends, you could send to an API endpoint:
|
|
63
|
-
// fetch('/api/analytics', { method: 'POST', body: JSON.stringify({ name, properties }) })
|
|
64
57
|
}
|
|
65
58
|
|
|
66
59
|
/**
|
|
@@ -118,13 +111,14 @@ function processQueue(): void {
|
|
|
118
111
|
}
|
|
119
112
|
|
|
120
113
|
/**
|
|
121
|
-
* Track a custom event
|
|
114
|
+
* Track a custom event. Events with an empty or non-string name are ignored.
|
|
122
115
|
*/
|
|
123
116
|
export function track(
|
|
124
117
|
name: string,
|
|
125
118
|
properties?: Record<string, unknown>,
|
|
126
119
|
): void {
|
|
127
120
|
if (typeof window === "undefined") return;
|
|
121
|
+
if (typeof name !== "string" || name === "") return;
|
|
128
122
|
|
|
129
123
|
if (isBlocked) return;
|
|
130
124
|
|
|
@@ -162,13 +156,14 @@ export function trackPage(properties?: Record<string, unknown>): void {
|
|
|
162
156
|
}
|
|
163
157
|
|
|
164
158
|
/**
|
|
165
|
-
* Identify a user
|
|
159
|
+
* Identify a user. An empty or non-string user id is ignored.
|
|
166
160
|
*/
|
|
167
161
|
export function identify(
|
|
168
162
|
userId: string,
|
|
169
163
|
traits?: Record<string, unknown>,
|
|
170
164
|
): void {
|
|
171
165
|
if (typeof window === "undefined") return;
|
|
166
|
+
if (typeof userId !== "string" || userId === "") return;
|
|
172
167
|
if (isBlocked) return;
|
|
173
168
|
|
|
174
169
|
if (!isInitialized || !analyticsState) {
|
|
@@ -238,20 +233,14 @@ export function getAnalyticsState(): AnalyticsState | undefined {
|
|
|
238
233
|
export function trackTutorialStart(
|
|
239
234
|
properties: Omit<TutorialEventProperties, "section_id">,
|
|
240
235
|
): void {
|
|
241
|
-
track(
|
|
242
|
-
"tutorial_start" satisfies TutorialEventName,
|
|
243
|
-
properties as Record<string, unknown>,
|
|
244
|
-
);
|
|
236
|
+
track("tutorial_start" satisfies TutorialEventName, properties);
|
|
245
237
|
}
|
|
246
238
|
|
|
247
239
|
/**
|
|
248
240
|
* Track section view
|
|
249
241
|
*/
|
|
250
242
|
export function trackSectionView(properties: TutorialEventProperties): void {
|
|
251
|
-
track(
|
|
252
|
-
"tutorial_section_view" satisfies TutorialEventName,
|
|
253
|
-
properties as Record<string, unknown>,
|
|
254
|
-
);
|
|
243
|
+
track("tutorial_section_view" satisfies TutorialEventName, properties);
|
|
255
244
|
}
|
|
256
245
|
|
|
257
246
|
/**
|
|
@@ -260,10 +249,7 @@ export function trackSectionView(properties: TutorialEventProperties): void {
|
|
|
260
249
|
export function trackSectionComplete(
|
|
261
250
|
properties: TutorialEventProperties,
|
|
262
251
|
): void {
|
|
263
|
-
track(
|
|
264
|
-
"tutorial_section_complete" satisfies TutorialEventName,
|
|
265
|
-
properties as Record<string, unknown>,
|
|
266
|
-
);
|
|
252
|
+
track("tutorial_section_complete" satisfies TutorialEventName, properties);
|
|
267
253
|
}
|
|
268
254
|
|
|
269
255
|
/**
|
|
@@ -272,10 +258,7 @@ export function trackSectionComplete(
|
|
|
272
258
|
export function trackTutorialComplete(
|
|
273
259
|
properties: Omit<TutorialEventProperties, "section_id">,
|
|
274
260
|
): void {
|
|
275
|
-
track(
|
|
276
|
-
"tutorial_complete" satisfies TutorialEventName,
|
|
277
|
-
properties as Record<string, unknown>,
|
|
278
|
-
);
|
|
261
|
+
track("tutorial_complete" satisfies TutorialEventName, properties);
|
|
279
262
|
}
|
|
280
263
|
|
|
281
264
|
/**
|
|
@@ -286,10 +269,7 @@ export function trackTutorialNavigation(
|
|
|
286
269
|
navigation_type: "keyboard" | "next" | "prev" | "toc";
|
|
287
270
|
},
|
|
288
271
|
): void {
|
|
289
|
-
track(
|
|
290
|
-
"tutorial_navigation" satisfies TutorialEventName,
|
|
291
|
-
properties as Record<string, unknown>,
|
|
292
|
-
);
|
|
272
|
+
track("tutorial_navigation" satisfies TutorialEventName, properties);
|
|
293
273
|
}
|
|
294
274
|
|
|
295
275
|
/**
|
|
@@ -298,8 +278,5 @@ export function trackTutorialNavigation(
|
|
|
298
278
|
export function trackTimeSpent(
|
|
299
279
|
properties: TutorialEventProperties & { time_spent_seconds: number },
|
|
300
280
|
): void {
|
|
301
|
-
track(
|
|
302
|
-
"tutorial_time_spent" satisfies TutorialEventName,
|
|
303
|
-
properties as Record<string, unknown>,
|
|
304
|
-
);
|
|
281
|
+
track("tutorial_time_spent" satisfies TutorialEventName, properties);
|
|
305
282
|
}
|
package/src/consent.ts
CHANGED
|
@@ -169,7 +169,11 @@ export function isDoNotTrackEnabled(): boolean {
|
|
|
169
169
|
* Get consent from cookie (for SSR)
|
|
170
170
|
*/
|
|
171
171
|
export function getConsentFromCookie(cookieString: string): boolean | null {
|
|
172
|
-
|
|
172
|
+
// Anchor to the start of the string or a cookie separator so that
|
|
173
|
+
// look-alike names such as "evil-vllnt-consent" are not matched.
|
|
174
|
+
const match = new RegExp(`(?:^|;\\s*)${CONSENT_COOKIE_NAME}=([^;]+)`).exec(
|
|
175
|
+
cookieString,
|
|
176
|
+
);
|
|
173
177
|
if (!match) return null;
|
|
174
178
|
return match[1] === "1";
|
|
175
179
|
}
|