JavaScript Injection
Selection-Change Callback#
SureBright fires a callback whenever the customer's protection selection changes — when they select a plan, switch plans, or deselect. Use it to react to those changes in your own code; for example, to update the price shown on your page so it reflects the selected protection.
The callback lives on the same window.SureBright global you use for initialize.
1. Register a Handler#
Pass your handler to window.SureBright.onSelectionChange. SureBright invokes it on every selection change and passes a selectionChange object that describes what changed. Read the price from that object to update your page — SureBright never modifies your page's price elements for you.
window.SureBright.onSelectionChange(function (selectionChange) {
if (selectionChange.action === "selected" && selectionChange.pricing) {
// Protection added — the total now includes the selected plan.
console.log(selectionChange.pricing.totalPrice, selectionChange.pricing.currency);
} else {
// Protection removed — fall back to the base product price.
console.log(selectionChange.pricing?.basePrice, selectionChange.pricing?.currency);
}
});onSelectionChange returns a function that unsubscribes your handler. Keep a reference to it only if you need to stop listening later.
2. Read the Selection Change#
Each call receives a single selectionChange object describing what the customer did:
actionstringrequiredThe kind of change. Either selected or deselected.
sourcestringrequiredThe widget surface the change came from: pdp, quickview, cart, checkout, postPurchase, registration, or shippingInsurance.
quoteobject | nullThe selected protection plan. Present on a selected action from a surface that exposes a full quote; null on deselected or where a quote isn't available.
productobject | nullThe product the customer was viewing. null when product data isn't available at selection time.
pricingobject | nullComputed price breakdown for the selection. null when the base product price is unknown.
