GARB is a small Python library that provides an object-oriented interface for building requests for Google Analytics Reporting API v4.
Install garb
using pip:
pip install garb
- Build a request body, e.g.:
import garb
# ...
date_ranges = [garb.daterange.DateRange('7daysAgo', 'today')]
metrics = [garb.metric.Metric('ga:sessions')]
report_requests = [garb.report_request.ReportRequest(VIEW_ID, date_ranges, metrics)]
request_body = garb.report_request.RequestBody(report_requests)
- Pass a
RequestBody
object as a parameter to thebatchGet
method:
def get_report(analytics):
return analytics.reports().batchGet(body=request_body).execute()
GARB is licensed under MIT License.