Skip to content

Metric Tree Attribution

1. Overview

Metric tree attribution is used to break down and analyze complex metrics composed of multiple submetrics. The metric tree structure helps identify where growth comes from automatically.

Metric tree attribution supports:

  • Time-comparison attribution (tree_time_compare)

  • Peer-comparison attribution (tree_peer_compare)

Both modes use the same input structure; only the comparison method differs.

2. API URL

Time-Comparison Attribution

POST /anymetrics/api/v1/attribution/tree_time_compare

Peer-Comparison Attribution

POST /anymetrics/api/v1/attribution/tree_peer_compare

3. Common Request Headers

parameter Name Type required Description
tenant-id String Yes Tenant ID used to specify the workspace
auth-type String Yes Authentication method. Supports UID, TOKEN, ACCOUNT, and APIKEY.
auth-value String Yes Authentication value corresponding to auth-type.

Description:
Common parameters can be obtained in Aloudata CAN > API Integration.

image.png


4. Request parameters(Request Body)

Field Name Type required Description
metricTreeDef Object Yes Metric tree definition returned by the breakdown API
attribution Object Yes Attribution calculation configuration, including comparison mode and filters

4.1 metricTreeDef Structure

Returned by the metric breakdown API (breakdown):

  • metricTreeNodes: metric name for each node

  • metricTree:Expression for each node, referencing child nodes

  • metricDefinitions:Temporary metric definitions

  • rootNode:Root node ID

Example from breakdown:

{
  "rootNode": "node_001",
  "metricTree": {
    "node_001": "[node_002] - [node_003]",
    "node_002": "[node_004] * [node_005]"
  },
  "metricTreeNodes": {
    "node_001": "profit",
    "node_002": "revenue",
    "node_003": "cost",
    "node_004": "order_count",
    "node_005": "price"
  }
}

4.2 attribution Structure

Time comparison:

Field Name Type Description
attributionCalculateType String AVG (average attribution)
filters Array Global filters
currentTimeConstraint String Current time-range expression
compareTimeConstraint String Comparison time-range expression

Peer comparison:

Field Name Type Description
attributionCalculateType String AVG (average attribution)
filters Array Global filters
currentObject Object Current object (filters + timeConstraint)
compareObject Object Comparison object (filters + timeConstraint)

5. Request Example

5.1 Time-Comparison Example (tree_time_compare)

{
  "metricTreeDef": {
    "rootNode": "node_001",
    "metricTree": {
      "node_001": "[node_002] - [node_003]",
      "node_002": "[node_004] * [node_005]"
    },
    "metricTreeNodes": {
      "node_001":"profit",
      "node_002":"revenue",
      "node_003":"cost",
      "node_004":"order_count",
      "node_005":"price"
    }
  },
  "attribution": {
    "filters": [],
    "attributionCalculateType": "AVG",
    "currentTimeConstraint": "datetrunc[metric_time],\"day\")=\"2025-07-07\"",
    "compareTimeConstraint": "datetrunc[metric_time],\"day\")=\"2025-07-06\""
  }
}

5.2 Peer-Comparison Example (tree_peer_compare)

{
  "metricTreeDef": { ... },
  "attribution": {
    "filters": [],
    "attributionCalculateType": "AVG",
    "currentObject": {
      "filters": ["[store]=\"Hangzhou Store\""],
      "timeConstraint": "datetrunc[metric_time],\"day\")=\"2025-07-07\""
    },
    "compareObject": {
      "filters": ["[store]=\"Nanjing Store\""],
      "timeConstraint": "datetrunc[metric_time],\"day\")=\"2025-07-06\""
    }
  }
}

6. Response Structure

The response is a map. Each key is a node ID, and each value is the attribution result for that metric.

Example structure:

{
  "node_001": {
    "@currentValue": 10.0,
    "@compareValue": 12.0,
    "@growth": -2.0,
    "@growthRate": -0.166,
    "@overallContributionRate": -0.5,
    "@relativeContributionRate": -0.3
  },
  "node_002": { ... }
}

7. Field Descriptions

Field Name Description
@currentValue Calculated value of the current object or current time range
@compareValue Calculated value of the comparison object or comparison time range
@growth Growth value,= current - compare
@growthRate Growth rate,= (current - compare) / compare
@overallContributionRate Contribution ratio in the full metric tree
@relativeContributionRate Relative contribution value, usually used for sorting

8. Call Example

8.1 Metric Tree Attribution (Time Comparison)

Query Request:

curl --location --request POST 'http://127.0.0.1:8083/anymetrics/api/v1/attribution/tree_time_compare' \
--header 'auth-type: UID' \
--header 'tenant-id: tn_19487697' \
--header 'auth-value: 463663891121963008' \
--header 'Accept-Language: zh-CN' \
--header 'Content-Type: application/json' \
--data-raw '{
  "metricTreeDef": {
      "rootNode": "node_693597278",
        "metricTree": {
            "node_693597278": "(([node_2083930844])) / ([node_1553155881])"
        },
        "metricTreeNodes": {
            "node_2083930844": "sum_quantity1",
            "node_1553155881": "countDistinct_sales_id",
            "node_693597278": "avgslM06"
        }
  },
  "attribution": {
    "filters": [],
    "attributionCalculateType": "ALL",
    "currentTimeConstraint": "datetrunc([metric_time],\"day\")=\"2025-07-07\"",
    "compareTimeConstraint": "datetrunc([metric_time],\"day\")=\"2025-07-06\""
  }
}'

Response Example

{
    "data": {
        "node_2083930844": {
            "@currentValue": 3171.0,
            "@relativeContributionRate": 0.0,
            "@compareValue": 3412.0,
            "@growthRate": -0.070633,
            "@growth": -241.0
        },
        "node_1553155881": {
            "@currentValue": 3171.0,
            "@relativeContributionRate": 0.0,
            "@compareValue": 3412.0,
            "@growthRate": -0.070633,
            "@growth": -241.0
        },
        "node_693597278": {
            "@currentValue": 1.0,
            "@compareValue": 1.0,
            "@growthRate": 0.0,
            "@growth": 0.0
        }
    },
    "success": true,
    "code": "200",
    "errorMsg": null,
    "detailErrorMsg": null,
    "traceId": "cced9e32f6aa4b3eb03905b51054ad4d.194.17780536606010059"
}

8.2 Metric Tree Attribution (Peer Comparison)

Request Example

curl --location --request POST 'http://127.0.0.1:8083/anymetrics/api/v1/attribution/tree_time_compare' \
--header 'auth-type: UID' \
--header 'tenant-id: tn_19487697' \
--header 'auth-value: 463663891121963008' \
--header 'Accept-Language: zh-CN' \
--header 'Content-Type: application/json' \
--data-raw '{
    "metricTreeDef": {
        "rootNode": "node_693597278",
        "metricTree": {
            "node_693597278": "(([node_2083930844])) / ([node_1553155881])"
        },
        "metricTreeNodes": {
            "node_2083930844": "sum_quantity1",
            "node_1553155881": "countDistinct_sales_id",
            "node_693597278": "avgslM06"
        }
    },

    "attribution": {
        "filters": [],
        "attributionCalculateType": "AVG",
        "currentObject": {
            "filters": [
                "[brand]=\"Baiwei\""
            ],
            "timeConstraint": "datetrunc[metric_time],\"day\")=\"2025-07-07\""
        },
        "compareObject": {
            "filters": [
                "[brand]=\"Dianfan\""
            ],
            "timeConstraint": "datetrunc[metric_time],\"day\")=\"2025-07-07\""
        }
    }
}'

Response Example

{
    "data": {
        "node_2083930844": {
            "@currentValue": 105397.0,
            "@relativeContributionRate": 0.0,
            "@compareValue": 105397.0,
            "@growthRate": 0.0,
            "@growth": 0.0
        },
        "node_1553155881": {
            "@currentValue": 105397.0,
            "@relativeContributionRate": 0.0,
            "@compareValue": 105397.0,
            "@growthRate": 0.0,
            "@growth": 0.0
        },
        "node_693597278": {
            "@currentValue": 1.0,
            "@compareValue": 1.0,
            "@growthRate": 0.0,
            "@growth": 0.0
        }
    },
    "success": true,
    "code": "200",
    "errorMsg": null,
    "detailErrorMsg": null,
    "traceId": "2537fe72c3f84f51892047a537d3592a.183.17780539097420057"
}