messageCallback

    messageCallback


    Article summary

    Shoplive Shortform provides a messageCallback function that lets you handle any events that happen within the Shortform.

    Installation sample code

    Install the below code to the common layout of the page

    <script type="text/javascript" src="https://static.shoplive.cloud/shoplive-shortform.js"></script>
    <script>
      const messageCallback: { 
        LOGIN_REQUIRED: function(payload) {
          alert("LOGIN_REQUIRED");
          location.href = "YOUR_LOGIN_PAGE_URL";
        },
        ON_CLICK_PRODUCT_ITEM: function(payload) {
          alert("ON_CLICK_PRODUCT_ITEM");
          location.href = payload.product.url;      
        }
      };
      
      cloud.shoplive.initShortform({ 
        accessKey: 'YOUR ACCESS KEY HERE', 
        messageCallback: messageCallback 
      });
    </script>

    Messages & Payload

    The following is a list of events that can be directly handled by the messageCallback setting.

    LOGIN_REQUIRED

    On clicking where login is required, such as when a user attempts to post a comment.

    Payload

    Type

    type

    string


    ON_CLICK_PRODUCT_ITEM

    On clicking on a product in a product list

    Payload

    Type

    product

    Product

    shorts

    Shorts


    ON_CLICK_SHARE_BUTTON

    On clicking the Share button

    Payload

    Type

    shorts

    Shorts

    url

    string

    DETAIL_ACTIVE

    On activating the Shortform Detail (Shortform video play within the feed)

    Payload

    Type

    shorts

    Shorts

    DETAIL_ON_PLAYER_DISMISS

    On closing the Shortform Detail (Shortform video play within feed)

    Payload

    Type

    N/A

    N/A

    DETAIL_VIEWING_SECONDS

    3 seconds heartbeat when watching a Shortform detail video

    Payload

    Type

    shorts

    Shorts

    videoCurrentTime

    number