-
-
Notifications
You must be signed in to change notification settings - Fork 362
Expand file tree
/
Copy pathevents.ts
More file actions
178 lines (160 loc) · 4.34 KB
/
Copy pathevents.ts
File metadata and controls
178 lines (160 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
* Typed event registry for GA4 analytics.
*
* Source of truth for every event the site emits. The discriminated union
* means wrong/missing props for a given event name produce a TypeScript
* error at the call site rather than silent bad data downstream.
*
* See `.agents/analytics.md` for the human-readable reference (event
* meanings, funnel definition, custom dimensions, BigQuery setup).
*/
import type { PartnerPlacementOrderStrategy } from '../partner-placement'
// ---------- Enums ----------
export type PartnerPlacement =
| 'directory'
| 'detail'
| 'docs_rail'
| 'blog_rail'
| 'grid'
| 'home_grid'
| 'library_grid'
| 'embed_grid'
| 'docs_strip'
| 'ecosystem_game'
| 'partners_index_cta'
| 'library_callout'
export type PartnerClickDestination = 'external' | 'internal_detail'
export type PartnerTierValue = 'gold' | 'silver' | 'bronze'
export type PartnerFilterChange =
| 'libraries_changed'
| 'status_changed'
| 'cleared_all'
export type BuilderMode = 'lucky' | 'confident' | 'none'
export type BuilderAction =
| 'copy_prompt'
| 'deploy'
| 'clone_repo'
| 'open_codex'
| 'open_claude'
| 'open_cursor'
| 'download'
| 'open_advanced'
| 'netlify_start'
| 'provider_redirect_manual'
| 'provider_redirect_auto'
| 'open_repo'
export type BuilderSurface = 'result_panel' | 'deploy_dialog'
export type BuilderFailureStage = 'analysis' | 'generation' | 'login_blocked'
// ---------- Session context ----------
/**
* Slow-changing context stamped on every builder event so any breakdown
* works in GA4 without joining sessions in BigQuery.
*/
export interface BuilderSessionContext {
mode_used: BuilderMode
idea_used: string
}
// ---------- Event union ----------
export type AnalyticsEvent =
| {
name: 'page_view'
props: {
page_location: string
page_path: string
page_title: string
}
}
| {
name: 'partner_viewed'
props: {
partner_id: string
order_strategy?: PartnerPlacementOrderStrategy
placement: PartnerPlacement
partner_tier?: PartnerTierValue
rotation_seed?: string
slot_index?: number
}
}
| {
name: 'partner_clicked'
props: {
partner_id: string
placement: PartnerPlacement
destination: PartnerClickDestination
destination_host?: string
order_strategy?: PartnerPlacementOrderStrategy
partner_tier?: PartnerTierValue
rotation_seed?: string
slot_index?: number
}
}
| {
name: 'partner_filter_applied'
props: {
change: PartnerFilterChange
library_filters: string
status_filter: string | null
result_count: number
}
}
| {
name: 'partner_inquiry_started'
props: {
placement: PartnerPlacement
}
}
| {
name: 'builder_analyzed'
props: BuilderSessionContext & {
analysis_deployment?: string
inferred_library_count: number
inferred_partner_count: number
feature_count: number
}
}
| {
name: 'builder_generated'
props: BuilderSessionContext & {
final_deployment?: string
final_package_manager?: string
final_library_count: number
final_partner_count: number
final_addon_count: number
library_ids: string
partner_ids: string
addon_ids: string
}
}
| {
name: 'builder_failed'
props: BuilderSessionContext & {
stage: BuilderFailureStage
error_message?: string
retry_after?: number
anonymous_generations_remaining?: number
}
}
| {
name: 'builder_activated'
props: BuilderSessionContext & {
action: BuilderAction
surface: BuilderSurface
provider?: string
automatic: boolean
}
}
// ---------- Helper types ----------
export type AnalyticsEventName = AnalyticsEvent['name']
export type AnalyticsEventProps<TName extends AnalyticsEventName> = Extract<
AnalyticsEvent,
{ name: TName }
>['props']
/**
* Default session context for new builder sessions. `mode_used = 'none'`
* means the user hasn't picked Lucky or Confident yet; `idea_used = 'none'`
* means they haven't selected a suggested idea.
*/
export const defaultBuilderSessionContext: BuilderSessionContext = {
mode_used: 'none',
idea_used: 'none',
}