Most computations are handled by a metric handler, the remainder are calculated by the report property mapper. The report property mapper is able to compute values that involve more than one metric handler. For example, to determine the average number of orders submitted per session, you rely on a metric handler components to add up the total number of submitted orders (OrderSubmittedMetricHandler) and sessions (SessionMetricHandler), and configure the report property mapper to divide the submitted order total by the session total.

Unlike a metric handler, the report property mapper executes when a user requests the Results tab in the ATG Campaign Optimizer UI. Be aware that complex computations may delay the Results tab display so design your report property mapper to evaluate simple calculations in order to ensure optimal performance. The metrics calculated by the report property mapper are not saved to the database and, therefore, are discarded after they are generated.

Averages are a good example of computations that should be handled by a report property mapper, even when averages involve values managed by one metric handler. It is more efficient to calculate averages when they are needed because they are quick to compute so saving them to the database would consume more resources than is worthwhile.

To modify the report property mapper to perform a calculation for your metric, complete the following tasks:

  1. Extend the existing Property Mapper class by creating a subclass of atg.abtest.web.reporting.PropertyMapper. If you are running ATG Commerce, subclass atg.abtest.web.commerce.reporting.CommercePropertyMapper instead. Add your class to the CLASSPATH.

  2. Code your subclass to perform the necessary calculation. See Average Order Price Sample Code below.

  3. Create a new properties file for the report property mapper component and include your new class as such:

    $class=packageName.classNameUpdate

    where packageName is the package and classNameUpdate is the class name.

  4. Save your new properties file as <ATG10dir>/home/localconfig/atg/
    abtest/web/reporting/PropertyMapper.properties
    .

Note: Be sure to add your property to the metric info component metricIds property so that it appears in the report. See Configuring a Metric Info Component for details.

Average Order Price Sample Code

Here’s the code used by ATG Campaign Optimizer for Commerce to implement the average order price metric. This code accesses the price total (revenue) for all orders and the total number of orders. Then, it divides the order total by the price total to produce the average revenue.

public Object getPropertyValue(RepositoryItem pItem, String pPropertyName) {

if (pPropertyName.equals("avgRevenuePerOrder")) {

  // Average revenue per order = revenue ordered / orders

  Double  revenueOrdered = (Double)  pItem.getPropertyValue("revenueOrdered");
  Integer orders         = (Integer) pItem.getPropertyValue("orders");
  if (revenueOrdered == null || orders == null || orders.intValue() == 0)
    return null;
  return new Double(revenueOrdered.doubleValue() / orders.doubleValue());
}
else {
      return super.getPropertyValue(pItem, pPropertyName);
    }
  }
}