Giter Club home page Giter Club logo

ga-cl's Introduction

ga-cl

Simple Google Analytics command line tools for Python (2.x).

Get started

Follow steps 1 and 2 here: https://developers.google.com/analytics/devguides/config/mgmt/v3/quickstart/installed-py to create the Google Cloud project and download the client_secrets.json file.

Clone this project to a directory in your hard drive with git clone https://github.com/sahava/ga-cl.git.

Create a new directory in the root of this project named secret/ , and copy the client_secrets.json file to this directory.

Now you should have two directories in your project root: secret/ and modules/.

Authenticate against the tools

When you run any of the python modules, a web browser will open, and you will be prompted to login with the Google account you want to run the module API calls against. Once you have authenticated, this authentication is stored in the analytics.dat file in the secret/ directory.

To remove authentication, simply delete this file.

The modules might require different levels of authentication, so when moving from one module to the next, remove the analytics.dat file to re-authenticate.

ga_permissions_to_csv.py

Requires:

Allow the tool to read your Google Analytics account data.

Run:

python ga_permissions_to_csv.py [-a account_id,account_id2,account_id3] path_to_client_secrets

This module creates a CSV file of the GA accounts you have access to, with the user permissions listed for each account in their respective CSV file. You need Manage Users access to each GA account for which a file is created.

You can provide a list of Google Analytics Account IDs to the -a argument, or you can drop the -a argument to create CSV files for all the accounts you have sufficient access to.

path_to_client_secrets is a relative path to where the client_secrets.json file is stored.

Once the command is run, a new directory csv/ is created, where all the CSV files (one for each account) are stored. These files contain the user permission information for each respective account.

Example:

python ga_permissions_to_csv.py ../secret/client_secrets.json

data_retention.py

Requires:

Allow the tool to read and edit your account, property, and view settings.

To update the settings, you need EDIT access to each property you want to update.

Run:

python data_retention.py (-c | -u PATH) path_to_client_secrets

This module can be used to create (-c) a CSV file in the csv/ directory named data_retention_list.csv. This file contains a row for every web property the logged in user has access to. Each row shows the current data retention settings (TTL and Reset) for each respective property.

You can also use this to mass update (-u PATH_TO_CSV) the properties, using the CSV file created by -c as the source data (PATH_TO_CSV should be the path to this CSV file). The tool checks if the data retention TTL and/or Reset values have been changed, and if they have, you are prompted whether you want to update the properties with the new values or not.

Valid values for TTL are MONTHS_14, MONTHS_26, MONTHS_38, MONTHS_50, INDEFINITE.

Valid values for Reset are True, False.

Examples:

python data_retention.py -c ../secret/client_secrets.json

python data_retention.py -u csv/data_retention_list.csv ../secret/client_secrets.json

insert_filter.py

Requires:

EDIT permissions on the Google Analytics account for creating the filters.

EDIT permissions on the Google Analytics property and profile level where you want to link the newly created filters.

You will need the Account ID, Web Property ID (UA-12345-1), and Profile ID of the account and the profile(s) where you want to create and link these filters.

You can get the Account ID and the Profile ID by looking for the string /aNNNwNNNpNNN in the URL of the Google Analytics user interface, when browsing through reports of any given profile.

The number after a (but before w) is the Account ID, and the number after p is the Profile ID.

Run:

python insert_filter.py -c accountId -j /path/to/file.json path_to_client_secrets

With this module, you can compile a list of filter resources (https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/filters#resource) in a .json file, which you then use to create these filters in the given Google Analytics account ID.

Once the filters have been created, the tool will prompt you for a Web Property ID and a Profile ID to which these filters will be linked. You can also quit the tool at this point if you don't want to create the links.

Once a set of links have been created, the tool will prompt you again for a Web Property ID and a Profile ID, if you want to link the filters to another profile.

Example:

Create filters from file filters.json in account 12345

python insert_filter.py -c 12345 -j ./filters.json ../secret/client_secrets.json

ga-cl's People

Contributors

sahava avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ga-cl's Issues

TypeError: a bytes-like object is required, not 'str'

python modules/ga_permissions_to_csv.py -a 111111111 secret/client_secrets.json

Fetching permissions for account "ANDappky_APK_2" (111111111)...
Building "csv/andappky_apk_2_111111111.csv"...
Traceback (most recent call last):
File "modules/ga_permissions_to_csv.py", line 90, in
main(sys.argv[1:])
File "modules/ga_permissions_to_csv.py", line 86, in main
build_csv(permissions, account)
File "modules/ga_permissions_to_csv.py", line 49, in build_csv
wr.writerow(['Account name', account['name'].encode('utf-8')])
TypeError: a bytes-like object is required, not 'str'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.