Creating a Metric from a Service

Generate a data feed from a supported SaaS service via the query builder, then create a metric from it.

  1. GET /query_builder/services — list the available services.

  2. GET /data_feed_connections?queryBuilderService=<serviceName> — find (or confirm) a connection for that service.

  3. GET /query_builder/services/:serviceName/views?connectionId=<connectionId> — list the views available on that connection.

  4. GET /query_builder/services/:serviceName/views/:viewName/fields?connectionId=<connectionId> — list the view's fields, to build the query below.

  5. POST /data_feeds/generate?type=queryBuilder — generate the feed (see the Data Feeds guide for the full query field shape):

    {
      "connectionId": "cd882b55c245465e93857cd331cb3ffa",
      "viewName": "orders",
      "query": {
        "fields": [
          { "name": "NewUsers", "filters": [], "filterOption": "all" },
          { "name": "Country", "filters": [], "filterOption": "all" },
          { "name": "Channel", "filters": [], "filterOption": "all" }
        ]
      }
    }
  6. POST /metrics — see Creating the metric from the feed below.

Creating the metric from the feed

POST /data_feeds/generate returns a feed with an id and columns[] (each with its own id); the metric then points at the feed itself, not at any underlying datasource:

{
  "name": "New Users",
  "description": "New users reported by the service, by country and channel",
  "sourceType": "DATAFEED",
  "sourceId": "<feed id>",
  "fieldId": "<id of the value column>",
  "dimensions": [
    { "name": "Country", "fieldId": "<id of the country column>" },
    { "name": "Channel", "fieldId": "<id of the channel column>" }
  ]
}

Use the id of a metric-shaped column (e.g. a numeric column with an aggregation) for fieldId. If the feed has more than one date column and the metric should key off a specific one, set timeRefId to that column's id; otherwise it can be omitted. Other columns you want as filter/group-by dimensions go in dimensions[], each with that column's id as fieldId — as with the two above, which make the metric filterable and groupable by country and by channel. Only the view fields you asked for in the generate query become columns, so add a field there for every dimension you want.


Did this page help you?