WebView JS API reference
When running inside a WebView, the LoyaltyLion JS SDK exposes additional APIs the parent mobile app can use to trigger updates and pass information
WebView APIs can be used by executing JavaScript inside the WebView and calling
loyaltylion.webview.methodName
, where methodName
is one of the documented
API methods below.
Interacting with the JS API is typically not required for a basic WebView setup, but is often used to support advanced features
Unless otherwise specified, you must wait for the LoyaltyLion SDK to report that it has finished loading before using WebView APIs. You can do this by listening to the sdkReady event.
setShopifyCartState
loyaltylion.webview.setShopifyCartState
This can be used to inform the LoyaltyLion SDK about the current Shopify cart state, which is needed for some functionality. For example, free product rewards often require a cart to contain a paid item before they can be redeemed, so the SDK needs to know about the cart first.
setShopifyCartState
expects a single argument, which should be a JSON object
representing the cart state. All fields can be retrieved from the Storefront API
Cart object.
Properties
The ID of the cart
The total amount of the customer to pay, as a decimal money amount. From cost.totalAmount.amount
on the Storefront API Cart
object.
An array of objects describing the current lines on the cart