Analytics事件和Google跟踪代码管理器

Analytics事件和Google跟踪代码管理器

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

问题描述

我在我的网站上实施了Google Analytics(GA),并通过 ga(send,event,...); 功能发送了几个自定义事件它运作良好。

我正在尝试使用Google跟踪代码管理器(GTM)。我已经删除了原始GA代码段,现在我使用GTM在我的网站上注入了GA代码,并且浏览量得到了正确的跟踪。不好的工作是由ga()函数发送的我的自定义事件。



我注意到 GA create 具有跟踪器名称变量,如

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

和Google Analytics调试器扩展程序Google Chrome报告命令被忽略。未知的目标:undefined



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



我通过在GTM设置中将跟踪器名称设置为空字符串来快速修复它(编辑标签 - >更多设置 - >高级配置 - >☑跟踪器名称,将文本框留空),现在它可以正常工作,但我认为它不是那么棒的解决方案。

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

解决方案

有一种方法 - 您可以在标签管理器中重新命名ga函数(高级配置,全局函数名称),例如到real_ga。然后,在自己的页面中创建一个自定义的ga函数,该函数接受来自事件跟踪调用的参数并将它们传递给real_ga函数(因此您只需在一个位置更改跟踪器名称),或者更好地将它们推送到dataLayer (然后您可以在GTM中使用dataLayer值进行事件跟踪)。

但你为什么要这么做?你实际上没有问题,你只是对你的解决方法感到不满。正确的答案是,只要它有效就不会感觉不好。


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

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.

I have noticed that GA create has tracker name variable like

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

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

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.

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.

Is there any other options to have my existing GA send event calls and using also event tracking through 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跟踪代码管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 20:38