我已经用electron-vue js创建了一个教育应用程序,现在我决定在这个桌面应用程序中实现Google Analytics。我在谷歌上搜索了一些packages,但找不到我可以从谷歌分析中获得的确切信息,例如,我应该使用谷歌分析的哪些功能来改进我的基于研究的桌面应用程序( electron-vue js platform)。这里有一点关于它的描述: a)应用程序完全离线。b)它包括学习材料,如音频、视频等。c)它还提供打印学习材料等功能。即使是一个想法也可以帮助我弄清楚如何使用谷歌分析,这可能是一个很好的开端。提前向您表示感谢!
发布于 2020-05-21 20:44:38
Google analytics将把Electron视为一个网站。
我使用这个插件https://github.com/MatteoGabriele/vue-analytics
在渲染器中Vue的主条目中设置如下
import VueAnalytics, { set } from 'vue-analytics'
Vue.use(VueAnalytics, {
id: 'UA-idnumber',
router,
// debug: {
// enabled: true,
// trace: true // help you find problems
// },
fields: {
cookieDomain: 'none' // no domain
},
autoTracking: {
pageviewTemplate (route) {
// allow custom page titles in the router meta
let title = route.meta.title
if (!title) {
title = route.name
}
return {
page: route.name,
title: title,
location: route.path
}
}
}
})
set('allowAdFeatures', false) // no ads
set('checkProtocolTask', null) // ignore electron protocols
set('checkStorageTask', null) // ignore electrons cache solution, assume it works然后我有这样的指令
import { event } from 'vue-analytics'
Vue.directive('gaClick',
{
inserted: (el, binding, vnode) => {
let routeName = vnode.context.$route.meta.title
if (!routeName) {
routeName = vnode.context.$route.name
}
el.addEventListener('click', async e => {
const category = binding.value && binding.value.category ? binding.value.category : 'button Click'
const action = binding.value && binding.value.action ? binding.value.action : 'Click'
const label = binding.value && binding.value.label ? binding.value.label : `${e.target.innerText} (${routeName})`
const value = binding.value && binding.value.value ? binding.value.value : 0
event(category, action, label, value)
})
}
})在按钮和链接上使用,如下所示
<router-link
:to="{name:'status-page'}}"
v-ga-click="{label:'Status Page'}"
>
Status Page
</router-link>这将为你提供google analytics的几乎所有功能。除非他们决定再次改变事情并破坏它。就像他们推动对“应用程序”进行firebase分析一样
https://stackoverflow.com/questions/61933723
复制相似问题