@vllnt/analytics 0.2.0-canary.13db137 → 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 +47 -13
- package/docs/API.md +384 -0
- package/llms.txt +56 -0
- package/package.json +15 -6
- package/src/analytics.ts +282 -0
- package/src/consent.ts +179 -0
- package/src/index.ts +48 -0
- package/src/react.tsx +221 -0
- package/src/types.ts +102 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics consent state stored in localStorage
|
|
3
|
+
*/
|
|
4
|
+
export type ConsentState = {
|
|
5
|
+
/** Whether analytics tracking is allowed */
|
|
6
|
+
analytics: boolean;
|
|
7
|
+
/** Whether functional cookies are allowed (always true for site operation) */
|
|
8
|
+
functional: boolean;
|
|
9
|
+
/** ISO timestamp when consent was given */
|
|
10
|
+
timestamp: string;
|
|
11
|
+
/** Version of consent prompt (bump to re-prompt users) */
|
|
12
|
+
version: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Consent categories that can be toggled
|
|
17
|
+
*/
|
|
18
|
+
export type ConsentCategory = "analytics" | "functional";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Tutorial-specific event names
|
|
22
|
+
*/
|
|
23
|
+
export type TutorialEventName =
|
|
24
|
+
| "tutorial_complete"
|
|
25
|
+
| "tutorial_navigation"
|
|
26
|
+
| "tutorial_section_complete"
|
|
27
|
+
| "tutorial_section_view"
|
|
28
|
+
| "tutorial_start"
|
|
29
|
+
| "tutorial_time_spent";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Tutorial event properties
|
|
33
|
+
*/
|
|
34
|
+
export type TutorialEventProperties = {
|
|
35
|
+
/** Completion percentage (0-100) */
|
|
36
|
+
completion_percent?: number;
|
|
37
|
+
/** User's locale */
|
|
38
|
+
locale: string;
|
|
39
|
+
/** Navigation method used */
|
|
40
|
+
navigation_type?: "keyboard" | "next" | "prev" | "toc";
|
|
41
|
+
/** Section identifier */
|
|
42
|
+
section_id?: string;
|
|
43
|
+
/** Section position (0-indexed) */
|
|
44
|
+
section_index?: number;
|
|
45
|
+
/** Time spent in seconds */
|
|
46
|
+
time_spent_seconds?: number;
|
|
47
|
+
/** Total number of sections */
|
|
48
|
+
total_sections?: number;
|
|
49
|
+
/** Unique tutorial identifier (contentId) */
|
|
50
|
+
tutorial_id: string;
|
|
51
|
+
/** Human-readable tutorial title */
|
|
52
|
+
tutorial_title: string;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Generic analytics event
|
|
57
|
+
*/
|
|
58
|
+
export type AnalyticsEvent = {
|
|
59
|
+
name: string;
|
|
60
|
+
properties?: Record<string, unknown>;
|
|
61
|
+
timestamp?: string;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Analytics instance configuration
|
|
66
|
+
*/
|
|
67
|
+
export type AnalyticsConfig = {
|
|
68
|
+
/** Application name for analytics */
|
|
69
|
+
app: string;
|
|
70
|
+
/** Enable debug mode */
|
|
71
|
+
debug?: boolean;
|
|
72
|
+
/** Application version */
|
|
73
|
+
version?: number;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Hook options for useConsent
|
|
78
|
+
*/
|
|
79
|
+
export type UseConsentOptions = {
|
|
80
|
+
/** Current consent version (bump to re-prompt) */
|
|
81
|
+
consentVersion?: number;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Return type for useConsent hook
|
|
86
|
+
*/
|
|
87
|
+
export type UseConsentReturn = {
|
|
88
|
+
/** Accept all tracking */
|
|
89
|
+
acceptAll: () => void;
|
|
90
|
+
/** Current consent state (null if not yet determined) */
|
|
91
|
+
consent: ConsentState | null;
|
|
92
|
+
/** Decline analytics tracking (functional always on) */
|
|
93
|
+
declineAnalytics: () => void;
|
|
94
|
+
/** Whether consent has been given (any response) */
|
|
95
|
+
hasResponded: boolean;
|
|
96
|
+
/** Whether currently loading from storage */
|
|
97
|
+
isLoading: boolean;
|
|
98
|
+
/** Reset consent (will re-show banner) */
|
|
99
|
+
resetConsent: () => void;
|
|
100
|
+
/** Update specific consent category */
|
|
101
|
+
updateConsent: (category: ConsentCategory, value: boolean) => void;
|
|
102
|
+
};
|