Migration › Knowledge Base › Rule order & sendEvent
Rule order & sendEvent
Assemble the sandwich before you hand it over. Launch will happily pass an empty plate to the customer if you don't tell it to make the sandwich first.
The Web SDK splits collection into two rule actions: Update Variable (fill your XDM - Global object) and Send Event (dispatch it). The trouble is that Launch sorts rule components by their Order value before running them, so a Send Event with a default order can fire before the variables are populated.
The fix is deterministic ordering: give variable-setting rules a low Order (e.g. 1) and the terminal Send Event a high Order (e.g. 50)[28], and enable the property setting "Run rule components in sequence." On event-driven and SPA sites this matters even more, because multiple rules compete.
For your migration: this is the single most common build bug, a payload that arrives with cart items but no page context, or half its events missing. Order discipline makes it disappear.
Set variables in low-Order rules, send in high-Order rules, and enable "run components in sequence." Never rely on default ordering.
The two-rule pattern
Collection now splits into two actions: Update Variable fills your XDM - Global object, and Send Event dispatches it. The clean structure is one rule (or rule component) that sets everything, and a terminal one that sends, assemble the sandwich, then hand it over.
Why order is a real bug, not a nicety
Launch sorts rule components by their Order value before executing them[28]. So a Send Event left at the default order can fire before the variables are populated, shipping a payload with, say, cart items but no page context, or half its events missing. On event-driven and SPA sites, where multiple rules react to the same moment, this is even more likely.
The fix
Give variable-setting rules a low Order (e.g. 1) and terminal Send Event rules a high Order (e.g. 50), and enable the property setting "Run rule components in sequence" so actions within a rule complete in order.
Worked: a Product View rule
Any custom code that still references s.eVar1 or s.events throws once AppMeasurement is removed. Rewrite it to populate the variable object and dispatch via Send Event.