mrmatt11
mrmatt11

Reputation: 77

Date Range returning 0 using Google Analytics API

This code, which is based on the sample Google provides here: isn't returning the actual date range, just a 0. I'm pretty sure this is an error.

Can anyone provide guidance?

Result:

Date range: 0
ga:sessions: 1
ga:country: United States

Code:

I'm using the example here: https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-py

Upvotes: 1

Views: 379

Answers (1)

Brett
Brett

Reputation: 1289

The code snippet at https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-py contains the following python:

      for i, values in enumerate(dateRangeValues):
        print('Date range:', str(i))

The Date range: 0 printed in the response is the index of date range from the request. This python code is printing the structure of the API response. In the API response, each ReportRow has a list of DateRangeValues with one for each request DateRange: documentation.

To print a human-readable date range based on the report response, you'll need to combine the request and the response. The response has date range indexes (i.e. 0), and the request has the date ranges (i.e. 'dateRanges': [{'startDate': '7daysAgo', 'endDate': 'today'}],).

Upvotes: 2

Related Questions