You should only subscribe to events that you intend to handle. The LoyaltyLion
SDK checks which handlers have been registered and uses that to conditionally
enable functionality.For example, free product rewards will only be
redeemable if the appropriate events (
addCartLine
, etc) have been registered.Listening to events
The events themselves are the same for both iOS and Android, so the only difference is how to subscribe to them.On iOS, we emit events using the WKScriptMessageHandler interface. Use your
WKUserContentController
to subscribe to the events you’re interested in.sdkReady
This event is emitted once the LoyaltyLion SDK has finished loading. At
this point, the WebView JS API can be
used to interact with the LoyaltyLion SDK running within the WebView.
Example
addCartLine
This event is emitted when a shopper has redeemed a free product reward, and we
need a new line to be added to the cart for the product.
The product data will contain a hidden attribute that our Shopify Function will pick
up and automatically apply a discount to the item.
The message body will be an object containing the merchandise ID, quantity
and attributes that should be added to the cart via a
cartLinesAdd
mutation.
Message body
The ProductVariant ID to add to the cart.Example:
gid://shopify/ProductVariant/1001
The Product ID to add to the cart.Example:
gid://shopify/Product/100
The quantity of the item to add.
An object containing attributes that should be included with the merchandise line.Example:
Example
The message body will be automatically parsed, so they can
be typecast to retrieve the values.
removeCartLine
This event is emitted when we need to remove a line from the cart. This
typically occurs when the shopper cancels a previously-redeemed free product
reward.
The message body will be an object containing the lineId
that should be removed from the cart via a
cartLinesRemove
mutation.
Message body
The CartLine ID to remove from the cart.Example:
gid://shopify/CartLine/19fdf4cb-5495-4c2f-83d0-40c6a4898f5e
The ProductVariant ID of the CartLine that is being removed from the cart.Example:
gid://shopify/ProductVariant/1001
The Product ID of the CartLine that is being removed from the cart.Example:
gid://shopify/Product/100
The quantity of the CartLine that is being removed from the cart.
An object containing the attributes of the CartLine that is being removed from the cart.
Example
The message body will be automatically parsed, so they can
be typecast to retrieve the values.