Skip to content

Commit 4ad4373

Browse files
committed
chore: typing improvements
1 parent 1074c31 commit 4ad4373

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

.claude/settings.local.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
"mcp__analytics-mcp__run_realtime_report",
3737
"Bash(python3:*)",
3838
"mcp__playwright__browser_click",
39-
"mcp__playwright__browser_type"
39+
"mcp__playwright__browser_type",
40+
"Bash(pnpm typecheck:*)",
41+
"Bash(pnpm lint:*)"
4042
]
4143
}
4244
}

src/lib/analytics.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,64 +60,75 @@ export type NavigationType = 'header_link' | 'footer_link' | 'inline_link'
6060
// ============================================================================
6161

6262
export interface ViewBuyButtonsParams {
63+
[key: string]: unknown
6364
source_page: string
6465
button_location: ButtonLocation
6566
}
6667

6768
export interface ClickBuyButtonParams {
69+
[key: string]: unknown
6870
book_format: BookFormat
6971
source_page: string
7072
button_location: ButtonLocation
7173
}
7274

7375
export interface ViewFreeChapterFormParams {
76+
[key: string]: unknown
7477
form_location: string
7578
}
7679

7780
export interface SubmitFreeChapterFormParams {
81+
[key: string]: unknown
7882
form_location: string
7983
}
8084

8185
export interface ClickOutboundLinkParams {
86+
[key: string]: unknown
8287
link_url: string
8388
link_domain: string
8489
link_text: string
8590
source_page: string
8691
}
8792

8893
export interface ScrollDepthParams {
94+
[key: string]: unknown
8995
percent_scrolled: ScrollDepthThreshold
9096
page_path: string
9197
content_type: string
9298
}
9399

94100
export interface BlogReadCompleteParams {
101+
[key: string]: unknown
95102
page_path: string
96103
estimated_read_time: number
97104
time_on_page: number
98105
}
99106

100107
export interface ViewBlogCtaParams {
108+
[key: string]: unknown
101109
cta_type: string
102110
cta_position: CtaPosition
103111
cta_variant: PromoVariant
104112
page_path: string
105113
}
106114

107115
export interface ClickBlogCtaParams {
116+
[key: string]: unknown
108117
cta_type: string
109118
cta_position: CtaPosition
110119
cta_variant: PromoVariant
111120
page_path: string
112121
}
113122

114123
export interface InternalNavigationParams {
124+
[key: string]: unknown
115125
from_page: string
116126
to_page: string
117127
navigation_type: NavigationType
118128
}
119129

120130
export interface ViewChapterDetailsParams {
131+
[key: string]: unknown
121132
chapter_number: number
122133
chapter_title: string
123134
}
@@ -171,7 +182,10 @@ export function isDebugMode(): boolean {
171182
/**
172183
* Log analytics event to console in debug mode
173184
*/
174-
function debugLog(eventName: string, params: Record<string, unknown>): void {
185+
function debugLog<T extends Record<string, unknown>>(
186+
eventName: string,
187+
params: T,
188+
): void {
175189
if (!isDebugMode()) return
176190

177191
console.group(`📊 Analytics Event: ${eventName}`)
@@ -197,9 +211,9 @@ function getGtag(): GtagFunction | null {
197211
* Generic event tracking function
198212
* Handles cases where gtag might not be loaded yet (Partytown delay)
199213
*/
200-
export function trackEvent(
214+
export function trackEvent<T extends Record<string, unknown>>(
201215
eventName: string,
202-
params: Record<string, unknown>,
216+
params: T,
203217
): void {
204218
debugLog(eventName, params)
205219

0 commit comments

Comments
 (0)