如何在我的 Vue 网站中正确设置 Google Analytics? [英] How can I properly setup Google Analytics in my Vue website?
问题描述
我有 1 个名为calculator.vue 的组件,在我的 main.js 中有插件代码,如下所示:
I have 1 component called calculator.vue and in my main.js I have the code for the plugin, like below:
import App from './App.vue'
import vuetify from './plugins/vuetify'
import "./plugins/vuetify-money.js"
import VueMeta from 'vue-meta'
import VueAnalytics from 'vue-analytics'
Vue.use(VueAnalytics, {
id: 'My UA',
disableScriptLoader: true
})
Vue.use(VueMeta);
Vue.config.productionTip = false
new Vue({
vuetify,
render: h => h(App)
}).$mount('#app')```
推荐答案
如此处所述:https://github.com/MatteoGabriele/vue-analytics
他的插件将停止接收功能请求.我只会花时间修复重要的错误.Google 从analytics.js 迁移到了它的新gtag.js 库,我创建了一个名为vue-gtag 的新插件.如果您要创建一个新项目,我建议您开始使用它.
his plugin will stop receiving feature requests. I will only spend time for important bug fixes. Google moved from analytics.js to its new gtag.js library and I've created a new plugin called vue-gtag. I suggest you to start using that one if you are about to create a new project.
你可以在这里看到一个例子:https://matteo-gabriele.gitbook.io/vue-gtag/#add-plugin-to-your-application
You can see an example here: https://matteo-gabriele.gitbook.io/vue-gtag/#add-plugin-to-your-application
import Vue from "vue";
import App from "./App.vue";
import VueGtag from "vue-gtag";
Vue.use(VueGtag, {
config: { id: "UA-1234567-1" }
});
new Vue({
render: h => h(App)
}).$mount("#app");
这篇关于如何在我的 Vue 网站中正确设置 Google Analytics?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!