PR Summary

What problems was I solving

Page analytics users need to export large amounts of analytics data as CSV files. Previously, this operation was synchronous and could time out for large datasets. This PR redesigns the export system to use an asynchronous job-based approach with tracking and status queries.

What user-facing changes did I ship

Added 'CSV Export' button on the analytics tab that initiates an asynchronous export job. Users can watch progress while the export runs in the background and download when ready. Added 'Group by' dropdown to enable grouping analytics by attribution dimensions (UTM fields or custom query params). Comparison tables and cards now show attribution group labels, helping users understand which attribution data generated each metric row.

How I implemented it

The new export system consists of: (1) A new analytics_export_jobs table that stores export job metadata and the full request payload (for later reuse), (2) Temporal workflow (pageAnalyticsCsvExportWorkflow) that orchestrates CSV generation, (3) File Service's new storeFileContent API to upload CSV content directly (20MB max), (4) Attribution grouping support across analytics APIs allowing exports grouped by UTM fields or additional query params, (5) Export UI that polls for job completion and auto-starts download when ready. The frontend changes from synchronous export to job submission + polling (15s default timeout, retries backoff). All new fields are backwards-compatible (optional in schemas).

Description for the changelog

Implemented async page analytics CSV export with job tracking and progress display. Added attribution grouping support to analytics queries and export output, enabling users to analyze performance by marketing channel (UTM) or custom query parameters. Export UI now shows group labels and lets users select multiple grouping dimensions. CSV export job table indexes by tenant, user, and status for efficient listing and cleanup.

Add analytics_export_jobs table

critical6 files
New analytics_export_jobs table with job status tracking, request payload storage, and indexing by tenant, user, and status.

CSV export job management (API, workflows, activities)

high10 files
Async job management API with create/export job and get job status endpoints, backed by Temporal workflow.

Aggregate query implementations with grouping

high2 files
New SQL queries for session aggregate and daily counts supporting attribution grouping (using lateral CTEs to group data).

New repository interfaces for export functionality

high3 files
New analyticsexport aggregate and job repository interfaces added to service, with corresponding benchmarks added to history.

CSV export activity and page listing

high4 files
CSV generation and serialization components for export activity (row building, CSV formatting, file storage integration).

File content upload API

high3 files
New storeFileContent API with 20MB max limit, supporting utf8/base64 encoding for direct CSV content upload.

Page analytics export GraphQL schema

high3 files
New GraphQL operations for page analytics CSV export including job creation and status polling.

Page analytics export UI

high10 files
UI for export (dropdown, polling UI) with STATE attachment and prompts under metrics cards.

Export view model types and GraphQL bindings

high10 files
New attribution grouping types and GraphQL operations for export with job polling

CSV export API

high2 files
Export job API interfaces and types (create/export job, aggregated exports with grouping)

Implementation dependencies

high2 files
Implementation dependencies for file-service-api and temporal-service integration

Export job and aggregate repository layer

medium3 files
Repository layer for export job status tracking and page analytics aggregate CSV data access with pagination.

Attribution grouping SQL and data mapping helpers

medium5 files
SQL fragment builders and data mapping for attribution grouping (views aggregates by UTM and additional query params).

Session summary queries with attribution grouping

medium6 files
Added attribution grouping support to session summary queries with new aggregatesByPage and dailyCountsWithGrouping endpoints.

CSV export implementation tests

medium4 files
Export job service integration tests and export generation tests (4 new test files).

Page listing for export

medium
Lists exportable pages (published pages matching filters) for CSV export operations.

ViewModel and GraphQL layer tests

medium4 files
Updated tests for async job models, grouped queries, and attribution grouping

Export metadata and group types

medium2 files
Grouping types for exports and query updates supporting attribute grouping

Test integration for cache and history

medium7 files
Test files updated to mock and use new export repositories

Session charts and dependency mocks

medium2 files
Minor UI change and updated mock for storeFileContent