在 nuxt.js 中设置 Google Analytics 4 [英] setup Google Analytics 4 in nuxt.js

查看:155
本文介绍了在 nuxt.js 中设置 Google Analytics 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Nuxt 设置新的 Google Analytics 4 (GA4) 帐户时遇到问题.根据教程,一切似乎都配置好了,但是我的流量没有显示在 GA(开发和生产)中

在 nuxt.config.js 我有以下内容

 构建模块:['@nuxtjs/tailwindcss','@nuxtjs/google-analytics'],谷歌分析: {id: 'G-HWW3B1GM6W'},

google id 是我的生产网站的 GA4 数据流 id.我尝试了 2 个不同的流,带 www 和不带 www,但 GA4 中没有显示流量.

解决方案

[UPDATE]

如果您想使用 GA4 属性(即具有 G-XXXXXXXXXX 格式的 ID),您可以尝试使用

I'm having issues setting up a new Google Analytics 4 (GA4) account with Nuxt. Everything seems configured ok based on tutorials, however my traffic doesn't show up in GA (dev & production)

In nuxt.config.js I have the following

  buildModules: [
    '@nuxtjs/tailwindcss','@nuxtjs/google-analytics'
  ],
  googleAnalytics: {
    id: 'G-HWW3B1GM6W'
  },

The google id is a GA4 Data Stream id with my production website. I tried 2 different streams, with www and without, but the traffic doesn't show up in GA4.

解决方案

[UPDATE]

If you want to use GA4 Property (which is what has the ids in the format G-XXXXXXXXXX) you can try to use vue-gtag package by creating a plugin:

import Vue from 'vue'
import VueGtag from 'vue-gtag'

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

Add this in nuxtconfig.js

plugins: ['@/plugins/gtag']


About the problem indicated in your message, that plugin you mentioned works with the Universal version of Google Analytics (which is what has the ids in the format UA-XXXXXXXXX-X), like the example in your link:

 buildModules: [
   '@nuxtjs/tailwindcss','@nuxtjs/google-analytics'
 ],
 googleAnalytics: {
   id: 'UA-XXXXXXXX-X'
 },

The code you entered in the example, G-HWW3B1GM6W, refers to the new Google Analytics 4 which, being a different system from the previous one and does not work (yet) with that plugin.

So I suggest you to create a Universal Analytics type Property and use its ID (UA-XXXXX-X) with the plugin you indicated. You can find it by clicking on Show advanced options (when you create a new property):

这篇关于在 nuxt.js 中设置 Google Analytics 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