[ga()函数Google Analytics(分析)在Google跟踪代码管理器中实现为代码]

问题描述 投票:0回答:1

我需要使用自定义ga('send')函数来发送在表单提交(特别是通过Marketo)上触发的数据。

在将GA作为脚本标签安装的网络媒体资源上,效果很好。但是,在一个站点上我需要这样做,GA是通过GTM作为标记安装的。这显然是最佳做法。

基本上,代码看起来像这样(针对上下文):

form.onSuccess(function (values, url) {console.log('success');
...ga('send', 'event', {eventCategory: 'form',eventAction: 'submit',eventLabel: 'Form Submit'});...return false;});

我做了一些研究

How to send ga(...) events with Google Tag Manager?

Google Analytics Code Explanation

前提是我首先需要定义ga()函数-所以我这样做是这样的:

window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;ga('create', "UA-3488044-2", 'auto');
form.onSuccess(function (values, url) {console.log('success');
...ga('send', 'event', {eventCategory: 'form',eventAction: 'submit',eventLabel: 'Form Submit'});...return false;});

我可以看到`console.log(“ success”),并且没有引发任何错误,但是我没有看到GA中记录了表单提交事件。

有什么想法吗?如何使用GA的Google跟踪代码管理器实现与脚本代码进行自定义事件?

javascript google-analytics
1个回答
0
投票

在通过GTM标签实现GA的marketo表单页面上,那么您应该考虑为此使用custom datalayer events

不必担心“ custom”一词,基本上可以代替ga()函数:

dataLayer.push({'event': 'event_name'});

所以您的代码变成:

form.onSuccess(function (values, url) {console.log('success');
...dataLayer.push({'event': 'form-submit'});...return false;});

THEN IN GTM:

  1. 根据您刚刚编写的自定义事件(“表单提交”)创建触发器,以推送到数据层,如下所示:enter image description here
  2. 然后创建一个GA标签,将曲目类型设置为“ EVENT”,并根据需要填写类别,操作和标签。然后附加在步骤1中创建的触发器。enter image description here
  3. 预览或提交所有内容以查看其是否正常。
© www.soinside.com 2019 - 2024. All rights reserved.