Send Docs Feedback

Statistics Collector policy

  About | Samples | Element reference | Error codes | Schema | Related topics


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.


This policy can be attached in one of the following locations.

Only one StatisticsCollector policy can be attached to a single API proxy bundle.

ProxyEndpoint TargetEndpoint
    PreFlow Flow PostFlow PreFlow Flow PostFlow    
    PostFlow Flow PreFlow PostFlow Flow PreFlow    

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.


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.

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

Element reference

The element reference describes the elements and attributes of the StatisticsCollector policy.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StatisticsCollector async="false" continueOnError="false" enabled="true" name="Statistics-Collector-1">
    <DisplayName>Statistics Collector 1</DisplayName>
        <Statistic name="name" ref="" type="STRING">value</Statistic>

<StatisticsCollector> attributes

<StatisticsCollector async="false" continueOnError="false" enabled="true" name="Stats-1">
Attribute Description Default Presence

Set to true to specify that the policy should be run in a thread pool different from the pool servicing the request/response flow.

Note: This setting is only used for for internal optimization. Contact Apigee Support via the Support Portal for more information.

false Optional

Set to false to return an error when a policy fails. This is expected behavior for most policies.

Set to true to have flow execution continue even after a policy fails.

false Optional

Set to true to enforce the policy.

Set to false to "turn off" the policy. The policy will not be enforced even if it remains attached to a flow.

true Optional

The internal name of the policy. Characters you can use in the name are restricted to: A-Z0-9._\-$ %. However, the Edge management UI enforces additional restrictions, such as automatically removing characters that are not alphanumeric.

Optionally, use the <DisplayName> element to label the policy in the management UI proxy editor with a different, natural-lanaguage name.

N/A Required

<DisplayName> element

Use in addition to the name attribute to label the policy in the management UI proxy editor with a different, natural-lanaguage name.

<DisplayName>My Stats Collector</DisplayName>
Default: N/A
Presence: Optional
Type: String

<Statistics>/<Statistic> element

    <Statistic name="name" ref="" type="STRING">value</Statistic>
Attribute Description Default Presence

Custom name provided for the referenced variable. The name cannot contain spaces or dashes. In the example below, the referenced variable is

The following restrictions apply:

N/A Required

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.

N/A Optional

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.

N/A Optional

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}


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

Related topics

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


Help or comments?

  • If something's not working: Ask the Apigee Community or see Apigee Support.
  • If something's wrong with the docs: Click Send Docs Feedback on this page.
    (Incorrect? Unclear? Broken link? Typo?)