Skip to content

Tutorial: Spend per provider

This tutorial shows how to use the API to fetch ad spend broken down by marketing channel (provider) for a given portfolio and date range.

This task can be broken into stages:

  1. Query the portfolio's funnel steps to find the COST step ID
  2. Query daily performance for that funnel step
  3. Fetch providers to translate provider IDs into human-readable names

Apollo Studio

Step 1: Find the COST funnel step ID

Every portfolio has a funnel step of type COST that tracks ad spend. Fetch the portfolio's funnel steps to get its ID.

graphql
query Portfolio($teamId: Int!, $portfolioId: Int!) {
  portfolioV2(teamId: $teamId, portfolioId: $portfolioId) {
    teamId
    portfolioId
    title
    funnelSteps {
      funnelStepId
      type
      title
    }
  }
}

Example response:

json
{
  "data": {
    "portfolioV2": {
      "teamId": 1,
      "portfolioId": 1,
      "title": "Lightning e-commerce",
      "funnelSteps": [
        { "funnelStepId": 329, "type": "COST", "title": "Cost" },
        { "funnelStepId": 330, "type": "AWARENESS", "title": "Impressions" },
        { "funnelStepId": 331, "type": "CONSIDERATION", "title": "Clicks" },
        { "funnelStepId": 333, "type": "CONSIDERATION", "title": "Add to Cart" },
        { "funnelStepId": 334, "type": "CONVERSION", "title": "Orders" },
        { "funnelStepId": 335, "type": "CONVERSION_VALUE", "title": "Revenue" }
      ]
    }
  }
}

The COST funnel step has ID 329. Use this in the next step.

Step 2: Query daily spend per provider

Pass the funnelStepId from Step 1 to get daily adSpend values broken down by provider.

graphql
query SpendPerProvider($teamId: Int!, $portfolioId: Int!, $period: DateRangeInput!, $funnelStepId: Float!) {
  portfolioV2(teamId: $teamId, portfolioId: $portfolioId) {
    performance(period: $period) {
      funnelStep(funnelStepId: $funnelStepId) {
        dailyMetrics {
          day
          providers {
            providerId
            value {
              adSpend
            }
          }
        }
      }
    }
  }
}

Variables:

json
{
  "teamId": 1,
  "portfolioId": 1,
  "period": { "start": "2025-05-01", "end": "2025-05-02" },
  "funnelStepId": 329
}

Example response:

json
{
  "data": {
    "portfolioV2": {
      "performance": {
        "funnelStep": {
          "dailyMetrics": [
            {
              "day": "2025-05-01",
              "providers": [
                { "providerId": 24, "value": { "adSpend": 12345.67 } },
                { "providerId": 60, "value": { "adSpend": 1234.00 } }
              ]
            },
            {
              "day": "2025-05-02",
              "providers": [
                { "providerId": 24, "value": { "adSpend": 11200.50 } },
                { "providerId": 60, "value": { "adSpend": 980.00 } }
              ]
            }
          ]
        }
      }
    }
  }
}

Step 3: Translate provider IDs to names

Provider IDs like 24 and 60 are not self-explanatory. Fetch the providers list to map them to human-readable names.

graphql
query {
  providers {
    provider_id
    name
  }
}

Example response (truncated):

json
{
  "data": {
    "providers": [
      { "provider_id": 24, "name": "Google Ads" },
      { "provider_id": 60, "name": "RTB House" }
    ]
  }
}

With this you can join the results: provider 24 = Google Ads spent 12,345.67 on May 1st, provider 60 = RTB House spent 1,234.00.

Shortcut

If you are building an application and don't want to make a separate providers request on every load, you can hardcode the provider list from the Providers reference page — the IDs are stable and don't change.