SDK lifecycle

Events: sdk.ready and sdk.error.

SDK lifecycle starting, then ready (sdk.ready, once a page, with what the page shows) when the campaign is in: at once from a copy this browser saved in the last 10 minutes, else when the API answers. If the API fails and there is no saved copy, the SDK stops at failed (sdk.error, action campaign.load) without sdk.ready; with a copy it stays ready and still sends that sdk.error. Both set html data-next-error="campaign". Once ready, a step that fails sends sdk.error and the SDK stays ready. a saved copy, or the API answers fails, no copy starting loading the campaign ready sdk.ready failed sdk.error

The lifecycle is one page's: every page load starts at starting, and a page restored from the back/forward cache reloads and starts again.

StateMeans
startingThe campaign is loading; window.next already exists
readyThe campaign is in; html[data-next-ready] is set once the page shows its values
failedThe campaign could not load, and this browser has no copy of it from the last 10 minutes; html[data-next-ready] never comes
FromWhat happensToEvents, in order
noneThe loader has no data-campaign key, or the SDK code cannot loadnonenone: html[data-next-error="config"] or "load", a console.error, and no window.next
startingA copy of the campaign saved in this browser in the last 10 minutesreadysdk.ready, at once; when the API answers, the copy is replaced (no event of its own) and the cart is priced
startingNo copy: the API answersreadysdk.ready
startingNo copy: the API failsfailedsdk.error (campaign.load); no sdk.ready on this page
starting or readyBrowser storage is blocked or fullunchangedsdk.error (storage.write); before window.next exists it still reaches a listener added later
readyThe API fails after a saved copy made it readyreadysdk.error (campaign.load); the copy stays in use and prices the cart
readyA step fails; see Errors belowreadysdk.error, then the step's own event when it has one

Snapshot

  • sdk.ready carries a Snapshot: the campaign, the cart and the selectors as the page shows them then, the same objects the events carry.
  • checkout joins once a checkout form is bound and order once a page loads one, both after sdk.ready: next.snapshot() has them, the event does not.
  • next.snapshot() returns the same shape at any time.

Late listeners

  • next.on and next.analytics.on give a listener added later the events of that name this page already sent (its last 100; sdk.ready is never dropped), oldest first, then the new ones.
  • Past 100, the oldest cart.updated, cart.calculating, cart.calculated, selector.pricing or selector.priced goes first, then the oldest internal event, then any other.
  • A 0.4.x name gets only the events after the call; campaign:loaded, currency:fallback, sdk:url-parameters-processed, error:occurred and checkout:started are replayed too.

html attributes

  • data-next-error: "config" or "load" when the loader never started the SDK; "campaign" when campaign.load failed, with or without a saved copy.
  • data-next-ready (empty): after sdk.ready, once the checkout, order and slot code the page uses has bound and the values are written.
  • Then the window.nextReady callbacks run with window.next (a later push runs at once), and analytics starts when the browser is idle.
  • In failed none of that happens: no data-next-ready, and the nextReady callbacks never run.

Errors

  • On sdk.error, action names the step, code says why, status is the HTTP status when the API answered, and message is for developers and logs, never for shoppers.
  • A failure the shopper sees gets a second event: checkout.failed and upsell.failed carry it as error; coupon.check's is followed by coupon.denied (reason: 'check_failed').
  • A payment not taken is no SDK failure: a decline, or a return from the gateway unpaid, sends only payment.failed, code: 'declined' (and the gateway's decline_code) or 'payment_failed'.
  • The 0.4.x error:occurred gets every sdk.error, as message, code and details.
actionWhenWhat the SDK does nextAlso sentLikely code
campaign.loadThe campaign cannot loadStops at failed, without sdk.ready, when there is no saved copy; otherwise stays ready on the copyhtml[data-next-error="campaign"]network, auth, server, rejected
cart.calculateThe cart cannot be pricedThe cart is unpriced: the summary keeps its totals from before the change; the next change prices againnonenetwork, server, rejected
selector.priceOptions or a toggle cannot be pricedEach option keeps its last price, else shows its package price; the next change prices againnonenetwork, server
coupon.checkA coupon cannot be checkedThe code is not applied; applyCoupon resolves falsecoupon.denied (check_failed)network, server
user.saveThe Open Cart cannot be createdTries again on the next field changenonenetwork, server, rejected
address.load_rulesThe country list or a country's rules cannot loadUses the campaign's countries and the built-in checksnonenetwork, server
address.suggestAddress suggestions cannot loadShows no suggestionsnonenetwork, server
order.createThe order is not created: refused, or the request failsThe checkout goes back to idle; the cart unfreezescheckout.failedrejected, network, server
order.loadA page after the checkout cannot load the order in 10 sNo order.loaded or order.paid: no order values, data-next-order-items shows its error message, and offers stay hiddennonenetwork, timeout, server
upsell.addThe offer cannot be addedOn network, timeout or server it loads the order again first: an upsell that got on it counts as accepted. Else the next page after a secondupsell.failedrejected, network, timeout, server
storage.writeBrowser storage is blocked or fullKeeps working from memory; the cart may not carry over to the next pagenoneunavailable
codeMeans
networkNo answer: offline, DNS, CORS, or blocked
timeoutThe SDK stopped waiting, such as the 10-second order load
serverThe API failed (HTTP 5xx)
rejectedThe API refused the request (any other HTTP 4xx)
declinedThe card or the payment gateway declined; only on payment.failed
payment_failedThe gateway sent the shopper back unpaid; only on payment.failed
authThe campaign key is not allowed (HTTP 401, 403)
too_many_requestsRate limited (HTTP 429)
unavailableBrowser storage is blocked or full