The StatisticsCollector policy type enables you to collect statistical data for messages processed in a flow, such as product ID, price, REST action, client and target URL, and message length (predefined flow variables as well as custom variables). The data is then provided to the analytics server, which analyzes the statistics and generates reports. You can view the reports through Analytics Services.

You attach the StatisticsCollector Policy to the response path in your API proxy, where you can capture and publish a range of statistics to the analytics server.

For more information on how to analyze your data using Apigee analytics, see Analyze API message content using custom analytics.

Configuring a Statistics Collector policy

Configure the StatisticsCollector Policy using the following elements.

Field Name Description
name Custom name provided for the referenced variable. The name cannot contain spaces or dashes. In the example below, the referenced variable is product.id.

The following restrictions apply:

ref Flow variable that can be a predefined variable or a variable defined in the XML payload of the Extract Variables policy. See Extract message content using ExtractVariables.
type Valid values: string/integer/float/long/boolean/double

If provided, overrides the existing datatype of ref. Note that the type can be left empty only if ref is a predefined variable or the type is declared in the XML payload of the Extract Variables policy.

You can set the defaultval as shown in the following example to initialize a variable with a static, default value. If you provide a default value, then the default value you provide will be assigned to the variable the variable only when the variable does not get initialized during the message flow. If you do not provide a defaultval, then the variable is assigned normally during the message flow and calls fail if the variable is not resolved.

 

Example - Statistics Collector policy

<StatisticsCollector name="publishPurchaseDetails">
<Statistics>
<Statistic name="productID" ref="product.id" type="string">{defaultval}</Statistic>
<Statistic name="price" ref="product.price" type="string">{defaultval}</Statistic>
</Statistics>
</StatisticsCollector>

Policy-specific error codes

The default format for error codes returned by Policies is:

{
  "code" : " {ErrorCode} ",
  "message" : " {Error message} ",
  "contexts" : [ ]
}

The StatisticsCollector Policy type defines the following error codes:

Error Code Message
DatatypeMissing StatisticsCollection {0}: Datatype of {1} is missing. Context {2}
UnsupportedDatatype StatisticsCollection {0}: Datatype {1} is unsupported . Context {2}

Policy schema

Each policy type is defined by an XML schema (.xsd). For reference, policy schemas are available on GitHub.

Help or comments?

  • Something's not working: See Apigee Support
  • Something's wrong with the docs: Click Send Feedback in the lower right.
    (Incorrect? Unclear? Broken link? Typo?)