vue-gtag @legacy查询不返回客户端ID

发布于 2025-02-11 03:28:58 字数 716 浏览 1 评论 0原文

当我使用vue2时,我将Vue-gtag@legacy命名,因为它与Vuejs版本兼容的版本。

插件设置:

import VueGtagPlugin from "vue-gtag";
Vue.use(VueGtagPlugin, {
  config: { id: "G-MY-MEASUREMEND-ID" }
});

插件已正确加载 - 这是console.log。

{query: ƒ, config: ƒ, optOut: ƒ, optIn: ƒ, pageview: ƒ, …}
config: ƒ ()
customMap: ƒ (map)
event: ƒ (name)
exception: ƒ ()
linker: ƒ (params)
optIn: ƒ ()
optOut: ƒ ()
pageview: ƒ (param)
purchase: ƒ (params)
query: ƒ ()
refund: ƒ ()
screenview: ƒ (param)
set: ƒ ()
time: ƒ (params)

main.ts 甚至进入回调:

this.$gtag.query("get", "G-MY-MEASUREMEND-ID", "client_id", clientID => {
   console.log("CID", clientID);
});

有什么想法吗?

As I'm using Vue2, I insalled vue-gtag@legacy as it's the version compatible with version 2 of VueJS.

main.ts plugin setup:

import VueGtagPlugin from "vue-gtag";
Vue.use(VueGtagPlugin, {
  config: { id: "G-MY-MEASUREMEND-ID" }
});

The plugin is loaded correctly - this is the console.log of this.$gtag:

{query: ƒ, config: ƒ, optOut: ƒ, optIn: ƒ, pageview: ƒ, …}
config: ƒ ()
customMap: ƒ (map)
event: ƒ (name)
exception: ƒ ()
linker: ƒ (params)
optIn: ƒ ()
optOut: ƒ ()
pageview: ƒ (param)
purchase: ƒ (params)
query: ƒ ()
refund: ƒ ()
screenview: ƒ (param)
set: ƒ ()
time: ƒ (params)

However if I try to access client_id (which is my main goal), the callback prints nothing - it seems it doesn't even go inside the callback:

this.$gtag.query("get", "G-MY-MEASUREMEND-ID", "client_id", clientID => {
   console.log("CID", clientID);
});

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

秋叶绚丽 2025-02-18 03:28:58

尝试在nuxt.config.ts中输入此内容

  {
  src:'〜/plugins/main.ts',
  //如果您使用SSR
  SSR:是的
  //如果您使用CSR
  模式:“客户端”
  //一个
}
 

来源: https:///www.carlcassar。 com/com/act-google-analytics-to-a-nuxt-js-app

try entering this in nuxt.config.ts

{
  src: '~/plugins/main.ts',
  // if you use ssr
  ssr: true
  // if you use csr
  mode: 'client'
  // chooise one
}

source : https://www.carlcassar.com/articles/add-google-analytics-to-a-nuxt-js-app

醉生梦死 2025-02-18 03:28:58

我不确定是否可以在vue-gtag中使用get方法;我认为查询方法没有为此做好准备:
https://github.com/matteogabriele/vue-gtag/vue-gtag/issues/251

I'm not sure if it's possible to use the get method in vue-gtag; I think query method is not prepared for that:
https://github.com/MatteoGabriele/vue-gtag/issues/251

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文