本文介绍了使用gtag.js跟踪虚拟网页浏览量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多页注册表单,我想使用Google跟踪代码管理器跟踪用户通过表单的路径.我的页面在标题中使用推荐的代码段来跟踪页面视图:

I have a multipage registration form and I want to track user's path through the form using Google Tag Manager. My page uses a recommended code snippet in the header to track page view:

window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX');

根据文档,当用户单击以下形式的某个按钮:

According to documentation I generate a virtual page view when a user clicks a certain button in the form:

gtag('js', new Date());
gtag('config', 'UA-XXXXX', {
     'page_title' : 'User registration',
     'page_path': '/registration/page2'
});

但是,此代码不会添加新的页面视图.它覆盖了原始版本.我究竟做错了什么?我希望在用户单击按钮时生成新的综合浏览量.

However, this code doesn't add a new page view. It overrides the original one. What am I doing wrong? I want a new pageview to be generated when the user clicks a button.

推荐答案

看起来好像您不是在使用GTM,而是使用了gtag.js.

It doesn't look like you're using GTM, but gtag.js instead.

您需要在点击事件上触发它.像这样:

You'll need to trigger it on click events. Something like:

<button onclick="formStep2()">Click me</button>

然后使用formStep2()函数:

Then for the formStep2() function:

function formStep2(){
    gtag('config', 'UA-XXXXX', {
     'page_title' : 'User registration',
     'page_path': '/registration/page2'
    });
}

当然,您还可以通过传递一个指示路径/标题的参数来将功能设置为更通用/更有用.

Of course, you can setup the function to be more generic/useful by passing in a parameter indicating the path/title as well.

这篇关于使用gtag.js跟踪虚拟网页浏览量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 10:08