Skip to content

Commit b58eac9

Browse files
committed
docs(app): improve analytics tracking
1 parent 2c4ff35 commit b58eac9

9 files changed

Lines changed: 33 additions & 20 deletions

File tree

docs/app/components/FrameworkTabs.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script setup lang="ts">
2-
const { framework, frameworks } = useFrameworks()
3-
const { track } = useAnalytics()
2+
const { framework, setFramework, frameworks } = useFrameworks()
43
54
const value = ref<string | undefined>(undefined)
65
@@ -12,8 +11,7 @@ watch(framework, () => {
1211
})
1312
1413
function onFrameworkChange(newFramework: string) {
15-
framework.value = newFramework
16-
track('Framework Tab Switched', { framework: newFramework })
14+
setFramework(newFramework as 'nuxt' | 'vue', 'tabs')
1715
}
1816
</script>
1917

docs/app/components/PageHeaderLinks.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const items = [
1313
label: 'Copy Markdown link',
1414
icon: 'i-lucide-link',
1515
onSelect() {
16-
track('Page Action', { action: 'Copy Markdown Link' })
16+
track('Page Action', { action: 'Copy Markdown Link', page: route.path })
1717
copy(mdPath.value)
1818
toast.add({
1919
title: 'Copied to clipboard',
@@ -27,7 +27,7 @@ const items = [
2727
target: '_blank',
2828
to: `/raw${route.path}.md`,
2929
onSelect() {
30-
track('Page Action', { action: 'View as Markdown' })
30+
track('Page Action', { action: 'View as Markdown', page: route.path })
3131
}
3232
},
3333
{
@@ -36,7 +36,7 @@ const items = [
3636
target: '_blank',
3737
to: `https://chatgpt.com/?hints=search&q=${encodeURIComponent(`Read ${mdPath.value} so I can ask questions about it.`)}`,
3838
onSelect() {
39-
track('Page Action', { action: 'Open in ChatGPT' })
39+
track('Page Action', { action: 'Open in ChatGPT', page: route.path })
4040
}
4141
},
4242
{
@@ -45,13 +45,13 @@ const items = [
4545
target: '_blank',
4646
to: `https://claude.ai/new?q=${encodeURIComponent(`Read ${mdPath.value} so I can ask questions about it.`)}`,
4747
onSelect() {
48-
track('Page Action', { action: 'Open in Claude' })
48+
track('Page Action', { action: 'Open in Claude', page: route.path })
4949
}
5050
}
5151
]
5252
5353
async function copyPage() {
54-
track('Page Action', { action: 'Copy Page' })
54+
track('Page Action', { action: 'Copy Page', page: route.path })
5555
copy(await $fetch<string>(`/raw${route.path}.md`))
5656
}
5757
</script>

docs/app/components/content/ComponentCode.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { CalendarDate, Time } from '@internationalized/date'
88
import * as theme from '#build/ui'
99
import { get, set } from '#ui/utils'
1010
11+
const { track } = useAnalytics()
12+
1113
interface CastImport {
1214
name: string
1315
from: string
@@ -479,6 +481,7 @@ const { data: ast } = useAsyncData(codeKey, async () => {
479481
size="sm"
480482
class="absolute -bottom-[13px] -right-[13px] z-1 rounded-full lg:opacity-0 lg:group-hover/component:opacity-100 ring-muted transition-opacity duration-200"
481483
aria-label="Open in playground"
484+
@click="track('Playground Opened', { component: camelName, source: 'code' })"
482485
/>
483486
</UTooltip>
484487

docs/app/components/content/ComponentExample.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { hash } from 'ohash'
55
import { useElementSize } from '@vueuse/core'
66
import { get, set } from '#ui/utils'
77
8+
const { track } = useAnalytics()
9+
810
const props = withDefaults(defineProps<{
911
name: string
1012
class?: any
@@ -262,6 +264,7 @@ const urlSearchParams = computed(() => {
262264
size="sm"
263265
class="absolute -bottom-[13px] -right-[13px] z-1 rounded-full lg:opacity-0 lg:group-hover/component:opacity-100 ring-muted transition-opacity duration-200"
264266
aria-label="Open in playground"
267+
@click="track('Playground Opened', { component: camelName, source: 'example' })"
265268
/>
266269
</UTooltip>
267270

docs/app/components/header/Header.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
const route = useRoute()
33
const { desktopLinks } = useHeader()
44
const { open } = useChat()
5+
const { track } = useAnalytics()
6+
7+
function toggleChat() {
8+
if (!open.value) {
9+
track('AI Chat Opened', { source: 'header' })
10+
}
11+
open.value = !open.value
12+
}
513
</script>
614

715
<!-- eslint-disable vue/no-template-shadow -->
@@ -29,7 +37,7 @@ const { open } = useChat()
2937
variant="ghost"
3038
icon="i-lucide-bot-message-square"
3139
aria-label="Ask AI for help"
32-
@click="open = !open"
40+
@click="toggleChat"
3341
/>
3442
</UTooltip>
3543

docs/app/components/theme-picker/ThemePicker.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ watch(open, (isOpen) => {
1111
})
1212
1313
const { copy: copyCSS, copied: copiedCSS } = useClipboard()
14-
const { copy: copyAppConfig, copied: copiedAppConfig } = useClipboard()
14+
const { copy: copyConfig, copied: copiedConfig } = useClipboard()
1515
1616
const {
1717
neutralColors,
@@ -32,7 +32,7 @@ const {
3232
hasConfigChanges,
3333
configLabel,
3434
exportCSS,
35-
exportAppConfig,
35+
exportConfig,
3636
resetTheme
3737
} = useTheme()
3838
</script>
@@ -246,9 +246,9 @@ const {
246246
variant="soft"
247247
size="sm"
248248
:label="configLabel"
249-
:icon="copiedAppConfig ? 'i-lucide-copy-check' : 'i-lucide-copy'"
249+
:icon="copiedConfig ? 'i-lucide-copy-check' : 'i-lucide-copy'"
250250
class="flex-1 text-[11px]"
251-
@click="copyAppConfig(exportAppConfig())"
251+
@click="copyConfig(exportConfig())"
252252
/>
253253
<UTooltip text="Reset theme">
254254
<UButton

docs/app/composables/useFrameworks.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ export function useFrameworks() {
22
const framework = useCookie('nuxt-ui-framework', { default: () => 'nuxt' })
33
const { track } = useAnalytics()
44

5-
function setFramework(value: 'nuxt' | 'vue') {
5+
function setFramework(value: 'nuxt' | 'vue', source?: string) {
66
framework.value = value
7-
track('Framework Switched', { framework: value })
7+
track('Framework Switched', { framework: value, source: source || 'search' })
88
}
99

1010
const frameworks = computed(() => [{
@@ -21,6 +21,7 @@ export function useFrameworks() {
2121

2222
return {
2323
framework,
24+
setFramework,
2425
frameworks
2526
}
2627
}

docs/app/composables/useSearch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export function useSearch() {
77
const searchTerm = ref('')
88

99
function onSelect() {
10-
track('AI Chat Opened', { hasSearchTerm: !!searchTerm.value })
10+
track('AI Chat Opened', { source: 'search', hasSearchTerm: !!searchTerm.value })
1111

1212
if (searchTerm.value) {
1313
messages.value = [...messages.value, {

docs/app/composables/useTheme.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ export function useTheme() {
244244
return lines.join('\n')
245245
}
246246

247-
function exportAppConfig(): string {
248-
track('Theme Exported', { type: 'AppConfig' })
247+
function exportConfig(): string {
248+
track('Theme Exported', { type: 'Config', framework: framework.value })
249249

250250
const config: Record<string, any> = {}
251251

@@ -415,7 +415,7 @@ export function useTheme() {
415415
hasConfigChanges,
416416
configLabel: computed(() => framework.value === 'vue' ? 'vite.config.ts' : 'app.config.ts'),
417417
exportCSS,
418-
exportAppConfig,
418+
exportConfig,
419419
applyThemeSettings,
420420
resetTheme
421421
}

0 commit comments

Comments
 (0)