Skip to Content
iAdvizeDocs
Shopify

The shopper's own cart on Shopify

On a Shopify store with the web tag, the agent adds to and reads the cart behind your store's cart icon, and the tag refreshes the cart count on the page. What the shopper sees, what the tag does, and what stays separate.

On a Shopify store with the web tag, the agent works on the shopper's own cart: the one behind your store's cart icon and checkout. Before, it built a separate cart of its own, so a product it added did not show up in your store's cart and a product the shopper added on the site was invisible to the agent.

This page explains how that works and what it means for your store. It applies to a site with a Shopify connector.

What the shopper sees

  • The cart count in your header updates without a reload. The agent writes to the cart from the agent's servers, not from the shopper's browser, so your theme does not see the change by itself. When the agent's reply ends, the tag refreshes the cart count your theme shows on the current page. See The cart count on the current page for how, and for what it does not refresh.
  • The agent sees what the shopper put in the cart on your site. When it reads the cart, it reads the lines the store holds at that moment, whoever added them. Quantities the shopper changed on the site are kept: when the agent adds a product that is already in the cart, it adds to the quantity the cart holds. A quantity of 0 removes the product. When the agent changes a specific cart line, it sets that line's quantity. A quantity that is not a whole number is refused and the cart is left unchanged. Several changes in one step run one after the other, so none overwrites another.
  • The agent never shows the cart's access link. Where the separate cart gave the shopper Shopify's checkout link, the agent points the shopper to your store's cart page (/cart, or the page under your locale prefix such as /fr-ca/cart) when the page sent a valid one.

The cart card

Each time the agent reads or changes the shopper's cart, the panel shows a card with that cart under the answer. It is built from the cart Shopify returned, not from what the agent wrote, so it shows what the store actually holds at that moment.

The card shows:

  • Your cart, with the line "As the agent last saw it" under the title.
  • One row per cart line: the product name (cut after two lines), the quantity ("Qty 2") and the unit price when the cart gives one. The first 5 lines are listed, then "+3 more" for the rest.
  • Total: the cart's total as Shopify states it, when the cart gives one. It is never added up from the lines, so it can include a discount the lines don't show.
  • Your cart is empty. in place of the lines when the cart has none.
  • Go to cart: opens your store's cart page (/cart, or the page under your locale prefix) in a new tab. It shows only when the page sent a valid cart page address. It does not change the cart.

The card is read-only. It has no quantity or remove buttons: the shopper changes the cart by asking the agent, or on your store's own cart page.

Only the latest card shows in full. When the agent reads or changes the cart again, the earlier card collapses to one line, such as "Cart: 3 items" (the sum of the quantities), with a smaller Go to cart. After a page reload, a resumed conversation shows its cards collapsed too: the full card is for the cart read on the page the shopper is on.

The card does not refresh on its own. If the shopper changes the cart on your site (in the cart drawer, on a product page), the card on screen keeps the cart as the agent last saw it. The next time the agent reads or changes the cart, a new card shows the cart as it is then.

No card shows when the cart cannot be read whole: Shopify returned an error, or a line has no name or no whole, positive quantity. A partial cart is never shown as the shopper's cart. The agent's answer is unaffected.

Where it shows: only in the panel of the web tag, on a Shopify store where the shared cart is bound. The AI Storefront, the Playground and other platforms keep a separate cart, as described below, and show no cart card.

In the dashboard, a conversation's transcript shows its latest cart card in full, without Go to cart, and its earlier ones collapsed.

The cart count on the current page

After the agent adds, changes or removes a line of the shopper's cart, the tag refreshes the cart count your theme shows on the page, without reloading it. It happens once the agent's reply ends, so the count changes as the shopper reads the agent's confirmation.

The method is the same on every theme. There is no code per theme and nothing to set up:

  1. The tag looks for your theme's cart count elements inside its Shopify sections (the elements with an id starting with shopify-section-). It recognizes them by their markup: an id, a class or an attribute name containing cart-count, cart-bubble, cart-icon-count, cart-icon-bubble, cart-item-count or cart-item-bubble, in any case, with -, _ or nothing between the words.
  2. It asks your store to render those sections again, for the page the shopper is on and their own cart, through Shopify's Section Rendering API, at most 5 sections in one request. This is a read.
  3. It copies onto each count element on the page the class and content of the same element in the fresh render. Nothing else on the page changes: the rest of the header, its menu and the scripts your theme attached to it stay as they were.

What it never does:

  • It does not reload the page or take the shopper anywhere.
  • It does not write the cart. Every request it makes to your store is a read.
  • It does not open the cart drawer or refresh the lines it lists. A drawer your theme already rendered on the page can show the old lines until the next page view.
  • It does not fire your theme's or Shopify's cart events, so your analytics and apps don't count the agent's add a second time.

