Python script to find the Top n pages from your Google analytics account and write the response to a file/stdout in json/yaml format
-
Use virtualenv to create a virtual environment
# Create a virtual env $ virtualenv venv # Activate virtual env $ source venv/bin/activate
-
Install dependencies using pip
$ pip install -r requirements.txt
-
Specify Google service account credentials file location
Follow these instructions to create a service account in Google console. Download the
key.json
file and set theKEY_FILE_LOCATION
in.env
.Note: You'll also need to enable Google analytics APIs.
-
Add Google Analytics VIEW_ID in environment
Follow these steps to get the VIEW_ID for your analytics account:
- Sign in to Google Analytics.
- Click Admin, and navigate to View.
- In the VIEW column, click View Settings.
- You'll find View ID in Basic Settings.
-
Run the script
$ python main.py