简体   繁体   English

WooCommerce - 下订单时向 Google 跟踪代码管理器发送自定义事件

[英]WooCommerce - send a custom event to Google Tag Manager when order is placed

I need to emit / send a custom event to Google Tag Manager when an order is eventually placed, so this order can be tracked.当最终下订单时,我需要向 Google Tag Manager 发出/发送自定义事件,以便可以跟踪此订单。

The custom event should NOT be sent each time, when the WoocCommerce Thank you page is loaded, because the order would be tracked multiple times, when the page is reloaded.不应在每次加载 WoocCommerce 感谢页面时发送自定义事件,因为在重新加载页面时会多次跟踪订单。

So it should only be sent once for every order, when the final submit button is clicked AND the checkout form is valid.因此,当单击最终提交按钮并且结帐表单有效时,每个订单只应发送一次。

I looked for wooCommerce DOM events, but couldn't found a suitable one...我查找了 wooCommerce 个 DOM 事件,但找不到合适的事件...

I know there are plugins for that, but a plugin would be overkill for that I guess.我知道有用于此的插件,但我猜一个插件就太过分了。 We are a web agency and try to use as few plugins as possible and only necessary ones.我们是 web 代理机构,尽量使用尽可能少的插件,只使用必要的插件。

Unfortunately I have no clue, how I would emit an event on order placed... Any ideas or hints or even the solution to this?不幸的是,我不知道如何根据下订单发出事件……有什么想法或提示,甚至是解决方案吗? ;) ;)

Thanks in advance, have a nice day提前致谢,祝你有美好的一天

There are many solutions to this problem.这个问题有很多解决方案。 As you mentioned, a plugin would be likely most suitable in the universe of Wordpress.正如您提到的,插件可能最适合 Wordpress 的世界。

The next best solution is to open the documentation of woocommerce and see if you can find a callback for a successful order there.下一个最佳解决方案是打开 woocommerce 的文档,看看是否可以在那里找到订单成功的回调。 You emit an event from that callback if woocommerce doesn't do it already, which I believe you've checked.如果 woocommerce 尚未执行此操作,您会从该回调中发出一个事件,我相信您已经检查过了。

Another solution would be sending the conversion on thank you loads, but have a logic in place that would not send more than one event with the same order id.另一种解决方案是在感谢负载上发送转换,但有一个逻辑不会发送多个具有相同订单 ID 的事件。 And only when order id is defined.并且仅当定义了订单 ID 时。 That would require you to surface the order id or find where it's surfaced.这将需要您显示订单 ID 或找到它显示的位置。

A simpler yet dirty solution fitting woocommerce would be to just fire the conversion on the thank you page, but generate a cookie that would block the tag from firing again and let the cookie expire in N minutes, depending on whether you want to track repeated conversions from the same client.适合 woocommerce 的更简单但肮脏的解决方案是仅在感谢页面上触发转换,但生成一个 cookie 将阻止标记再次触发并让 cookie 在 N 分钟后过期,具体取决于您是否要跟踪重复转换来自同一个客户。

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

相关问题 当 WooCommerce 中的特定订单项目元数据为空时,发送自定义 email - Send a custom email when a specific order item meta is empty in WooCommerce 在 Woocommerce 中下订单后,将值插入自定义表中 - Insert Values into a custom table once order is placed in Woocommerce 下 WooCommerce 订单后,将一些数据添加到自定义数据库表中 - Add some data to custom database table once WooCommerce order is placed WooCommerce下订单时不保存add_fee - WooCommerce not saving add_fee when order is placed 通过REST API下订单时的woocommerce挂钩 - woocommerce hook when order is placed through REST API 在 Woocommerce 3.3 中下订单后向客户发送暂停订单通知 - Send customer on-hold order notification once order is placed in Woocommerce 3.3 每当下单超过 500 美元时,如何在 WooCommerce 中发送 email 警报? - How to send an email alert in WooCommerce whenever an order is placed for more than $500? WooCommerce - 发送自定义订单状态更改的自定义电子邮件 - WooCommerce - send custom email on custom order status change WooCommerce自定义checkout.js-订单以账单地址作为送货地址 - WooCommerce custom checkout.js - Order being placed with billing address as shipping address WooCommerce 不应该在订单是订阅父时发送订单完成邮件 - WooCommerce should NOT send order complete mail when order is subscription parent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM