Skip to content

ourdigital/google-analytics-tools

Repository files navigation

Google Analytics Reporting Automation

A Python-based tool for automated reporting from Google Analytics 4 to Google Sheets.

Features

  • Monthly metrics summaries
  • Daily detailed reports
  • Command-line interface for flexible reporting options
  • Integration with Google Sheets for easy data sharing
  • Support for custom metrics and dimensions

Project Structure

.
├── src/
│   ├── api/                 # API client modules
│   │   ├── ga4_api.py       # Google Analytics API client
│   │   └── sheets_api.py    # Google Sheets API client
│   ├── auth/                # Authentication modules
│   │   └── google_auth.py   # Google APIs authentication
│   ├── config/              # Configuration modules
│   │   └── settings.py      # Application settings
│   ├── services/            # Business logic services
│   │   └── analytics_service.py  # Analytics reporting service
│   └── utils/               # Utility functions
│       └── logger.py        # Logging utilities
├── tests/                   # Test modules
│   └── test_ga4_api.py      # Tests for GA4 API client
├── .env.example             # Example environment variables
├── main.py                  # Main entry point
└── requirements.txt         # Python dependencies

Setup

Prerequisites

  • Python 3.8 or higher
  • Google Analytics 4 property
  • Google Cloud project with Analytics Data API enabled
  • Service account with appropriate permissions

Installation

  1. Clone the repository:

    git clone https://github.com/yourorg/google-analytics-tools.git
    cd google-analytics-tools
    
  2. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  3. Install dependencies:

    pip install -r requirements.txt
    
  4. Create a .env file from the example:

    cp .env.example .env
    
  5. Edit the .env file with your Google Analytics and Sheets credentials

Usage

Monthly Report

Generate a monthly report with default metrics:

python main.py --report-type monthly

Daily Report

Generate a daily report for the last 30 days:

python main.py --report-type daily --days 30

Custom Metrics

Specify custom metrics:

python main.py --metrics activeUsers newUsers sessions

Custom Dimensions

Specify custom dimensions for daily reports:

python main.py --report-type daily --dimensions date deviceCategory

Testing

Run tests with pytest:

pytest

License

MIT License

About

simple Google Analytics reporting automation app prototype

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published