Events
The SDK fires events at key moments. Subscribe with appyStamp.on() and unsubscribe with appyStamp.off().
Subscribing to events
Section titled “Subscribing to events”function onReady(data) { console.log('SDK ready, authenticated:', data.authenticated);}
appyStamp.on('appy:ready', onReady);
// Later, to stop listening:appyStamp.off('appy:ready', onReady);Available events
Section titled “Available events”appy:ready
Section titled “appy:ready”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:
| Property | Type | Description |
|---|---|---|
authenticated | boolean | Whether a customer was successfully authenticated |
appy:redeemed
Section titled “appy:redeemed”Fires when a reward is successfully redeemed via appyStamp.redeem().
appyStamp.on('appy:redeemed', function (data) { alert('Your discount code: ' + data.code);});Data:
| Property | Type | Description |
|---|---|---|
code | string | The discount code |
name | string | The reward name |
balance | number | The customer’s new stamp balance |
appy:error
Section titled “appy:error”Fires when any SDK method encounters an error.
appyStamp.on('appy:error', function (data) { console.error('SDK error in', data.method, ':', data.error);});Data:
| Property | Type | Description |
|---|---|---|
method | string | The SDK method that failed (e.g. “shop”, “customer”, “redeem/42”) |
error | string | The error message |