Handle the Results

Handling a report response is not trivial, particularly if you want your solution to be flexible and independent of the actual dimensions and metrics you chose in your report.

Thankfully, the report response is pretty complete and includes a lot of useful information.

Headers

You can use the information returned in the headers to choose how to format a particular metric. It includes information on what type of metric it is, whether it’s a currency, ratio or tally for example, and what currency it’s in, if it’s a monetary value.

Example:

"headers": [
  { "name": "MONTH", "type": "DIMENSION" },
  { "name": "CLICKS", "type": "METRIC_TALLY" },
  { "name": "EARNINGS", "type": "METRIC_CURRENCY", "currency": "USD" },
  { "name": "AD_REQUESTS_COVERAGE", "type": "METRIC_RATIO" }
]

Rows

This is where you get the actual report results. Each response row represents a report row, which has a different meaning based on your chosen dimensions.

"rows": [
  { "cells":
    [ {"value": "2021-01"}, {"value": "278"}, {"value": "63.12"}, {"value": "0.9998"} ],
    [ {"value": "2021-02"}, {"value": "39"}, {"value": "8.46"}, {"value": "0.9998"} ]
  }
]

Totals and averages

When you run a report, you also get back the totals and averages utility arrays, which will contain a value for each appropriate metric.

"totals": {
  "cells": [
    {}, {"value": "317"}, {"value": "71.58"}, {"value": "0.9998"}
  ]
},
"averages": {
  "cells": [
    {}, {"value": "158"}, {"value": "71.58"}, {"value": "0.9998"}
  ]
}

Start and end Dates

If you’re using relative dates, it may sometimes be useful to know what the calculated start and end dates are.

"startDate": {"year": 2021, "month": 1, "day": 1},
"endDate": {"year": 2021, "month": 2, "day": 28}

Next steps