A Python-based tool for automated reporting from Google Analytics 4 to Google Sheets.
- 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
.
├── 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
- Python 3.8 or higher
- Google Analytics 4 property
- Google Cloud project with Analytics Data API enabled
- Service account with appropriate permissions
-
Clone the repository:
git clone https://github.com/yourorg/google-analytics-tools.git cd google-analytics-tools
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Create a
.env
file from the example:cp .env.example .env
-
Edit the
.env
file with your Google Analytics and Sheets credentials
Generate a monthly report with default metrics:
python main.py --report-type monthly
Generate a daily report for the last 30 days:
python main.py --report-type daily --days 30
Specify custom metrics:
python main.py --metrics activeUsers newUsers sessions
Specify custom dimensions for daily reports:
python main.py --report-type daily --dimensions date deviceCategory
Run tests with pytest:
pytest