demo · v140

Analytics Router

A popover has three openers: a header button, a context-menu item, and an auto-popup on first visit. Only the first two should fire an "intent" analytics event; the auto-popup is noise. event.source tells the router which is which.

Cart

3 items, $42.50

cart.addEventListener("toggle", (e) => {
  if (e.newState !== "open") return;
  if (!e.source) return;                  // auto-popup → skip
  analytics.track("cart_opened", {
    from: e.source.id,                    // "hdr" or "ctx"
  });
});

see also