The pattern
Every integration is the same three lines: subscribe to an event, read the payload, forward it to your tool.Klaviyo
Triple Whale
Google Analytics 4
Other events worth tracking
Things to get right
- Prices are in cents. Divide by 100 for tools that expect a decimal amount.
formatMoneyis for display only, so don’t send a formatted string to an analytics tool. - A quantity bump isn’t
item_added. Going from 1 to 3 on an existing line firescart_updated, notitem_added. If your tool needs to see that, diff against the previous state in acart_updatedhandler. - Don’t track from
cart_updatedif you mean “added”. It fires on every change, including removals and quantity edits, so you’ll over-report. - Check for double-counting. If your tool already captures add-to-cart some other way, this script will report it twice. Verify in the tool’s live view before going live.
Testing it
Add aconsole.log alongside your tracking call, then open the browser console and add a product:
Where to go next
- Events: every event and when it fires.
- Cart object: every field you can send.
- Cart analytics: the reporting Aftersell provides out of the box.