geekvv
geekvv

Reputation: 61

how to use Google-analytics-4 in Vue.js 2

Is vue-gtag can be only used in vue3? then, how can use GA4 in vue2, any references there, or demo code?

Thanks!

Upvotes: 6

Views: 6625

Answers (2)

seungwoo lee
seungwoo lee

Reputation: 77

vue-gtag 1.16.1 supports ga4 in vue2.

npm install [email protected] 

main.js

import Vue from 'vue'
import VueGtag from 'vue-gtag'
import router from '@/router'

// ...

Vue.use(VueGtag, {
    config: {
        id: 'G-XXXXXXXXXX',
        params: {
            send_page_view: false
        }
    }
}, router)

// ...

Upvotes: 7

Minseo Lee
Minseo Lee

Reputation: 195

You can use vue-gtag version 1 which supports vue2. And also, gtag is not vue spec, it's on javascript spec

Upvotes: 3

Related Questions