Skip to main content

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

🍰

Release files for freesixty 0.1.32

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for freesixty 0.1.32
File Size Uploaded
freesixty-0.1.32.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for freesixty 0.1.32
File Interpreter ABI Platform
freesixty-0.1.32-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 12.5 kB

Release files / freesixty-0.1.32.tar.gz

Download URL freesixty-0.1.32.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
667932fc8559891381cf22b38fbb1d5dac6e4da99a86517cdc493af5cc28b626
BLAKE2b-256 checksum
How to use checksums
9ffa9557d9f7834b5c7219e3bb793dec9d3f2e2877fb4a71abca73785b9992ac
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / freesixty-0.1.32-py2.py3-none-any.whl

Download URL freesixty-0.1.32-py2.py3-none-any.whl
Size 5.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
1c8a6c8ad8b3889eef880761f61713e944402263a1dc62239a10856eceb4221e
BLAKE2b-256 checksum
How to use checksums
3653c94b0e80bbf1ce695c8307a2c62ed52f71180214f5fe0675244c4baa7a4f
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.1.32 This release

2 release files

0.1.31

2 release files

0.1.30

2 release files

0.1.29

2 release files

0.1.28

2 release files

0.1.27

2 release files

0.1.26

2 release files

0.1.25

2 release files

0.1.24

2 release files

0.1.23

2 release files

0.1.22

2 release files

0.1.21

2 release files

0.1.20

2 release files

0.1.19

2 release files

0.1.18

2 release files

0.1.17

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page