Create a Data Collection Action

In some cases when you trigger an action, you might not want to alter your site's content while still retaining the customer data involved with the action. In these cases, you can perform a data collection action.

You can set up a handler for a data collection action by 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 decision based on the defined events. getActionsData then returns a JSON object containing customer data.

While this data does not affect your site's content, you can use it for other cases elsewhere in code.

addEvent

This method adds a local event to the SDK's internal stack.

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

Parameters:

  • context is name of the event.
  • events is the event data.

You can use this method multiple times to add all the necessary events for an experience you might want to trigger. The example code uses multiple method calls to fulfill the experience requirements:

personalizationInstance.addEvent(EventTypes.ContextScreenSize,
{
  width: 23,
  height: 34
});
personalizationInstance.addEvent(EventTypes.ContextIpAddress,
{
  ipAddress: "10.0.0.2",
});
personalizationInstance.addEvent(EventTypes.ContextPageView,
{
  url: "http://www.monetate.com/index.html",
  pageType: "Home"
});

getActionsData

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

getActionsData(actionType: Array<string>, includeReporting: boolean) : Promise<any>

Parameters:

  • actionType is the type of action you want to request. You can specify multiple actions in an array to handle.
  • includeReporting indicates whether the response will have impression reporting data.

Use DataCollection as the action type for this method.

includeReporting must be set to true for this method to return data.

responseData = personalizationInstance.getActionsData("monetate:action:DataCollection");

Full Code Example

Complete code example blocks are listed below.

// Add Context / Events
// ----------------------------------------------------
personalizationInstance.addEvent(EventTypes.ContextScreenSize,
{
  width: 23,
  height: 34
});
personalizationInstance.addEvent(EventTypes.ContextIpAddress,
{
  ipAddress: "10.0.0.2",
});
personalizationInstance.addEvent(EventTypes.ContextPageView,
{
  url: "http://www.monetate.com/index.html",
  pageType: "Home"
});
// ----------------------------------------------------
// Get Actions
let recData;
personalizationInstance
  .getActionsData("monetate:action:DataCollection", true)
  .then(res =>
  {
    recsData = res[0].actions;
  })
  .catch(error =>
  {
    console.warn('Error!', error);
  });