Vueサイトにgoogle analyticsを埋め込むシンプルな方法

はじめに

Vue サイトに google analytics を埋め込んだのでメモします
めっちゃ簡単です。

ライブラリインストール

公式サイト
https://github.com/MatteoGabriele/vue-gtag

1
npm install vue-gtag

修正

main.js に以下を追加

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import Vue from 'vue'
import App from './App.vue'
import router from './router'

// この塊を追加
// google アナリティクス
import VueGtag from 'vue-gtag'
Vue.use(
VueGtag,
{
config: { id: 'UA-123456789-1' }
},
router
)

new Vue({
router,
render: h => h(App)
}).$mount('#app')

UA-123456789-1 の部分は自分のやつに変えてね!

おわりに

簡単ですね!

Vueサイトにgoogle analyticsを埋め込むシンプルな方法

https://reon777.com/2020/01/07/vue-google-analytics/

Author

reon777

Posted on

2020-01-08

Updated on

2026-06-30

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×