← PORTAFOLIOPORTFOLIO / proyectos / universal-analytics

// PRJ_012 · 2024

Extractor Universal AnalyticsUniversal Analytics Extractor

Data · PythonData · Python

Una herramienta para sacar reportes de Google Analytics a Excel sin hacerlo a mano.A tool to pull Google Analytics reports into Excel without doing it by hand.

En detalleIn detailHerramienta Python que extrae reportes de Universal Analytics (Reporting API v4) y los exporta a CSV/Excel. Arquitectura por capas (domain · usecases · controller · infrastructure · view), con tests (pytest) y CI en GitHub Actions.Python tool that extracts Universal Analytics reports (Reporting API v4) and exports them to CSV/Excel. Layered architecture (domain · usecases · controller · infrastructure · view), with tests (pytest) and CI on GitHub Actions.

RolRole
Desarrollador a cargoLead developer
AñoYear
2024
GitHub
ver repo ↗view repo ↗
Stack
Python · Google Analytics · pandas

// IMPACTO// IMPACT

Reporting v4Reporting v4
apiapi
CSV/ExcelCSV/Excel
salidaoutput
pytestpytest
teststests

El problemaThe problem

Respaldar manualmente reportes de Universal Analytics es lento y repetitivo. Necesitaba extraer métricas por rango de fechas y exportarlas de forma estructurada, manteniendo el cliente de Google separado de la lógica.Manually backing up Universal Analytics reports is slow and repetitive. I needed to extract metrics by date range and export them in a structured way, keeping the Google client separate from the logic.

Cómo lo resolvíHow I solved it

Herramienta en capas (domain · usecases · controller · infrastructure · view): el cliente de la Reporting API v4 vive en infraestructura, los casos de uso orquestan la consulta y la salida se exporta a CSV/Excel. Tests de las capas puras con pytest y CI.Layered tool (domain · usecases · controller · infrastructure · view): the Reporting API v4 client lives in infrastructure, the use cases orchestrate the query, and the output is exported to CSV/Excel. Pure-layer tests with pytest and CI.

Arquitectura y stackArchitecture & stack

  1. [01]Service Account
  2. [02]Reporting API v4
  3. [03]Use Cases
  4. [04]Controller
  5. [05]CSV/Excel
  • Python
  • Google Analytics
  • pandas
  • openpyxl
# usecases/analytics_usecase.py
class AnalyticsUsecase:
    def __init__(self, analytics_client):
        self.analytics_client = analytics_client

    def fetch_report(self, report):
        # el caso de uso no conoce a Google: depende de la abstracción
        return self.analytics_client.fetch_report(report)

Lo que aprendíWhat I learned

01 //

Capas testeables

Separar el cliente de Google del dominio permite testear la lógica sin red ni credenciales.

02 //

Secretos fuera del repo

Las credenciales y el venv jamás deben versionarse: .gitignore + plantilla .example.

03 //

API en EOL

Universal Analytics fue descontinuado en 2024; el proyecto queda como referencia de integración.

01 //

Testable layers

Separating the Google client from the domain lets you test the logic without network or credentials.

02 //

Secrets out of the repo

Credentials and the venv must never be versioned: .gitignore + .example template.

03 //

EOL API

Universal Analytics was discontinued in 2024; the project stands as an integration reference.