woocommerce / woocommerce-google-analytics-integration

WordPress plugin: Provides the integration between WooCommerce and Google Analytics.
http://wordpress.org/plugins/woocommerce-google-analytics-integration/
170 stars 69 forks source link

Do not replace another `added_to_cart` vanilla handler if there is one #438

Closed tomalec closed 2 months ago

tomalec commented 3 months ago

Changes proposed in this Pull Request:

Do not replace another added_to_cart vanilla handler if there is one.

Or jQuery event to Vanilla listener hack for added_to_cart may remove any previous listeners if there are any.

For other events: onupdated_wc_div and onremoved_from_cart we prevent that.

Checks:

Screenshots:

Detailed test instructions:

  1. Simulate another extension listening to the event
    add_action(
    'wp_head',
    function () {
        wp_add_inline_script(
            'woocommerce-google-analytics-integration',
            'document.body.onadded_to_cart = () => { console.log("Other extension listens to added to cart"); };',
            'before',
        );
    },
    );
  2. Go to shop page
  3. Click add to cart
  4. You should see the console log, and event should be tracked in https://tagassistant.google.com/

Additional details:

Changelog entry

Tweak - Do not replace other extensions' add_to_cart listeners.

tomalec commented 2 months ago

Thanks for catching that. :) Fixed in https://github.com/woocommerce/woocommerce-google-analytics-integration/pull/438/commits/dd9211fa3df8a91209f7765722badaf18e65ca83. Would you mind another round @eason9487