A custom variable of the Function call type can call a class method of an app and pass relevant key values. For example, the event for buying a product in a shopping app contains only the product name. To report the product inventory in this event, perform the following steps:
package com.example.dtm;
import com.huawei.hms.dtm.ICustomVariable;
import java.util.Map;
import com.example.goods.Inventory;
public class InventoryDTMVariable implements ICustomVariable {
@Override
public String getValue(Map<String, Object> params) {
if (params == null) {
return "";
} else {
return new Inventory().query(params.get("goodName"));
}
}
}
