Create an Image-Based Badging Action

The product badging feature allows clients to apply some treatment to specific items on product listing pages and product detail pages to draw site visitors' attention to those items to foster engagement. Product badging highlights key attributes of items that might not otherwise jump out to visitors navigating products on the site.

A product badge frequently appears as a digital promotional sticker displayed atop the product image to indicate that the item is a bestseller or a top-rated product. These labels serve as customer endorsements, allowing shoppers to more quickly locate popular products on a page.

You can set up a handler for Omnichannel badging actions using two methods. The addEvents method defines the events that can trigger the action. The getActionsData method is then used as the trigger and requests the experience based on the defined events. getActionsData then returns a JSON object containing badging image data that you can then handle in code.

Prerequisites

You must first create an Omnichannel badging action within Monetate for the methods to reference. Refer to Configure an Omnichannel Product Badging Action for instructions.

This action uses Product Thumbnail View as an event listener. To accomplish this, you must set Thumbnail's product ID = as one of the conditions. Make note of this product ID so that you can pass the appropriate ID in code.

Optionally, you can add other conditions to this action. If you do, make note of those so that you can pass those as relevant events.

addEvents

This method records a local event.

addEvent(context: EventTypes, events: ContextData): void

Parameters:

  • context is name of the event. (Required)
  • events is the event data. (Required)

For an Omnichannel Badging action, use the ContextProductThumbnailView event as your context. Pass a list of product IDs that you want to set up a badge for as your events data.

coreSdkInstance.addEvent(EventTypes.ContextProductThumbnailView, {
  products: ["SLBC", "99"],
});

If you added other conditions to your Omnichannel Badging action, use additional calls of this method to handle them with the appropriate events and data.

getActionsData

This method sends the defined events to Monetate to trigger an experience. If the events fulfill the WHO settings of an experience, that experience is triggered. A JSON object containing the experience response is then returned.

getActionsData(actionType: ActionType) : Promise<any>

Parameters:

  • actionType is the type of action you want to request. You can specify multiple actions in an array to handle. (Required)

Use OmniChannelImageBadging as the action type for this method.

let imageBadge;
personalizationInstance
  .getActionsData(ActionTypes.OmniChannelImageBadging)
  .then(res => {
    imageBadge = res[0].actions;
  })
  .catch(error => {
    console.warn('Error!', error);
  });

Full Code Example

Complete code example blocks are listed below.

// Add the required events used in experience.

personalizationInstance.addEvent(EventTypes.ContextProductThumbnailView, {
  products: ["SLBC", "99"],
});

// -----------------------------
// Fetch badging experience data 
 
let imageBadge;
personalizationInstance
  .getActionsData(ActionTypes.OmniChannelImageBadging)
  .then(res => {
    imageBadge = res[0].actions;
  })
  .catch(error => {
    console.warn('Error!', error);
  });

Response Data

An example of the JSON data returned from getActionsData is below. Handle this response in your code accordingly to render the data in your UI as you see fit.

{
  "actions": [
    {
      "image_content": {
        "version": 2,
        "clickzones": [],
        "contentId": 775504,
        "top": 0,
        "title": "Test-Badge",
        "href": "https://marketer.monetate.net",
        "iwidth": 40,
        "alt": "Alt-Test-Badge",
        "iheight": 40,
        "ref": "https://sb.monetate.net/img/1/1094/4631519.jpg",
        "left": 180
      },
      "actionType": "monetate:action:OmniChannelImageBadging",
      "actionId": 4959427,
      "application_data": {
        "test": "React-native SDK"
      },
      "positioning_hint": "center",
      "pids": [
        "99",
        "SLBC"
      ]
    }
  ],
  "requestId": "81.2272963332645"
}