Skip to content

Commit be50af0

Browse files
committed
fix: fix analytics code
1 parent bdd1477 commit be50af0

File tree

7 files changed

+41
-14
lines changed

7 files changed

+41
-14
lines changed

common/util.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,11 @@ export function savePref (key, value) {
5353
pref[key] = value
5454
localStorage.setItem(PREF_KEY, JSON.stringify(pref))
5555
}
56+
57+
export function track (...args) {
58+
if (typeof window !== 'object' || !window.__vaTrack) {
59+
return
60+
}
61+
62+
window.__vaTrack(...args)
63+
}

components/OneDemo.vue

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
ref="source"
8383
class="source"
8484
:style="{ height: codeExpanded ? `${sourceHeight || 0}px` : '0' }"
85+
@copy="trackCopy('system')"
8586
>
8687
<div class="source-toolbar">
8788
<veui-button
@@ -101,6 +102,7 @@
101102
:class="{
102103
'one-demo-editor-shrink': !editorExpanded
103104
}"
105+
:path="path"
104106
:code="code"
105107
:expanded="editorExpanded"
106108
:browser="!!browser"
@@ -121,11 +123,11 @@ import toast from 'veui/plugins/toast'
121123
import { BrowserWindow } from 'vue-windows'
122124
import { getLocale } from '../common/i18n'
123125
import { play } from '../common/play'
126+
import { track } from '../common/util'
124127
import OneIframe from './OneIframe'
125128
import OneEditLink from './OneEditLink'
126129
import OneRepl from './OneRepl'
127130
import OneFocus from './OneFocus'
128-
import { track } from '@vercel/analytics'
129131
import 'veui-theme-dls-icons/copy'
130132
131133
Vue.use(toast)
@@ -191,13 +193,20 @@ export default {
191193
play(this.$refs.source.textContent, { locale, vendor })
192194
track('play', { vendor, path: this.path })
193195
},
196+
trackCopy (action) {
197+
if (this.copied) {
198+
return
199+
}
200+
201+
this.copied = true
202+
track('copy', { from: 'demo', path: this.path, action })
203+
},
194204
async copy () {
195205
try {
196206
await navigator.clipboard.writeText(this.code)
197-
track('copy', { from: 'demo', success: true })
207+
this.trackCopy('button')
198208
this.$toast.success(this.t('@onelive.copySuccess'))
199209
} catch (e) {
200-
track('copy', { from: 'demo', success: false })
201210
this.$toast.error(this.t('@onelive.copyFailed'))
202211
}
203212
},

components/OneEditLink.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<script>
2828
import { Icon } from 'veui'
2929
import i18n from 'veui/mixins/i18n'
30-
import { track } from '@vercel/analytics'
30+
import { track } from '../common/util'
3131
import 'veui-theme-dls-icons/external-link'
3232
3333
const BASE_URL = 'https://github.com/ecomfe/veui-docs/edit/master/one/docs/'

components/OneLive.vue

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
scrollBeyondLastLine: false
1818
}"
19+
@copy.native="trackCopy('system')"
1920
/>
2021
<div class="editor-toolbar">
2122
<veui-button
@@ -128,9 +129,8 @@ import 'splitpanes/dist/splitpanes.css'
128129
import { getLocale } from '../common/i18n'
129130
import { play } from '../common/play'
130131
import { transformLessCode } from '../common/transform'
131-
import { loadPref, savePref } from '../common/util'
132+
import { loadPref, savePref, track } from '../common/util'
132133
import OneIframe from './OneIframe'
133-
import { track } from '@vercel/analytics'
134134
135135
Vue.use(toast)
136136
@@ -189,7 +189,8 @@ export default {
189189
type: String,
190190
default: ''
191191
},
192-
browser: Boolean
192+
browser: Boolean,
193+
path: String
193194
},
194195
data () {
195196
return {
@@ -275,6 +276,9 @@ export default {
275276
this.error = null
276277
})
277278
}
279+
},
280+
transformedCode () {
281+
this.copied = false
278282
}
279283
},
280284
mounted () {
@@ -290,13 +294,15 @@ export default {
290294
let locale = getLocale(this.$route.path)
291295
play(this.localCode, { locale, vendor })
292296
},
297+
trackCopy (action) {
298+
track('copy', { from: 'editor', path: this.path, action })
299+
},
293300
async copy () {
294301
try {
295302
await navigator.clipboard.writeText(this.code)
296-
track('copy', { from: 'editor', success: true })
303+
this.trackCopy('button')
297304
this.$toast.success(this.t('copySuccess'))
298305
} catch (e) {
299-
track('copy', { from: 'editor', success: false })
300306
this.$toast.error(this.t('copyFailed'))
301307
}
302308
},

components/OneRepl.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
class="editor"
2323
:code="code"
2424
:browser="browser"
25+
:path="path"
2526
/>
2627
</article>
2728
</template>
@@ -62,7 +63,8 @@ export default {
6263
default: ''
6364
},
6465
expanded: Boolean,
65-
browser: Boolean
66+
browser: Boolean,
67+
path: String
6668
},
6769
methods: {
6870
handleClose () {

one/build/remark-custom.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { render } from './page'
44

55
const NAME = 'customblock'
66

7-
const typeMap = {
7+
const statusMap = {
88
tip: 'info',
99
warning: 'warning'
1010
}
@@ -25,13 +25,13 @@ export default function attacher () {
2525

2626
visit(tree, NAME, ({ className, value }, index, parent) => {
2727
let { contents } = render(value, path, {})
28-
if (typeMap[className]) {
28+
if (statusMap[className]) {
2929
if (!data.hasAlert) {
3030
data.hasAlert = true
3131
}
3232
parent.children.splice(index, 1, {
3333
type: 'html',
34-
value: `<veui-alert ui="s" type="${typeMap[className]}">${contents}</veui-alert>`
34+
value: `<veui-alert ui="s" status="${statusMap[className]}">${contents}</veui-alert>`
3535
})
3636
} else {
3737
className = className ? `${className} custom-block` : 'custom-block'

plugins/vercel.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { inject } from '@vercel/analytics'
1+
import { inject, track } from '@vercel/analytics'
22

33
export default () => {
44
inject()
5+
6+
window.__vaTrack = track
57
}

0 commit comments

Comments
 (0)