PATTERN LIBRARY

Reusable patterns for checkout behavior.

Bundles, bumps, upsells, and cart state. Every demo below is interactive — see how each pattern works before you build.

Open Workspace Browse templates

Getting started

Start here — every checkout page loads the SDK this way.

One script tag. The SDK reads your campaign, finds every data-next-* attribute on the page, and wires them to live cart state.

what happens on load
SDK loaded · 14 kB gzipped
CampaignSpec fetched · v4.3 · valid
attributes hydrated · 14 nodes
cart restored · from session
no build step · no framework requirement
index.html
<!-- Load SDK -->
<script
  src="https://cdn.jsdelivr.net/gh/NextCommerceCo/campaign-cart@latest/dist/loader.js"
  type="module"></script>

<!-- Campaign API key (public, domain-allowlisted) -->
<meta name="next-api-key"
      content="YOUR_CAMPAIGN_API_KEY">
<meta name="next-page-type"
      content="checkout">
the api key binds this page to its campaign

Bundle selectors

Use during checkout offer configuration.

Bundle cards wired to cart state. In swap mode, picking a bundle replaces the cart contents — one decision, one total.

demo cart $35.98
selection mode: swap · cart state owned by SDK
checkout.html
<div data-next-bundle-selector
     data-next-selection-mode="swap">

  <div data-next-bundle-card
       data-next-bundle-id="duo"
       data-next-bundle-items='[{"packageId":2,"quantity":2}]'
       data-next-selected="true">…</div>

  <div data-next-bundle-card
       data-next-bundle-id="triple"
       data-next-bundle-items='[{"packageId":2,"quantity":3}]'>…</div>

</div>
no JS required · the SDK hydrates the attributes on load

Order bumps

Use when adding optional add-ons at checkout.

A checkbox that adds a line item without leaving checkout. The SDK recalculates totals; declining removes it cleanly.

demo cart $35.98
2x Drone $35.98
order total $35.98
bump adds package 7 as a line item · totals recalculated by SDK
checkout.html
<div data-next-package-toggle>

  <div data-next-toggle-card
       data-next-package-id="7"
       data-next-is-upsell="true"
       data-next-package-sync="1">

    <input type="checkbox"> Add gift wrap — $3.99

  </div>

</div>
unchecking removes the line item · no orphaned charges

Upsells

Use after purchase, before the receipt page.

A post-purchase offer that charges against the original payment — accept adds to the order, decline moves on. No re-entry of card details.

demo · post-purchase order $35.98
ONE-TIME OFFER
Add 1 more Drone for $14.99
Ships in the same box — no extra shipping.
offer pending · expires with the session
charges the original payment method · one offer per order
upsell.html
<div data-next-upsell="offer"
     data-next-package-id="7">

  <h3>Add an extra battery?</h3>

  <button data-next-upsell-action="add">
    Yes, add to order
  </button>

  <button data-next-upsell-action="skip">
    No thanks
  </button>

</div>
both buttons route to thank-you · decline is never a dead end

Attributes

Use when displaying live cart or product values.

Any element can display live cart values with data-next-display. Values update — and flash — the moment state changes.

demo · bound values
Quantity 1
cart.quantity 1
cart.total $19.99
package.name 1x Drone
values re-render on every cart event · flash marks the change
any-page.html
<span data-next-display="cart.quantity">1</span>

<span data-next-display="cart.total">$35.98</span>

<span data-next-display="package.name">2x Drone</span>
displays format currency automatically from the CampaignSpec locale
NEXT STEP

Seen how they work?

Every pattern here ships inside the starter templates. Open the Workspace and put them to work.

Open Workspace Browse templates