Every failure leaves the page as it was, with no error for the shopper: a request that fails, a fresh render that has no matching element, or a page with no cart count element inside a section.

A change only counts when the agent's result is the shopper's own cart read whole, the same condition as the cart card. A read, a refused or failed change, or a turn that fell back to a separate cart refreshes nothing. When the shopper reloads the page, a change from an earlier page view does not trigger a refresh again.

A theme that draws its count by script

Some themes don't render the cart count in a section: their own JavaScript draws it in the browser. The refresh finds no count to copy there, so the count keeps its old value until the next page view.

Your developer can close that gap with the tag's cart:updated event, which fires after each change, once the tag's own refresh attempt is over. See the tag's events for the event and an example.

What is recorded

Two events are recorded, as for product cards:

  • A cart view, once per full card, the first time it scrolls into view.
  • A Go to cart tap, the first tap on each card.

Neither is recorded for a shopper who objected to measurement, nor in a preview. A cart is not a product, so neither event counts in the product figures: the Engagement report's Impressions & clicks, the Events list of the Diagnostics tab, and the "saw a product" and "clicked a product" steps of an A/B test's funnel leave them out. ⚠ No report shows cart views or Go to cart taps yet.

It works the same for a shopper who objected

A shopper who objected to measurement still gets the shared cart. The tag's cart read and the cart reference sent with each message do not check the objection, because they carry out what the shopper asked for (adding a product to their own cart) and measure nothing. The reference is not used to attribute orders: the conversation join key stays a separate, objection-gated mechanism. The cart count refresh does not check the objection either: it shows the shopper the change they asked for and records nothing.

The shopper-facing data-usage notice says so. On a Shopify store the agent reads the cart from the store's page and sends it with each message. The key that gives access to the cart is used for that request only, is never stored and is never shown to the language model. The agent may create an empty cart, whether or not the shopper objected.

What the tag does

All of this runs in the tag, on Shopify storefronts only (the tag detects window.Shopify).

  1. It reads the cart when the panel opens. It calls your store's cart.js and, when the cart exists, sends its reference to the agent's panel. It also re-reads the cart on route changes and when the tab becomes visible again, so a later message carries the cart the page holds then. An unchanged cart is not sent twice.
  2. It creates an empty cart if the visitor has none. A visitor with no cart has only a throwaway token. When the panel opens, the tag calls your store's own cart/update.js with no changes, so Shopify creates a real, empty cart. This sets Shopify's own cart cookie in the visitor's browser even if they add nothing.
  3. It refreshes the cart count after the agent changes the cart. When the agent's reply ends, the panel tells the tag, with a message that carries nothing but its type, that the cart changed. The tag then refreshes your theme's cart count as described above, re-reads cart.js as in step 1, and fires the cart:updated event.
  4. It sends nothing before the panel exists. A page where the shopper never opens the agent makes no cart request for this feature.
  5. It stays silent on failure. If a request fails, the conversation runs on its own separate cart, as before.

The cart reference contains the cart's access key, which can read and change the cart. The tag sends it only to the agent's own origin and holds it in memory, never in storage or a cookie of its own. It is not given to the language model, and it is removed from the cart results the agent keeps, so it is not stored in the conversation.

This relies on a Shopify behaviour that Shopify does not document: its cart service accepts the store's own cart token. We verified it on test stores. If Shopify changes it, the agent falls back to a separate cart and its link, as described below.

What stays as before

The shared cart is bound only for the web surface (your storefront with the tag) on a site with a Shopify connector. Everything else keeps a separate cart and its own checkout link:

  • the hosted AI Storefront page (/s/{key}),
  • the Playground and evaluation runs,
  • other platforms (BigCommerce, Adobe Commerce and so on).

A request with no valid reference also falls back to a separate cart, and so does a turn where Shopify answers that the cart no longer exists. The agent then carries on with a cart of its own for the rest of that turn.

Counting: the panel and the storefront are separate sources

An add made by the agent is recorded by the agent as an add_to_cart event from the panel. It is counted in the Sales report as an add from the agent. On the shared cart, the event carries the lines and the currency but not the cart's token, which is the shopper's own cart token.

The Shopify pixel counts adds on your pages as a separate source. Do not add the two together: they are different counts, and the agent's adds are not guaranteed to appear in the pixel's. Whether Shopify's own add-to-cart event fires for an add made by the agent can depend on your theme and setup, so the pixel may or may not show it.

Your own analytics (your pixel, GA4, Meta) may not see the agent's adds either. They listen to events in the shopper's browser, and the agent's add is written from the server. The panel's add_to_cart event is the record of it.