• Stars
    star
    168
  • Rank 225,507 (Top 5 %)
  • Language
    Python
  • License
    ISC License
  • Created over 10 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A command-line interface and Python API wrapper for Google Analytics.

Google Analytics for Python and the command-line

Build Status

google-analytics takes the pain out of working with the Google Analytics reporting APIs. It supports both the Core and the Real Time API. It is written in Python but there's also a full-featured command-line interface.

  • Authentication. OAuth2 is a bit of a pain and we've made it easier, both for interactive use and for server applications. We can also save your credentials in the operating system's keychain if you want to.
  • Querying. Easier to query per week, month or year. Query using metric IDs or using their full names, whichever you think is nicer. Work with both the Core and the Real Time APIs.
  • Reporting. Generate reports from the command-line. Optionally describe reports and queries in easy-to-read and easy-to-write YAML files. Reports in Python work better too: iterate through the entire report or column-per-column.
  • Exploration. Traverse the account hierarchy from account to webproperty to profile to dimensions, both programmatically and with the included command-line interface.
  • Exports. Clean JSON and CSV – as well as Pandas data frames – so you can analyze the data in anything from Excel to R.

This package is built on top of Google's own API client for Python.

Quickstart

First, install the package using pip

  • Python 2: pip install googleanalytics
  • Python 3: pip3 install googleanalytics

Then, create a new project in the Google Developers Console, enable the Analytics API under "APIs & auth > APIs" and generate credentials for an installed application under "APIs & auth > Credentials". Keep this page open. For more detail, look at the wiki page on authentication.

After that, executing your first query is as easy as

import googleanalytics as ga
accounts = ga.authenticate()
profile = accounts[0].webproperties[0].profile
pageviews = profile.core.query.metrics('pageviews').range('yesterday').value
print(pageviews)

Or on the command-line, that'd be:

googleanalytics --identity <identity> --account <account> --webproperty <webproperty> \
    query pageviews --start yesterday

The account, webproperty and profile determine what data you'll be querying. Learn more about profiles and querying on the Querying wiki page, or alternatively look at the Common Queries page for lots of examples. Read more about how to work with the resulting data in Working With Reports. On The Command-Line has more details about the command-line application.

The example above will authorize the app and authenticate you interactively. It is also possible to pass credentials as arguments in Python, using environment variables or from your operating system's keychain. Authentication is treated in much more depth on the authentication wiki page.

More Repositories

1

django-locking

Prevents users from doing concurrent editing in Django. Works out of the box in the admin interface, or you can integrate it with your own apps using a public API.
Python
138
star
2

Extendables

A framework for Adobe ExtendScript. Unmaintained and out of date.
JavaScript
136
star
3

facebook-insights

Python wrapper and command-line utility to interact with Insights data in the Facebook Graph API.
Python
97
star
4

draughtsman

Transparent compilation of templates and stylesheets for prototyping HTML interfaces. Also live reloading.
CoffeeScript
78
star
5

django-revisions

Sane content versioning for Django.
Python
72
star
6

pollster

Pollster polls for share counts of URLs at regular intervals.
Python
47
star
7

python-literate

Research notebooks in Python, with the power of literate programming and Markdown.
Python
40
star
8

python-ballpark

Better human-readable numbers
Python
37
star
9

social-shares

A command-line and programmatic interface to various social sharecount endpoints.
Python
30
star
10

jsdoc-for-sphinx

This is an MIT-licensed jsdoc-toolkit 2 template that produces ReStructured Text (*.rst) with Sphinx directives. Makes it easy to document Javascript in Sphinx projects.
JavaScript
28
star
11

python-omniture

A high-level Python wrapper for the Adobe Omniture API.
Python
23
star
12

backbone-express

Backbone-express serves Backbone applications with a server-side fallback, so they're visible to search engines.
CoffeeScript
19
star
13

render

Render text and HTML from Jade, Handlebars, Swig and most other kinds of templates on the command line. Render many files at once and decide where to write to dynamically from the data.
CoffeeScript
17
star
14

yaml2json

Convert YAML into JSON. Supports YAML frontmatter, YAML multidocs and other mixed text-and-yaml documents. Can process Textile, Markdown and AsciiDoc strings. Works on the command-line and in node.js.
CoffeeScript
11
star
15

hector

Hector is a static site generator.
CoffeeScript
9
star
16

tilt.js

A generic interface to various JavaScript and CSS preprocessors. Autodetects formats based on filename and mimetype.
CoffeeScript
7
star
17

django-treebeard-dag

Directed Acyclic Graphs for Django, using more-or-less the familiar django-treebeard API.
Python
7
star
18

refract

A command-line utility to reshape objects to a template. Destructuring assignment on steroids.
CoffeeScript
7
star
19

sqs-antenna

Command-line tool that executes a command for each SQS message it receives.
Python
7
star
20

python-rison

A Rison decoder for Python
Python
5
star
21

math

A simple mathematics library for JavaScript that's pretty much the Math object on crack. Also has `random` and `coordinates` submodules.
CoffeeScript
4
star
22

envv

Environments for client-side code: execute or skip code depending on whether you're deploying to a production server or just developing.
CoffeeScript
4
star
23

summa

Summa is a little CoffeeScript / JavaScript library for descriptive (summary) statistics and working with distributions (PMF, CDF). Open-source because why-the-heck-not, but don't expect any support.
CoffeeScript
4
star
24

python-inspector

Automatically document Python code. Think Sphinx Autodoc without the cruft.
Python
3
star
25

python-whatwhen

A higher-level topological sort.
Python
3
star
26

espy

A context finder for static site generators and prototyping tools.
CoffeeScript
3
star
27

put

Put is a command-line utility to move, rename, copy and symlink files. Uses a simple placeholder syntax to transform input filenames to output filenames. Think of it as an easier-to-use but perhaps less powerful Linux rename.
CoffeeScript
3
star
28

bones-coffeescript-example

A Backbone.js + Bones example app
CoffeeScript
2
star
29

python-dictionary

Helper functions for dictionaries.
Python
2
star
30

flatten

A simple command-line utility that flattens and unflattens JSON.
CoffeeScript
2
star
31

jobs

A next-generation cron.
MoonScript
2
star
32

python-paste

Supercharged split and join operations, inspired on the eponymous R functions.
Python
2
star
33

stockpile

Mimeo is the airplane mode for your application. Automatically cache and serve common JavaScript libraries or any kind of file from your development machine.
CoffeeScript
2
star
34

data-analysis-in-python

Workshop for the BA media party.
Python
2
star
35

python-fs

A small library that unifies file handling in Python
Python
2
star
36

nature-fixedwidth

A BSD-licensed fixed-width version of Martin Mahner's excellent nature theme for the Sphinx documentation generator.
2
star
37

python-addressable

Use lists like you would dictionaries.
Python
1
star
38

versioned

A command-line utility that makes it easy to version files with hardlinks.
Python
1
star
39

groupby

Split up JSON data into multiple files based on shared characteristics.
CoffeeScript
1
star
40

comprevise

A small PHP app to show and navigate through design concepts.
PHP
1
star
41

python-snakify

Slugify any string to a valid Python variable name.
Python
1
star
42

python-ranges

Generate various kinds of ranges, either in whatever Python data type is appropriate or as a list of strings that retain all the various quirks of your start, stop and step arguments.
Python
1
star