One hook for every add-to-cart event

window.ef.onAddToCart fires for every path into the cart with a normalized payload, so your pixels and tag manager get one clean event.

Your pixels needed to know the moment a product hit the cart. So you wired one snippet to the buy button, another to the cart widget, a third to quick buy, and hoped they stayed in sync when the page changed.

The enemy is re-implementing the same tracking event for every path into the cart.

There is one hook for all of it now: window.ef.onAddToCart. Subscribe once and it fires for the client-side cart, the plus and minus buttons, and /b buy links, with a normalized payload. The same detail is dispatched as an ef:add-to-cart event on window, so tag managers and pixels can listen without registering a callback at all.

window.ef.onAddToCart(function (e) {
  // e.source: 'cart' or 'buy-link'
  e.products.forEach(function (p) {
    gtag('event', 'add_to_cart', {
      currency: p.currency,
      value: p.price,
      items: [{ item_id: p.id, item_name: p.name }]
    });
  });
});

Backend script templates for common pixels ship in brand settings, so you start from a working example instead of a blank file.

Try it: paste the snippet into a page, add a product to the cart, and watch the event fire in your tag manager preview.