Requirements:
- CKAN 1.7.1+
- gdata (Python library)
- google-api-python-client
- Requires Google Analytics account with OAuth setup
Installation:
1. Activate CKAN python environment:
$ pyenv/bin/activate
Install extension:
$ pip install -e git+https://github.com/datagovuk/ckanext-ga-report.git#egg=ckanext-ga-report
Configure in development.ini (or similar):
googleanalytics.id = UA-1010101-1
googleanalytics.account = Account name (e.g., data.gov.uk)
googleanalytics.token.filepath = ~/pyenv/token.dat
ga-report.period = monthly
ga-report.bounce_url = /
ga-report.bounce_url: Specific path to record bounce rate (typically /)
Initialize database tables:
$ paster initdb –config=../ckan/development.ini
Run from src/ckanext-ga-report
Enable plugin in ckan.plugins:
ckan.plugins = ga-report
Authorization Setup:
1. Follow Google Analytics API instructions:
https://developers.google.com/analytics/resources/tutorials/hello-analytics-api
Create credentials.json file (use credentials.json.template as reference):
- Visit Google APIs Console: https://code.google.com/apis/console
- Sign in, create/use project
- Activate Analytics API in Services pane
- Go to API Access pane
- Create OAuth 2.0 client ID
- Set Application type: Installed application
- Note: Client ID, Client secret, Redirect URIs
Generate OAuth token file:
$ paster getauthtoken –config=../ckan/development.ini
Follow browser prompts to authorize
Creates token.dat file
Reference token file in CKAN config:
googleanalytics.token.filepath = ~/pyenv/token.dat
Usage - Download GA Data:
$ paster loadanalytics –config=../ckan/development.ini
Run from src/ckanext-ga-report
Period Options:
- all: Data for all time (since 2010)
- latest: Just the latest data (default)
- YYYY-MM-DD: Data from this date onwards (inclusive)
Example:
$ paster loadanalytics latest –config=../ckan/development.ini
Configuration Options:
googleanalytics.id = UA-1010101-1
# Your Google Analytics tracking ID
googleanalytics.account = Account name
# Account name (e.g., data.gov.uk)
# Top level item at https://www.google.com/analytics
googleanalytics.token.filepath = ~/pyenv/token.dat
# Path to OAuth token file
ga-report.period = monthly
# Reporting period (monthly, weekly, etc.)
ga-report.bounce_url = /
# Specific path to record bounce rate for
# Typically / (home page)
Paster Commands:
- initdb: Initialize database tables
- loadanalytics : Download GA data for period
- getauthtoken: Generate OAuth token file
- fixtimeperiods: Fix time periods in database
Reports Available:
- Analytics data by time period
- Totals per group
- Bounce rate for specified paths
- Site manager-focused periodic reports
Difference from ckanext-googleanalytics:
- ckanext-googleanalytics: Recent page view stats for end users
- ckanext-ga-report: Periodic reports for site managers/monitoring
- Focus on regular periodic data collection
- Group-level analytics
- Historical trend analysis
Troubleshooting:
Error: “(ProgrammingError) relation ‘ga_url’ does not exist”
- Solution: Run paster initdb step successfully
- Ensure config path is correct
- Check database connection
Development Status: Development
License: Open Government Licence (OGL) - Crown Copyright
- Compatible with Creative Commons Attribution License
- http://www.nationalarchives.gov.uk/doc/open-government-licence/
Developed by: Cabinet Office (UK Government)