简体   繁体   English

GTM dataLayer推送后表单提交

[英]Form submit after GTM dataLayer push

I am using GTM's Enhanced Ecommerce to report events via pushes to the dataLayer variable. 我正在使用GTM的增强型电子商务通过推送到dataLayer变量来报告事件。

I have a situation where I need to push an event and immediately submit a form in the event callback. 我有一种情况需要推送一个事件并立即在事件回调中提交一个表单。 Google in theory provides the eventCallback mechanism for this, but consider the following code: Google理论上为此提供了eventCallback机制,但请考虑以下代码:

<script>
dataLayer.push({
  'ecommerce': {
    'currencyCode': 'EUR',
    'impressions': [
     {
       'name': 'Donut Friday Scented T-Shirt',
       'id': '67890',
       'price': '33.75',
       'brand': 'Google',
       'category': 'Apparel',
       'variant': 'Black',
       'list': 'Search Results',
       'position': 2
     }]
  }
},{
    'eventCallback': function() {
        document.location = productObj.url; // works
        document.getElementById('form-id').submit(); // fails (!?!)
    }
});
</script>

Notes: 笔记:

  1. There no Javascript errors on the page 页面上没有Javascript错误
  2. The form #form-id exists (not a matter of typos) 表单#form-id存在(不是拼写错误)

Bottom line: how do I go about causing the form to submit after the push? 底线:如何在推送后使表单提交? Or is this not possible? 或者这不可能吗?

Any particular reason as for why you are using GTM to submit a form (particularly after a product impression)? 您使用GTM提交表单的原因有何特别原因(特别是在产品展示后)? This is probably beyond its intended use and sounds way too hacky. 这可能超出了它的预期用途,听起来太过于苛刻。

Assuming the website does the push itself, you could submit the form immediately after the dataLayer.push on the webpage script, and using GTM's own form submit delay catch the push, assemble the product impression tag yourself, then let the form submit as expected after it fired. 假设网站自己进行推送,您可以在网页脚本上的dataLayer.push之后立即提交表单,并使用GTM自己的表单提交延迟抓住推送,自己组装产品展示标签,然后让表单按预期提交它解雇了。 That should do it. 应该这样做。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM