Cart tracking
Tocadule keeps a live snapshot of every visitor's cart called cart_state. It is the single source of truth for cart cards in popups and emails, abandoned-cart automations, the "has items in cart" segment, and product-in-cart targeting. You feed it with one call:
tocadule.cart({ items, total, currency, item_count })Send the whole current cart on every change (add, remove, quantity edit) — not a delta. Each call replaces the previous snapshot.
The cart is your store's own: it has one source, chosen in the Data centre's Cart card. On Shopify our app reads it from Shopify's carts webhooks; on IdeaSoft the Data centre gives you a ready cart box; anywhere else, call tocadule.cart() from your cart code. The snippet does not read carts from your pages by itself.
Install
tocadule.cart() is part of the standard snippet. The tiny inline stub queues any calls into tocadule._q and the async snippet.js replays them once it loads, so you can call tocadule.cart() immediately — before the main script has finished downloading.
<link rel="preconnect" href="https://app.tocadule.com">
<script>window.tocadule=window.tocadule||{};window.tocadule._q=window.tocadule._q||[];['track','identify','cart','requestPush','setConsent'].forEach(function(m){window.tocadule[m]=window.tocadule[m]||function(){window.tocadule._q.push([m,arguments])}});</script>
<script async fetchpriority="high" data-workspace="YOUR_WORKSPACE_ID" src="https://app.tocadule.com/snippet.js"></script>Sending the cart
Loop over every line in the cart and build one object per line. This is the exact script from the in-app Events guide:
<script>
// cart: call on every cart change (add, remove, quantity) and on the cart page, with the WHOLE cart. Replace each {…} with your platform's token.
var items = [];
// inside your platform's cart loop, once per product:
items.push({ product_id: `{productId}`, variant_id: `{variantId}`, sku: `{sku}`, name: `{productName}`,
price: `{productPrice}`, quantity: `{productQuantity}`, url: `{productUrl}`, image_url: `{productImage}` });
tocadule.cart({ items: items, subtotal: `{subtotal}`, currency: `{currency}`, cart_id: `{cartId}` });
</script>An empty cart is items: []. No email or other personal data goes on the cart.
Top-level fields
| Field | Required | Notes |
|---|---|---|
items | yes | One object per cart line (see below). An empty cart is items: []. |
subtotal | recommended | The items after discounts, VAT included, no shipping. Money as your store writes it. |
currency | recommended | ISO code, e.g. TRY, USD. Used for cart cards and purchase gap-fill. |
cart_id | recommended | Your cart's id, when you have one. |
discount, tax, total | no | The cart's discount, VAT and total, as your store writes them. |
item_count | no | Total quantity across all lines. |
Item fields
Our line keys. product_id, name, price and quantity are load-bearing for cart cards and for forwarding to ad destinations; the rest make the cards look better and improve matching. Your own names work too, mapped once in Data centre › Cart.
| Field | Notes |
|---|---|
product_id | Join key across events, and the content_id sent to ad catalogs. |
variant_id | The variant's id. |
sku | Stock code. |
name | Product name shown on cards. |
price | The unit price paid, VAT included, as your store writes it. |
quantity | Line quantity. |
url | The product's page. |
image_url | Product image URL — used on popup/email cart cards. |
brand | Brand / vendor. |
category | Product category. |
variant | Variant label (size / colour). |
discount | The per-unit discount already taken off price. |
Any extra scalar fields you put on an item (e.g. gtin, model_code) are carried through untouched — canonical keys always win, extras fill the gaps. (Keys prefixed with _, function values, and empty/null values are the only things stripped.)
The Cart health panel in your workspace samples recent cart_state items and shows the present-rate per field, so you can confirm the required fields are actually arriving and spot a product_id or price that's coming through empty.
cart_state is PII-free by design
Never put email, phone, or a name on tocadule.cart(). The cart snapshot carries only cart contents plus the visitor's anonymous_id. It resolves to a contact through the identity map — as soon as an identity event links the browser (identify at sign-up / login or on logged-in pages, including right before a purchase), the cart attaches to that contact via the anonymous_id.
That means you need at least one identity event per visitor somewhere in their journey — but never on the cart. Personal data sent on any event, the cart included, is stripped before the row is stored.
The cart only ever carries cart contents — never customer PII. Identity always comes from identify (or a popup form, or your platform).
How cart_state powers other things
- Nothing is derived from the cart. The latest snapshot is the visitor's cart now and a purchase closes it;
add_to_cartis your store's own event (sent by your code or your dataLayer), never made from a snapshot. - Visitors who refused tracking have no visitor id, only the day's hash (IP + user agent), which several refused visitors can share (an office network, the same phone and browser). The server keeps up to 10 carts per day hash and gives a snapshot to the cart it overlaps most, each cart with its own episode (what a cart reminder is tied to). Nothing is stored on the device for this.
- Open carts count carts. Open carts, open cart value and unfinished checkouts count carts, not people: one per visitor with a browser id, but two refused visitors sharing a day hash with different carts count as two (each cookieless cart carries a
cart_refthat lives only within that day). People counts and segments are unchanged. - Abandoned-cart automations read the visitor's latest non-empty
cart_state("has items + idle"). - Popup and email cart cards render from the latest
cart_state({cart_total},{cart_count},{cart_currency}, and the dynamic product-upsell block). - Purchase gap-fill: when a
purchasearrives without line items (and/or without acurrency), we stitch them from the visitor's most recent non-empty cart (checkout_startedpreferred, elsecart_state) within the last 7 days, matched byanonymous_idorcontact_id. Items/currency already on the purchase are left untouched.
Deduplication
You never set dedup IDs. Browser events dedup on anonymous_id; external/server events dedup on source_event_id. On top of that, tocadule.cart() throttles itself: if the cart contents and count are unchanged and the last snapshot fired within the last 60 seconds, the call is skipped. This roughly halves cart_state volume on SPA-style stores that re-fire on every navigation, without starving abandonment automations.
Consent
cart_state respects the same two consent lanes as every other event:
- Analytics lane (
consent_state) gates storing theanonymous_id. In cookieless mode the cart still sends, but without a persistent visitor ID. - Advertising lane (
ad_consent): the cart itself is never forwarded to ad destinations; it stores no personal data.
Email/SMS opt-in is a separate merchant preference and does not affect cart tracking.