现有的 Google Analytics 事件和 Google Tag Manager [英] Existing Google Analytics events and Google Tag Manager

查看:18
本文介绍了现有的 Google Analytics 事件和 Google Tag Manager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的网站上实施了 Google Analytics (GA),我通过 ga("send", "event", ...); 函数发送了几个自定义事件,并且运行良好.

I have implemented Google Analytics (GA) on my site and I send several custom events through ga("send", "event", ...); function and it works well.

我正在试用 Google 跟踪代码管理器 (GTM).我已经删除了原始 GA 代码段,现在我使用 GTM 在我的网站上注入 GA 标记,并且浏览量被正确跟踪.我的自定义事件由 ga() 函数发送,效果不佳.

I am experimenting with Google Tag Manager (GTM). I have removed original GA snippet, and now I use GTM to inject GA tag on my site and pageviews are tracked correctly. What does not work well are my custom events sent by ga() function.

我注意到 GA create 有像

ga("create", "UA-12345678-1", {name: "gtm0123456789", allowLinker: false});

和用于 Google Chrome 的 Google Analytics Debugger 扩展报告 命令被忽略.未知目标:未定义.

and Google Analytics Debugger extension for Google Chrome reports Command ignored. Unknown target: undefined.

我发现发送事件调用应该包含跟踪器名称,​​所以它应该看起来像 ga("gtm0123456789.send", "event", ...);,但我不想要更改我所有现有的 GA 发送事​​件 调用.

I found out that send event call should include tracker name so it should look like ga("gtm0123456789.send", "event", ...);, but I don't want to change all my existing GA send event calls.

我通过在 GTM 设置中将跟踪器名称设置为空字符串(Edit Tag -> More Settings -> Advanced Configuration -> ☑ Tracker Name,将文本框留空)来快速修复它,现在它有效,但我不认为这是一个很好的解决方案.

I quickfixed it by setting tracker name to empty string in GTM settings (Edit Tag -> More Settings -> Advanced Configuration -> ☑ Tracker Name, leaving the textbox blank) and now it works, but I do not think it is such great solution.

是否还有其他选项可以让我现有的 GA 发送事​​件 调用并通过 GTM 使用事件跟踪?

Is there any other options to have my existing GA send event calls and using also event tracking through GTM?

推荐答案

有一个方法——你可以在标签管理器中重命名 ga 函数(高级配置,全局函数名),例如到real_ga".然后你在你自己的页面中创建一个自定义 ga 函数,它从你的事件跟踪调用中获取参数并将它们传递给 real_ga-function(所以你只需要在一个地方更改跟踪器名称),或者更好地将它们推送到 dataLayer(然后您可以使用 dataLayer 值在 GTM 中进行事件跟踪).

There is a way - you can rename the ga function in the tag manager (advanced configuration, global function name), e.g. to "real_ga" . Then you create a custom ga function in your own page that takes the parameters from your event tracking calls and passes them to the real_ga-function (so you need to change the tracker name only in one place), or better pushes them to the dataLayer (and then you can use the dataLayer values for event tracking in GTM).

但是你为什么要这样做呢?您实际上没有问题,您只是对您的解决方法感到难过.对此的正确答案是,只要它有效,就不会感到难过.

But why would you want to do that ? You do not actually have a problem, your simply feel bad about your workaround. The proper answer to this is, as long as it works don't feel bad.

这篇关于现有的 Google Analytics 事件和 Google Tag Manager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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