google-analytics.js 361 Bytes
import { defineNuxtPlugin } from '#app'
import VueGtag from 'vue-gtag'

export default defineNuxtPlugin((nuxtApp) => {
  const getGDPRConsent = true; // 自定义获取用户同意的逻辑
  if (getGDPRConsent) {
    nuxtApp.vueApp.use(VueGtag, {
      config: { id: 'AW-881504701' } // 使用你的 Google Analytics 4 测量ID
    }, nuxtApp.router);
  }
});