Skip to main content

Simple Google Analytics API data extraction.

Project description

Freesixty

A simple Google Analytics API data extraction.

Simple example:

1. Install freesixty

pip install freesixty

2. Get data

import freesixty

SCOPES = ['https://www.googleapis.com/auth/analytics.readonly']
KEY_FILE_LOCATION = 'gcp_keyfile.json'
VIEW_ID = 'XXXXXXX'

query = {
    'reportRequests': [
    {
        'viewId': VIEW_ID,
        'dateRanges': [{'startDate': '2009-01-01', 'endDate': '2019-01-05'}],
        'metrics': [{'expression': 'ga:sessions'}],
        'dimensions': [{'name': 'ga:country', 'name': 'ga:date'}]
    }]
}

folder_uri = 'file:///tmp/example/folder'
analytics = freesixty.initialize_analyticsreporting(KEY_FILE_LOCATION)
freesixty.store_query(analytics, query, folder_uri, 'json')

3. Use it

ls /tmp/example/folder

4. Profit

:cake:

Splitting query example

In case a query would return over 100k rows of data it will fail. We can get around it by splitting the date range into smaller chunks. E.g.:

queries = freesixty.split_query(query=query, start_date='2019-01-01', end_date='2019-02-01', freq='D')

for q in queries:
    freesixty.store_query(analytics, query, folder_uri, 'json')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

freesixty-0.1.1.tar.gz (4.9 kB view hashes)

Uploaded Source

Built Distribution

freesixty-0.1.1-py2.py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page