Skip to content

Commit bdd1477

Browse files
committed
feat: add analytics
1 parent a9be1e5 commit bdd1477

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

components/OneDemo.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<veui-button
5656
v-tooltip="t(codeExpanded ? 'hideCode' : 'showCode')"
5757
ui="icon"
58-
@click="codeExpanded = !codeExpanded"
58+
@click="handleCodeToggle"
5959
>
6060
<veui-icon
6161
scale="1.2"
@@ -66,7 +66,7 @@
6666
v-tooltip="t(editing ? 'closeEditor' : 'openEditor')"
6767
class="toggle-editor"
6868
ui="text"
69-
@click="editing = !editing"
69+
@click="handleEditorOpen"
7070
>
7171
Live
7272
</veui-button>
@@ -125,6 +125,7 @@ import OneIframe from './OneIframe'
125125
import OneEditLink from './OneEditLink'
126126
import OneRepl from './OneRepl'
127127
import OneFocus from './OneFocus'
128+
import { track } from '@vercel/analytics'
128129
import 'veui-theme-dls-icons/copy'
129130
130131
Vue.use(toast)
@@ -188,15 +189,26 @@ export default {
188189
play (vendor) {
189190
let locale = getLocale(this.$route.path)
190191
play(this.$refs.source.textContent, { locale, vendor })
192+
track('play', { vendor, path: this.path })
191193
},
192194
async copy () {
193195
try {
194196
await navigator.clipboard.writeText(this.code)
197+
track('copy', { from: 'demo', success: true })
195198
this.$toast.success(this.t('@onelive.copySuccess'))
196199
} catch (e) {
200+
track('copy', { from: 'demo', success: false })
197201
this.$toast.error(this.t('@onelive.copyFailed'))
198202
}
199203
},
204+
handleCodeToggle () {
205+
this.codeExpanded = !this.codeExpanded
206+
track('code-toggle', { expanded: this.codeExpanded, path: this.path })
207+
},
208+
handleEditorOpen () {
209+
this.editing = true
210+
track('live-edit', { path: this.path })
211+
},
200212
handleEditorClose () {
201213
this.editing = false
202214
},
@@ -205,6 +217,7 @@ export default {
205217
},
206218
resetFocus () {
207219
this.$refs.focuser.focus()
220+
track('reset-focus', { path: this.path })
208221
}
209222
}
210223
}

components/OneEditLink.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
:href="href"
1212
target="_blank"
1313
rel="noopener"
14+
@click="handleClick"
1415
>
1516
<slot :label="t('editOnGitHub')">
1617
<span class="full">{{ t('editOnGitHub', { item: t(type) }) }}</span>
@@ -26,6 +27,7 @@
2627
<script>
2728
import { Icon } from 'veui'
2829
import i18n from 'veui/mixins/i18n'
30+
import { track } from '@vercel/analytics'
2931
import 'veui-theme-dls-icons/external-link'
3032
3133
const BASE_URL = 'https://github.com/ecomfe/veui-docs/edit/master/one/docs/'
@@ -51,6 +53,11 @@ export default {
5153
href () {
5254
return `${BASE_URL}${this.path}`
5355
}
56+
},
57+
methods: {
58+
handleClick () {
59+
track('edit-source', { path: this.path })
60+
}
5461
}
5562
}
5663
</script>

components/OneLive.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ import { play } from '../common/play'
130130
import { transformLessCode } from '../common/transform'
131131
import { loadPref, savePref } from '../common/util'
132132
import OneIframe from './OneIframe'
133+
import { track } from '@vercel/analytics'
133134
134135
Vue.use(toast)
135136
@@ -292,8 +293,10 @@ export default {
292293
async copy () {
293294
try {
294295
await navigator.clipboard.writeText(this.code)
296+
track('copy', { from: 'editor', success: true })
295297
this.$toast.success(this.t('copySuccess'))
296298
} catch (e) {
299+
track('copy', { from: 'editor', success: false })
297300
this.$toast.error(this.t('copyFailed'))
298301
}
299302
},

0 commit comments

Comments
 (0)