Triggered UI Events

Default and Custom Events triggered by Swym UI.

❗️

The usage of these Events API is restricted to actions carried out within the default wishlist interface.

The recommended use of these APIs is to update theme-related UI elements only. Utilising them for complex business logic or to modify the default wishlist page or modal could potentially introduce significant risks and may not be officially supported.

Trigger

Events are a way of letting the listener know there was an action or an internal state change. These browser events can be triggered by user interactions or manually on the Swym Event Layer.

swat.triggerSwymEvent

For end-user actions, we can manually trigger events on the Swym Event Layer based on the installed Swym apps.

Definition

swat.triggerSwymEvent(event, product, element)

Example

Here's an example of how you can trigger a remove from wishlist event on the Swym Event Layer when a user removes a product from the Wishlist.

// Define eventname
let event = 'sw:removedfromwishlist';

// Define the event listener function
let listener = function(eventData) { 
  console.log("A product was removed from wishlist", eventData);
  // update button state here...
};

// Add listener for the 'removedfromwishlist' event to the Swym Event Layer
swat.evtLayer.addEventListener(event, listener);

let product = {};
let currentElement = "";

// Manually trigger the 'removedfromwishlist' event for a product
swat.triggerSwymEvent(event, product, currentElement);

Swym JSEvent

Swym JSEvents are events triggered by Swym default UI. We have exposed some events for analytics and other UI actions for the default Wishlist UI.

The Swym JSEvent Object has many events, however we only support the below for merchant / development use case.

swat.JSEvents.customerInfoRefreshed

Triggered when e

Definition

swat.evtLayer.addEventListener(swat.JSEvents.customerInfoRefreshed, function(){});

Swym APIs allow a couple of modes of connecting shopper accounts either via a native storefront login or a via connect link.

Native storefront login is detected asynchronously and raises a Swym JSEvent swat.JSEvents.customerInfoRefreshed which can be subscribed.

Example

// Define event
let event = swat.JSEvents.customerInfoRefreshed;

// Define listener
let listener = function(evt) {
  swat.authCheck(function(shopperContext) {
    
  });
};

swat.evtLayer.addEventListener(event, listener);

Success Response

{
  "authn": true,
  "email": "shopper email",
  "regn": {
    "userinfo": { // where available
      "fname": "", // where available
      "lname": "", // where available
      "acc_mkt": null // accepts marketing flag - boolean where available
    }
  }
}
{
  "authn": false,
  "email": null
}

📘

Find something missing?

In the event of any incorrect or incomplete information, please reach out to [email protected] and we will get back to you.