{"id":19017919,"date":"2026-09-11T17:06:45","date_gmt":"2026-09-11T17:06:45","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/bug-remove-from-cart-tracking-broken\/"},"modified":"2026-09-11T17:10:06","modified_gmt":"2026-09-11T17:10:06","slug":"bug-remove-from-cart-tracking-broken","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/bug-remove-from-cart-tracking-broken\/","title":{"rendered":"Bug: remove-from-cart tracking broken"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hi Pixel Manager team,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First of all, thank you for a great plugin! It has saved us an enormous amount of time setting up conversion tracking. We have, however, stumbled upon a bug we want to report. I believe this bug is not specific to my environment but is a bug in your plugin.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Environment: Pixel Manager for WooCommerce (free, v1.67.0), WooCommerce (10.9.4), Flatsome theme with child theme.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The bug is, in short, that <strong>remove-from-cart tracking is broken<\/strong> due to a mismatch in how <code>cart_item_keys<\/code> are handled, which produces the <strong>&#8220;Wasn&#8217;t able to retrieve a productId&#8221;<\/strong> error message. Let me describe this in detail.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When a customer removes a product from the cart (mini-cart, cart and checkout), the Js-console in Chrome show the following error:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Pixel Manager: error: Error: Wasn't able to retrieve a productId<br \/>    at e.removeProductFromCart (functions.js:171)<br \/>    at HTMLAnchorElement.&lt;anonymous&gt; (event_listeners.js:159)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This results in the <code>pmw:remove-from-cart<\/code> event nevr being sent.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Steps to reproduce<\/strong>: Add any product to the cart, then load any page with the product in the cart, finally click a remove-from-cart button\/link.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Root cause<\/strong>: I had a long debug session where I managed to trace where things go wrong. A data-format mismatch inside the plugin between the backend cart sync and the remove-link resolver:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. ajax_pmw_get_cart_items() <\/strong>returns cart item keys as <code>cart_item_keys[key] = { id, is_variation, parent_id }<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ class-pixel-manager.php<br \/>$data&#091;'cart']&#091;$product-&gt;get_id()]&#091;'variant'] = (string) implode( ' | ', $variant_text_array );<br \/>$data&#091;'cart_item_keys']&#091;$cart_item]&#091;'parent_id'] = (string) $product-&gt;get_parent_id();<br \/>$data&#091;'cart_item_keys']&#091;$cart_item]&#091;'is_variation'] = true;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. <strong>pmw<\/strong><\/strong>.<strong>getCartItemsFromBackend()<\/strong> and <strong>pmw<\/strong>.<strong>reconcileCartFromBackend()<\/strong> in <code>src\/js-src\/public\/pmw\/functions.js<\/code> merge that response into <code>pmwDataLayer.cart_item_keys<\/code> via <code>Object.assign<\/code>, overwriting the <code>{ product_id, variation_id }<\/code> entries that the inline cart-fragment scrips printed on page load by <code>includes\/pixels\/class-pixel-manager.php<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ includes\/pixels\/class-pixel-manager.php<br \/>&lt;script&gt;<br \/>  (window.pmwDataLayer = window.pmwDataLayer || {}).cart_item_keys            = window.pmwDataLayer.cart_item_keys || {};<br \/>  window.pmwDataLayer.cart_item_keys&#091;'&lt;?php <br \/>    echo esc_js( $cart_item_key );<br \/>    ?&gt;'] = &lt;?php <br \/>    echo wp_json_encode( $data, $json_encode_options );<br \/>    ?&gt;;<br \/>&lt;\/script&gt;<br \/><br \/>\/\/ src\/js-src\/public\/pmw\/functions.js&lt;\/span&gt;<br \/>if (pmwDataLayer.cart_item_keys&#091;cartItemKey]&#091;\"variation_id\"] === 0) {<br \/>  productId = pmwDataLayer.cart_item_keys&#091;cartItemKey]&#091;\"product_id\"];<br \/>} else {<br \/>  productId = pmwDataLayer.cart_item_keys&#091;cartItemKey]&#091;\"variation_id\"];<br \/>}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. pmw.getProductIdByCartItemKeyUrl() <\/strong>still reads the old fields, but since the &#8220;variation_id&#8221; key was overwritten, the productId will be undefined &#8220;variation_id&#8221; does not exist in the <code>cart_item_keys[cartItemKey]<\/code> associative array. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ product-detection.js<br \/>if (pmwDataLayer.cart_item_keys&#091;cartItemKey]&#091;\"variation_id\"] === 0) {<br \/>   productId = pmwDataLayer.cart_item_keys&#091;cartItemKey]&#091;\"product_id\"];<br \/>} else {<br \/>   productId = pmwDataLayer.cart_item_keys&#091;cartItemKey]&#091;\"variation_id\"];<br \/>}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This  explains why the <strong>&#8220;Wasn&#8217;t able to retrieve a productId&#8221;<\/strong> error was thrown. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Happy to provide debug logs or more details if useful. Thanks again for a fantastic plugin!<\/p>\n","protected":false},"template":"","class_list":["post-19017919","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19017919","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":2,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19017919\/revisions"}],"predecessor-version":[{"id":19017926,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19017919\/revisions\/19017926"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=19017919"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}