Hande 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.

Example:

"rows": [
  [ "2014-01", "278", "63.12", "0.9998" ],
  [ "2014-02", "39", "8.46", "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.

Example:

"totals": [ "", "317", "71.58", "0.9998" ]
"averages": [ "", "158", "35.79", null ]

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.

Example:

"startDate": "2014-01-01"
"endDate": "2014-02-28"

Next steps