Add EMI APIs to Custom Widgets

Einstein Marketing Insights (EMI) is an insights discovery tool used to analyze a data set and uncover key highlights that affect your performance in a positive or negative manner. This tool enables you to become proactive with your marketing efforts. The EMI APIs allow you to pull your insight bots and insights into custom widgets.

REQUIRED USER ROLE
To add EMI APIs to widgets Admin and Power User

There are three EMI APIs created for custom widgets: Get Bot Details, List Bots, and Get Bot Results.

  1. In a custom widget, click the edit icon to open the Custom Widget Editor dialog panel.
  2. In the snipped library, click Javascript.
  3. At the bottom, click Einstein Marketing Insights API.
  4. To add the API, click the plus + icon next to the API name.
  • Get Bot Details — This API returns the bot parameters in JSON format. For example, bot name, types of analyses it runs, and its scheduling. When adding the snippet, insert the bot ID in the code so the query knows which bot information to pull. The bot ID can be found in the bot URL. Select the desired bot, then copy the ID from the URL.

    shows bot ID in URL

  • List Bots — This API returns a list of available bots and their general details in the current workspace in JSON format. For example, bot name, KPI, date, and the types of analyses it runs.

    Here is an example of JS code you can copy and paste to utilize the List Bots API:

    Note
    Note Be sure to change the bot id to the bot id you want to retrieve data for. This code snippet returns raw data. You can customize the code to create a visual display of your choice.
    DA.api.EMI.getBotsSummary({cb: (err, data) => { 
      var toPrint = "";
      data.bots.forEach((item, i) => {
        toPrint+= JSON.stringify(data.bots[i]) + "<br><br>"
      })
      
      document.getElementById("demo").innerHTML = toPrint;
    }});
    
  • Get Bot Results — This API extracts the actual insights from a specific bot in JSON format. It includes data for each insight, such as the dimension and value of the insight, its performance, and its volume. Insert the bot ID that you want to populate. The bot ID appears in the URL.

    Here is an example of JS code you can copy and paste to utilize the Get Bot Results API:

    Note
    Note Be sure to change the bot id to the bot id you want to retrieve data for. This code snippet returns raw data. You can customize the code to create a visual display of your choice.
    DA.api.EMI.getInsightsByBotId({botId: 55149, cb: (err, data) => {
      var toPrint = "";
      data.insights.forEach((item, i) => {
        toPrint+= JSON.stringify(data.insights[i]) + "<br><br>"
      })
      
      document.getElementById("demo").innerHTML = toPrint;
    }});
    

If you want to populate several bots, dedicate each API call to a single bot by inserting the desired ID into each API.

Here’s a video about custom widgets: