---
title: "Compute a Sankey diagram"
method: POST
path: "/api/v2/product-analytics/sankey"
tags: ["Product Analytics"]
---

# Compute a Sankey diagram

`POST /api/v2/product-analytics/sankey`

## Request

- Base URL: `https://api.datadoghq.com`
- URL: `https://api.datadoghq.com/api/v2/product-analytics/sankey`
- Auth: one of:
  - API key in header `DD-API-KEY` and API key in header `DD-APPLICATION-KEY`
  - OAuth 2
    - Authorization code: `/oauth2/v1/authorize`
    - Token URL: `/oauth2/v1/token`
- TypeScript: <https://skmtc.dev/datadog/apis/datadog-api-v2-collection/docs/api/v2/product-analytics/sankey/post.ts> (a function with typed inputs; its response is checked against the schema)

Compute a Sankey diagram of how sessions flow between the values of two facets,
showing where users continue and where they drop off at each step.

## Request body

- ProductAnalyticsSankeyRequest: Request body for a Sankey diagram query.
  - `data` ProductAnalyticsSankeyRequestData, required: The single JSON:API resource carrying a Sankey query. Its attributes hold the time window to query, the search that selects the sessions, and the definition of the diagram to build.
    - `attributes` ProductAnalyticsSankeyRequestAttributes, required: Attributes of a Sankey request.
      - `definition` ProductAnalyticsSankeyDefinition, required: The shape of the Sankey diagram, expressed as the facets to flow between and how many steps to show.
        - `entries_per_step` integer: Maximum number of nodes to keep in each column. Remaining values are rolled up into an aggregated node. Omit it, or send `0`, to use the default of `5`.
        - `number_of_steps` integer: Number of intermediate columns between the source and the target. Omit it, or send `0`, to use the default of `5`.
        - `source` string, required: Facet forming the first column of the diagram.
        - `target` string, required: Facet forming the last column of the diagram.
      - `search` ProductAnalyticsSankeySearch, required: Selects the sessions a Sankey diagram is built from.
        - `audience_filters` ProductAnalyticsAudienceFilters: Audience filter definitions for targeting specific user segments.
          - `accounts` ProductAnalyticsAudienceAccountSubquery[]: Account audience queries.
            - `name` string, required: Name of this query, referenced in the formula.
            - `query` string: Search query for filtering accounts.
          - `formula` string: Boolean formula combining audience queries by name.
          - `segments` ProductAnalyticsAudienceSegmentSubquery[]: Segment audience queries.
            - `name` string, required: Name of this query, referenced in the formula.
            - `segment_id` string, uuid, required: UUID of the segment to filter by.
          - `users` ProductAnalyticsAudienceUserSubquery[]: User audience queries.
            - `name` string, required: Name of this query, referenced in the formula.
            - `query` string: Search query for filtering users.
        - `join_keys` ProductAnalyticsJoinKeys: Identity join keys used to stitch events belonging to the same user or session.
          - `primary` string: Primary identity join key. Defaults to `@session.id`.
          - `secondary` string[]: Additional identity join keys.
        - `query` string: Datadog search query restricting the events considered.
      - `time` ProductAnalyticsSankeyTime, required: The time window a Sankey query covers.
        - `from` integer, required: Start of the query window, in epoch milliseconds.
        - `to` integer, required: End of the query window, in epoch milliseconds.
    - `type` 'sankey_request', required: The resource type identifier for a Sankey request.

## Response `200`

OK

- ProductAnalyticsSankeyResponse: Response for a Sankey diagram query.
  - `data` ProductAnalyticsSankeyResponseData, required: The single JSON:API resource holding a computed Sankey diagram. Its attributes contain the nodes of every column and the links that carry sessions between them.
    - `attributes` ProductAnalyticsSankeyResponseAttributes, required: Attributes of a Sankey response, containing the nodes and the links between them.
      - `links` ProductAnalyticsSankeyLink[]: The links of the diagram, one per pair of connected nodes.
        - `column` integer: Zero-based index of the column the link starts from.
        - `id` string: Unique identifier for the link.
        - `source` string: Identifier of the node the link starts at.
        - `target` string: Identifier of the node the link ends at.
        - `value` integer: Number of sessions flowing along the link.
      - `nodes` ProductAnalyticsSankeyNode[]: The nodes of the diagram, one per facet value and column.
        - `aggregated_nodes` ProductAnalyticsSankeyAggregatedNode[]: The nodes rolled up into this one, when the node is an aggregate.
          - `id` string: Unique identifier for the node.
          - `incoming_value` integer: Number of sessions entering the node.
          - `name` string: The facet value the node represents.
          - `outgoing_value` integer: Number of sessions leaving the node.
          - `type` 'aggregated': The resource type identifier for a node rolled up into an aggregated node.
          - `value` integer: Number of sessions passing through the node.
        - `column` integer: Zero-based index of the column the node sits in.
        - `dropoff_value` integer: Number of sessions that ended at the node.
        - `id` string: Unique identifier for the node.
        - `incoming_value` integer: Number of sessions entering the node.
        - `name` string: The facet value the node represents.
        - `outgoing_value` integer: Number of sessions leaving the node.
        - `type` 'regular' | 'other' | 'dropoff': The kind of node. `regular` is a single facet value, `other` rolls up the values that did not fit within `entries_per_step`, and `dropoff` collects the sessions that ended at this column.
        - `value` integer: Number of sessions passing through the node.
    - `id` string, required: Unique identifier for this response data object.
    - `type` 'sankey_response', required: The resource type identifier for a Sankey response.

## Other responses

- `400`: Bad Request
- `403`: Not Authorized
- `429`: Too many requests

---

[API](https://skmtc.dev/datadog/apis/datadog-api-v2-collection.md) - [All operations](https://skmtc.dev/datadog/apis/datadog-api-v2-collection/llms.txt) - [OpenAPI document](https://skmtc.dev/datadog/apis/datadog-api-v2-collection/revisions/3f70db624329?raw)
