Skip to content

Commit 0263606

Browse files
seanoliverivasilov
andauthored
Fix templateTitle telemetry for production command format (supabase#40321)
* Fix templateTitle telemetry for production command format Consolidated regex parsing to handle both URL format (/ui/r/name.json) and shadcn registry alias format (@supabase/name) in a single pass. The regex extracts title and framework atomically, properly handling version specifiers like @latest through greedy backtracking. * Handle vue and nuxtjs in the supabase clients. * Fix the types. --------- Co-authored-by: Ivan Vasilov <[email protected]>
1 parent 1d54b9d commit 0263606

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

apps/ui-library/components/command-copy-button.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ export function CommandCopyButton({ command }: { command: string }) {
1818
}, [copied])
1919

2020
const parseCommandForTelemetry = (cmd: string) => {
21-
// Extract framework from URL (e.g., 'nextjs' from 'password-based-auth-nextjs.json')
22-
const frameworkMatch = cmd.match(/ui\/r\/.*?-(nextjs|react|react-router|tanstack)\.json/)
21+
// Extracts title and framework e.g. "title: password-based-auth, framework: nextjs"
22+
const match = cmd.match(
23+
/(?:\/ui\/r\/|@supabase\/)(.+)-(nextjs|react-router|react|tanstack|vue|nuxtjs)(?:@[^@\s]+|\.json)?$/
24+
)
2325

24-
// if the block doesn't have a framework defined (like infinite query), default to react
25-
const framework = frameworkMatch
26-
? (frameworkMatch[1] as 'nextjs' | 'react-router' | 'tanstack' | 'react')
27-
: 'react'
26+
const framework =
27+
(match?.[2] as 'nextjs' | 'react-router' | 'tanstack' | 'react' | 'vue' | 'nuxtjs') ?? 'react'
28+
const title = match?.[1] ?? ''
2829

2930
// Extract package manager from command prefix (npx, pnpm, yarn, bun)
3031
const packageManager = cmd.startsWith('npx')
@@ -37,15 +38,7 @@ export function CommandCopyButton({ command }: { command: string }) {
3738
? ('bun' as const)
3839
: ('npm' as const)
3940

40-
// Extract template title from URL (e.g., 'password-based-auth' from 'password-based-auth-nextjs.json')
41-
const titleMatch = cmd.match(/\/ui\/r\/(.*?)\.json/)
42-
const title = (titleMatch ? titleMatch[1] : '').replaceAll(`-${framework}`, '')
43-
44-
return {
45-
framework,
46-
packageManager,
47-
title,
48-
}
41+
return { framework, packageManager, title }
4942
}
5043

5144
return (

packages/common/telemetry-constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ export interface SupabaseUiCommandCopyButtonClickedEvent {
12191219
properties: {
12201220
templateTitle: string
12211221
command: string
1222-
framework: 'nextjs' | 'react-router' | 'tanstack' | 'react'
1222+
framework: 'nextjs' | 'react-router' | 'tanstack' | 'react' | 'vue' | 'nuxtjs'
12231223
packageManager: 'npm' | 'pnpm' | 'yarn' | 'bun'
12241224
}
12251225
}

0 commit comments

Comments
 (0)