Storefront window API
For theme developers: DollarBack exposes a JavaScript API on window.dollarlabs so custom themes can read cashback data, read the cashback total for the whole cart, compute cashback for any product, open the rewards widget from their own controls, re-initialize widgets after AJAX navigation, and react to cart changes. This is the reference for that API.

Prerequisite: the window-variable embed
The Cashback Window Variable app embed (handle cashback-window-variable) must be enabled in your theme. It injects the initial data (common, data, globals, widgetMessages) before the deferred JS bundle loads. Without it, window.dollarlabs is undefined.

Wait for readiness
The bundle loads deferred. Read the namespace only after the dollarback:ready event fires on window:
The namespace map
window.dollarlabs.common
Shop and customer context, available on every page: customerId, isCustomerLoggedIn, customerFirstName, customerTags, customerAcceptsMarketing, customerReferralCode, customerBalance, currencyFormat, routes.
window.dollarlabs.dollarback.data
Cashback program state: cashbackEnabled, the enabled configurations, referralSettings, tiers (tiersEnabled, customerTierName, tierMultiplier), and redemptionRules as configured in the app.
window.dollarlabs.dollarback.globals
The inputs the cashback engine runs on: every configuration (enabled or not), shopCurrency, currencyFormat, presentCurrencyRate, roundUpCashback, maximumOrderCashback, plus the widget display settings.
window.dollarlabs.dollarback.widgetMessages
The widget message templates.
window.dollarlabs.dollarback.pdpResult
Latest cashback calculation for the product page being viewed: config, cashbackAmount, formattedCashbackAmount, currency. Set on product pages after the bundle runs.
window.dollarlabs.dollarback.cartResult
Latest cashback calculation for the whole cart: the total, a per-line breakdown, and order-goal progress. Set on every page once the cart has been read. See Read the cashback total for the cart.
window.dollarlabs.dollarback.calculate
The per-product calculator. See calculate().
These objects are read-only display snapshots. Read them, but don't mutate them and don't treat them as an authoritative balance ledger; the app recalculates them itself.
data and globals share some key names but not their values: globals.configurations holds every configuration, while data.configurations holds only the enabled ones. Read each from where it lives rather than merging the two.
customerBalance is null only for guests. For a signed-in customer it is always an object with amount, currency and formatted, even when they hold no credit: then amount is 0 and formatted can be an empty string. Check the amount, not just the object, and read it with Number():
Read the cashback total for the cart
window.dollarlabs.dollarback.cartResult holds what the whole cart earns right now. DollarBack reads /cart.js on every page, works out the best offer for each line, adds the lines up, and then applies your maximum-per-order cap and rounding. The result is the same total the stock cart message shows, so a custom cart drawer, a mini-cart, or a header badge can show it without the cart block on the page.
cashbackAmount
The cart's cashback total in minor units (cents), already converted to the customer's currency: 750 means 7.50. It is missing, not 0, when nothing in the cart earns, so read it as cashbackAmount ?? 0.
formattedCashbackAmount
The same total formatted with your store's money format, such as "$7.50". It is the number 0 when nothing earns. Use it for display.
currency
Your store's currency code.
configs
The per-line breakdown: one { item, config, cashbackAmount } entry for each cart line that earns, where item is the /cart.js line and cashbackAmount is in minor units.
bestConfig
The cashback offer behind the total.
remainingAmount, nextAmount, goalConfig
Order-goal progress, set when the cart hasn't reached an order goal's next tier yet: how much more to spend, what that tier pays (an amount, or a percentage for percentage goals), and the order goal it belongs to. Both amounts are formatted strings.
messageType
"earned_and_more" (earning now, and there's a higher goal tier to reach), "progress" (nothing earned yet, but there's a goal tier to reach), "earned" (an order goal is fully reached), or "max_ceiling_applied" (the maximum-per-order cap kicked in). It is missing for a plain percentage or fixed offer with no goal to reach.
discountRewards
Discount-code rewards the cart qualifies for, if you reward discount codes instead of store credit. These don't count toward cashbackAmount.
The cart is read after dollarback:ready, so cartResult may not be set yet when that event fires. Read it if it is already there, then listen for dollarbackCartUpdated. That event fires with the new result each time the total is recalculated: on page load, and again whenever the cart changes.
To show cashback per line in a drawer, match configs entries against the drawer's lines by item.key:
The total is an estimate from the cart as it stands. The cashback actually issued is calculated on the order, after checkout discounts, so it can come out lower. See How cashback is calculated.
calculate() for cashback on any product
This runs the same engine as the product-page message for one variant, so a custom theme can render its own cashback line anywhere, such as on collection grids, quick views, or bundle builders. It considers purchase offers only, and applies the customer's eligibility, tier multiplier, maximum-per-order cap and rounding.
Pass the price in minor units, the way Shopify's variant.price Liquid object and /products/<handle>.js give it: 5800 for 58.00. Pass collections as GIDs ("gid://shopify/Collection/289123456789"), not bare numbers. Offers limited to certain collections only match if you do.
It returns one of three things:
null: no offer applies to this product or customer.{ config, cashbackAmount, formattedCashbackAmount, currency, currencyFormat }for a percentage or fixed offer.cashbackAmountis in minor units.{ config, cashbackType: "orderGoal", requiresCartCalculation: true }when the best offer is an order goal. An order goal's cashback depends on the whole cart, so there's no per-product amount to return. ReadcartResultinstead.
Compare your custom rendering against the stock PDP block's message to confirm the numbers match.
openWidget() to open the panel
Opens the floating widget's panel from your own JavaScript, so a header link, an icon, or any custom button can act as the entry point. It requires the Cashback Widget app embed to be enabled; the call opens the panel that embed renders.
options is optional:
tab
"home", "offers", "referral"
The navigation tab to open on.
view
"redeem", "history", "membership"
Opens the redeem-rewards, reward-history or membership screen directly.
configId
string
A cashback offer id. Opens the Offers tab, scrolls to that offer, and briefly highlights it.
From markup:
There is no matching closeWidget(). Customers close the panel with the launcher button, by clicking outside it, or by pressing Escape.
For the full recipe that hides the floating launcher and drives the panel from a navigation menu item instead, see Open the widget from a menu link.
Init actions to re-mount after AJAX navigation
Themes that swap DOM without full page loads (AJAX product loads, quick-view modals, cart drawers) can re-initialize surfaces manually:
initPDP(config)
Re-initialize the product-page context. Config fields: productId, productCollectionIds, variants (array of { id, price }), giftCard, initialVariantId, initialVariantPrice.
initCart()
Re-initialize the cart context.
initCartDrawerInjector()
Re-attach the cart-drawer message injection.
initPDPReactRender()
Re-mount the PDP message component.
initCartReactRender()
Re-mount the cart message component.
initWidgetReactRender()
Re-mount the floating widget.
initLoyaltyPageReactRender()
Re-mount the loyalty page.
All live under window.dollarlabs.dollarback.
Events
dollarback:ready
On window, when the bundle has loaded.
(none)
cart_changed
On window, whenever the cart watcher detects additions, removals or quantity changes.
{ detail: newCart } (the new cart, as /cart.js returns it).
dollarbackCartUpdated
On window, each time the cart's cashback is recalculated.
The new cartResult. See Read the cashback total for the cart.
dollarbackProductUpdated
On window, each time the product page's cashback is recalculated (variant, quantity or cart changes).
The new pdpResult.
dollarback:open-widget
You dispatch it on window to open the panel.
The same options object openWidget() takes.
Dispatching the event is equivalent to calling openWidget(), and is useful when you'd rather not touch the namespace at all:
DollarBack's own messages recalculate off cart_changed; your theme can hook it too:
Legacy globals (deprecated)
Older themes may use the globals below. They still work, and each one points at the same object or function as its replacement, so the values always agree. They are deprecated, though: write new code against window.dollarlabs only, and move old code over when you next touch it.
window._dollarlabs.common
window.dollarlabs.common
window._dollarlabs.dollarback
window.dollarlabs.dollarback.data
window._dollarlabs.WidgetMessageTemplate
window.dollarlabs.dollarback.widgetMessages
window.dollarbackGlobals
window.dollarlabs.dollarback.globals
window.DollarbackCalculate
window.dollarlabs.dollarback.calculate
window.DollarlabsProduct
window.dollarlabs.dollarback.pdpResult
window.DollarbackCart
window.dollarlabs.dollarback.cartResult (the cart total)
window._dollarlabs_balance
window.dollarlabs.common.customerBalance.formatted
window.initPDP, window.initCart and the other bare init* functions, window.CartWatcher, window.CashbackCalculator
The same names under window.dollarlabs.dollarback
A theme that reads the cart total from window.DollarbackCart.cashbackAmount keeps working. The equivalent now is window.dollarlabs.dollarback.cartResult.cashbackAmount, read as shown in Read the cashback total for the cart.
The short-link bridge
Clicks on anchors pointing at link.dollarlabs.io (the trackable short links used by social-follow rewards) automatically get the logged-in customer's ID appended as ?c=. That's how social-reward clicks are attributed. You don't need to add anything, but don't strip the parameter.
Common issues
window.dollarlabsisundefined: the Cashback Window Variable embed is off (see the prerequisite above), or you read it beforedollarback:ready.openWidget()does nothing: the Cashback Widget app embed is off, so there is no panel to open, or the call ran beforedollarback:readyfired.calculate()returnsnull: no config matches that product/variant, or the customer is excluded; see How cashback is calculated. For offers limited to certain collections, check that you passed collection GIDs, not bare IDs.Amounts are 100 times too big, or too small:
cashbackAmountandcalculate()'svariantPriceare in minor units (cents). For display, useformattedCashbackAmount.cartResultisundefined: the cart hasn't been read yet. Listen fordollarbackCartUpdatedrather than reading it once ondollarback:ready.Messages vanish after AJAX navigation: call the relevant init action after your theme swaps the DOM.
A widget won't render at all: see A widget isn't showing on my store.
Related articles
Last updated