Skip to content

Events

The SDK fires events at key moments. Subscribe with appyStamp.on() and unsubscribe with appyStamp.off().

function onReady(data) {
console.log('SDK ready, authenticated:', data.authenticated);
}
appyStamp.on('appy:ready', onReady);
// Later, to stop listening:
appyStamp.off('appy:ready', onReady);

Fires once when the SDK has finished initialising. Shop data has been loaded, and if customer data was provided, the customer has been authenticated.

appyStamp.on('appy:ready', function (data) {
// data.authenticated = true if customer was logged in
if (data.authenticated) {
appyStamp.customer().then(renderLoyaltyWidget);
}
});

Data:

PropertyTypeDescription
authenticatedbooleanWhether a customer was successfully authenticated

Fires when a reward is successfully redeemed via appyStamp.redeem().

appyStamp.on('appy:redeemed', function (data) {
alert('Your discount code: ' + data.code);
});

Data:

PropertyTypeDescription
codestringThe discount code
namestringThe reward name
balancenumberThe customer’s new stamp balance

Fires when any SDK method encounters an error.

appyStamp.on('appy:error', function (data) {
console.error('SDK error in', data.method, ':', data.error);
});

Data:

PropertyTypeDescription
methodstringThe SDK method that failed (e.g. “shop”, “customer”, “redeem/42”)
errorstringThe error message