duracelltomi / gtm4wp

Google Tag Manager plugin for WordPress
https://gtm4wp.com/
GNU General Public License v3.0
147 stars 96 forks source link

Location change on add-to-cart #271

Open kzemek opened 1 year ago

kzemek commented 1 year ago

In handling add-to-cart event for woocomerce-enhanced plugin there's code that first prevents the link from working (e.preventDefault()) and then programatically changes location to that of the product: https://github.com/duracelltomi/gtm4wp/blob/10e7e9638e8750b30081ff9f5e340a370aa34657/js/gtm4wp-woocommerce-enhanced.js#L807 That's good in the general case but e.g. Shoptimizer preventDefaults itself to add a mini sidebar on product addition instead of redirect -- in this case, gtm4wp redirects on click after the sidebar pops up.

It would be great if gtm4wp could check whether default was already prevented, and if so not change document.location to prevent this interaction.

duracelltomi commented 1 year ago

Do you mean something like this? https://github.com/duracelltomi/gtm4wp/commit/079b172ac562e82ef98e4956f5c9723860c53d88