Skip to main content

Simple Google Analytics API data extraction.

Project description

Freesixty

A simple Google Analytics API data extraction.

Installation

pip install freesixty

Access credentials

To set up access to your Google Analytics follow first step of these instructions. Store them in your local machine and enter their path into KEY_FILE_LOCATION variable.

Get data

import freesixty

KEY_FILE_LOCATION = './client_secrets.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'}]
    }]
}

analytics = freesixty.initialize_analyticsreporting(KEY_FILE_LOCATION)
result, is_data_golden = freesixty.execute_query(analytics, query)

On the other hand if we want to store resulting data to a desired URI.

import freesixty

KEY_FILE_LOCATION = './client_secrets.json'
VIEW_ID = 'XXXXXXX'
folder_uri = 'file:///tmp/example/folder'

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'}]
    }]
}

analytics = freesixty.initialize_analyticsreporting(KEY_FILE_LOCATION)
freesixty.store_query(analytics, query, folder_uri)

Getting more data

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:

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

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

Useful links

TODO:

  • More complete tests

:cake:

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.25.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

freesixty-0.1.25-py2.py3-none-any.whl (5.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file freesixty-0.1.25.tar.gz.

File metadata

  • Download URL: freesixty-0.1.25.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.8

File hashes

Hashes for freesixty-0.1.25.tar.gz
Algorithm Hash digest
SHA256 1e52d5ff8763fca49e1c8b59308f8046ab8c9e7610eb04779df3fecc5c908ba0
MD5 0171780d6445efaad91b4a24337f3150
BLAKE2b-256 b3451c98558e8d8a9abcc2ba829dc2ec39ac66f765c3c35b689516922c089d40

See more details on using hashes here.

File details

Details for the file freesixty-0.1.25-py2.py3-none-any.whl.

File metadata

  • Download URL: freesixty-0.1.25-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.8

File hashes

Hashes for freesixty-0.1.25-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 208f874716187cf20149a58fec8180a837ce471b9883cfd987826fe3d378ccab
MD5 c8596ffbe012d011061e8a8dcbe0b3af
BLAKE2b-256 2b9d1f7eeef3c1e35fb123e72476953d4ac7c0c6fe8defa2ddccfe2ff614f215

See more details on using hashes here.

Supported by

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