hook
is a promise-returning callback function that you provide and that the
LoyaltyLion SDK executes when certain hook-enabled events occur.
Hooks enable you to ‘hook into’ certain frontend workflows, giving you an
opportunity to make calls to other services, render your own UI, and influence
the behavior of the LoyaltyLion SDK.
For example, you may provide a hook
for the customers.rewards.claimed
hook
event that calls a storefront API to automatically add a discount to the cart,
or make a call to your own app to trigger fulfillment of a custom reward.
Your hook
should return a promise which resolves to an object which contains
an action
property. The action
is a string that informs what the LoyaltyLion
UI should do next.
Each kind of hook
has its own set of supported actions, depending on the
underlying use case and workflow.
loyaltylion.registerHook
method. This method
accepts two arguments:
hookName
- string, name of the hooked event to registercallback
- the function to be called when the hooked event occursready
, see below for an
example.
hook
must return a response with a valid action
within 5 seconds. If it
returns an invalid payload or doesn’t resolve in time, the LoyaltyLion SDK
uses the default action and proceed as if no hook was registered.
claimedReward
property matching
the schema of our rewards API.
Action string | UI result |
---|---|
hide_claim_modal | The LoyaltyLion SDK’s claimed reward modal is closed |
show_claim_modal | The LoyaltyLion SDK shows its standard post claimed reward modal content |
show_claim_modal
action is used as the default in case of invalid
return value or timeout.