Documentation Index
Fetch the complete documentation index at: https://docs.aftersell.com/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Upcart is a separate app from Aftersell, so Strategies aren’t baked into the Upsells module the way they are in Aftersell’s post-purchase and checkout flows. Instead, you bridge the two apps with a small script that calls the Strategies API directly and feeds the result into Upcart’s existing Upsells module via Upcart’s public API. The script is drop-in - paste it once into Upcart’s custom HTML, replace two values (your Strategy API key and the Strategy ID), and the Upsells module will start surfacing whatever products the Strategy returns.What You’ll Need
- Your Strategy API key. In Aftersell, go to Settings → Product Strategy and copy your Strategy API key.
- The Strategy ID. Open the Strategy you want to run in the Aftersell Strategy editor and copy its ID.
- The Upsells module enabled in Upcart. The script overrides the list of products shown in the existing upsell block, so the module needs to be turned on for anything to render.
Adding the Script
In Upcart, go to Settings → Custom HTML → Scripts (before load) and paste the script below. ReplaceSTRATEGY_ID and STRATEGY_API_KEY with the values from Aftersell, then save.
What the Strategy Sees
Because this runs from the storefront cart, the context is a slim subset of what’s available on Aftersell’s native surfaces:Product context
The line items currently in the Upcart cart are sent as the input products. Triggers like product type, vendor, product handle, product title, and any product ID / variant ID triggers all evaluate against these items.Cart context
- Subtotal - cart total in cents (Upcart’s
total_price). - Item count - total quantity across all lines.
- Line count - number of distinct line items.
Session context
- Currency code - taken from
window.Shopify.currency.active.
What Happens When the Strategy Returns
The products returned by the Strategy fully replace the list Upcart would otherwise show in the Upsells module. The merchant-defined upsell list is overridden for the duration of that cart - it’s not merged in. Each Strategy product is mapped to Upcart’s expected product shape (variants, images, options, metafields, etc.) so it renders inside the upsell block exactly like any other product.When No Product Is Returned
If the Strategy returns no products, the Upsells module renders empty - no upsells are shown. To avoid this, configure a Catch all in the Strategy so there is always a fallback product to return. See the Building Strategies page for how to set up a Catch all.Re-Evaluation on Cart Changes
Unlike checkout upsells, the Upcart implementation re-evaluates the Strategy every time the cart changes - items added, removed, or quantity-updated. The script subscribes to Upcart’scartUpdated event, sends the new cart to the Strategies API, and refreshes the cart drawer with the new upsell list.
A cart-signature check skips redundant calls if the line items and quantities haven’t actually changed, so back-to-back cart events that don’t materially change the cart won’t re-hit the API.
Tips for Upcart Strategies
- Design around the cart. Cart-shape and product triggers are the strongest signals you have here. Customer history and UTM-based targeting aren’t sent by the default script.
- Use Catch all as a safety net. Without one, the Upsells module will show nothing whenever no rule matches.
- Cache-friendly by default. The cart-signature guard prevents re-firing the API if the cart hasn’t materially changed - good for shoppers who toggle the cart open and closed without editing it.