简体   繁体   English

GTM - 表单提交时的Fire标记(仅当填写了必填字段时)

[英]GTM - Fire tag on form submit (only if required fields are filled)

I'm looking for an easy way to accurately track form submissions. 我正在寻找一种简单的方法来准确跟踪表单提交。 This is the code I'm currently using: 这是我目前正在使用的代码:

$(function () {
      $('#form').submit(function() {
        dataLayer.push({
            'event': 'GAEvent', 
            'eventCat': 'Form Submit - Create', 
            'eventAction': 'Form Submit Document', 
            'eventLabel': checked,
            'eventValue': count,
            'gaNonInt': false
        });
      });
    });

The issue is that the tag is firing even when the form is not submitting. 问题是即使表单未提交,标签也会触发。 For example, if someone fails to fill out a required field and clicks the submit button, GTM sees that submit click as a submission. 例如,如果某人未能填写必填字段并单击提交按钮,则GTM会将提交点击视为提交。 Is there an easy way to only fire the tag if all required fields are filled? 如果填写了所有必填字段,是否只有一种简单的方法可以触发标记?

Thanks in advance. 提前致谢。

You might want to try to use GTMs "native" submit trigger instead of the jQuery code and make sure that the "check validation" checkbox is ticked. 您可能希望尝试使用GTM“本机”提交触发器而不是jQuery代码,并确保选中“检查验证”复选框。

The javascript validation in your form suppresses the default behavior of the submit button and calls the submit event only when the validation has passed. 表单中的javascript验证会抑制提交按钮的默认行为,并仅在验证通过时调用submit事件。 With the "check validation" option set the GTM form submit trigger should be able to notice that the default behavior is prevented and fire the tags only when the validator functions calls the submit event (I say "should" because, anecdotally, I think the form submit trigger is not always 100% reliable, but it might be worth a try). 通过设置“检查验证”选项,GTM表单提交触发器应该能够注意到默认行为被阻止,并且仅当验证器函数调用提交事件时才触发标记(我说“应该”,因为,有趣的是,我认为表单提交触发器并不总是100%可靠,但它可能值得一试)。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何仅在使用 bootstrap 填写所有必需的 attr 字段后才提交表单? - How to submit a form only if all the required attr fields are filled using bootstrap? 如果未填写必填字段,如何防止提交表单上的函数调用? - How to prevent function call on submit form if required fields are not filled out? 即使未填写必填字段,我是否可以在超时时提交表单 - Can I submit form on timeout even if required fields are not filled 如何禁用提交,直到仅填写必填字段 - How to disable submit till only required fields are filled up 仅在所有必填字段均已填写时才提交表单吗? - Submit form only if all required fields are full? 当未填写必填字段时,不调用角提交 - Angular submit not called when required fields not filled 仅在提交表单之前填写必填字段的情况下,才能创建模式 - How to create a modal only if the required fields are filled out before submitting form 仅当在步骤向导表单中填写所有字段时,才激活提交按钮 - activate submit button only when all the fields are filled in step wizard form 在填写动态创建的必填字段之前,请禁用提交按钮 - Keeping submit button disabled until dynamically created required fields are filled 如何检查是否填写了所有必填字段以启用提交按钮? - How to check if all required fields are filled to enable submit button?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM