feat: add monthly trend charts for export events in static analytics#4842
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds monthly trend chart support for key export/download GA4 events in the static analytics sites (AnVIL Explorer, HCA Explorer, LungMAP), including new GA4 fetching + JSON export plumbing and template rendering.
Changes:
- Introduces a shared
make_event_charts()config factory and threadsevent_chartsthrough the static site generator/fetch/export pipeline. - Fetches monthly event counts (with missing months backfilled as zeros) and exports them as
data/event_charts.json. - Updates the static analytics HTML template to load
event_charts.jsonand render Chart.js bar charts beneath the corresponding event stat cards.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| analytics/anvil-explorer-sheets/generate_static_site.py | Adds make_event_charts() usage to enable export-event trend charts for AnVIL. |
| analytics/hca-explorer-sheets/generate_static_site.py | Adds make_event_charts() usage to enable export-event trend charts for HCA. |
| analytics/lungmap-analytics/sheets/generate_static_site.py | Adds make_event_charts() usage to enable export-event trend charts for LungMAP. |
| analytics/analytics_package/analytics/static_site/template/index.html | Loads event_charts.json and renders Chart.js charts under event count cards. |
| analytics/analytics_package/analytics/static_site/generator.py | Plumbs event_charts through generate_site() into fetch/export. |
| analytics/analytics_package/analytics/static_site/fetch.py | Implements monthly event-series fetching with month-range backfill and API call de-duplication by event name. |
| analytics/analytics_package/analytics/static_site/export.py | Exports event_charts.json containing chart titles and per-series monthly data. |
| analytics/analytics_package/analytics/static_site/charts.py | Adds shared make_event_charts() configuration factory for export event charts. |
| analytics/analytics_package/analytics/static_site/init.py | Exposes make_event_charts from the analytics.static_site package. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (3)
analytics/analytics_package/analytics/static_site/fetch.py:312
fetch_datagained anevent_chartsparameter but the Args section in the docstring doesn’t document it. Please add an entry describing the expected structure (e.g., chart_start + charts/series) so callers know how to use it.
def fetch_data(
ga_authentication,
property_id,
current_month,
analytics_start,
custom_events=None,
event_charts=None,
historic_data_path=None,
access_request_urls=None,
exclude_pages=None,
base_dimension_filter=None,
search_path=None,
):
"""Fetch all analytics data for the static site.
Args:
ga_authentication: GA4 authentication object from analytics.api.authenticate.
property_id: GA4 property ID.
current_month: Current month string (YYYY-MM).
analytics_start: Start date for all-time data (YYYY-MM-DD).
custom_events: List of dicts with "event_name" and "label" keys.
historic_data_path: Path to historic UA data JSON file (optional).
exclude_pages: Optional list of page paths to exclude from pageview data.
base_dimension_filter: Optional GA4 dimension filter dict applied to all queries.
search_path: Optional search page path to extract search queries from (e.g., "/search").
analytics/analytics_package/analytics/static_site/generator.py:50
generate_sitenow acceptsevent_charts, but the function docstring’s Args list doesn’t mention it. Please document this parameter (and how it relates to the exportedevent_charts.json) to keep the public API docs accurate.
def generate_site(
ga_authentication,
config,
property_id,
current_month,
analytics_start,
output_dir="site",
custom_events=None,
event_charts=None,
historic_data_path=None,
title_resolver=None,
access_request_urls=None,
exclude_pages=None,
base_dimension_filter=None,
search_path=None,
):
"""Generate a static analytics site.
Args:
ga_authentication: GA4 authentication object from analytics.api.authenticate.
config: Site config dict with keys:
- site_title: Display title (e.g., "AnVIL Catalog").
- logo_url: URL to the logo image.
- logo_link: URL the logo links to.
- primary_color: Primary color hex (e.g., "#035C94").
- primary_color_dark: Darker primary color hex.
property_id: GA4 property ID.
current_month: Current month string (YYYY-MM).
analytics_start: Start date for all-time data (YYYY-MM-DD).
output_dir: Output directory for the generated site.
custom_events: List of dicts with "event_name" and "label" keys.
Example: [{"event_name": "chat_submitted", "label": "Chat Submissions"}]
historic_data_path: Path to historic UA data JSON file (optional).
title_resolver: Optional callable that accepts the data dict and enriches
detail records with resolved entity titles (e.g., dataset/project names).
exclude_pages: Optional list of page paths to exclude from pageview data.
base_dimension_filter: Optional GA4 dimension filter dict applied to all queries
(e.g., an audience filter to exclude bot/tutorial traffic).
search_path: Optional search page path to extract search queries from (e.g., "/search").
analytics/analytics_package/analytics/static_site/export.py:68
export_dataadded anevent_chartsparameter, but the docstring Args section doesn’t include it. Please document it (including that it writesevent_charts.jsonwhen provided) so the behavior is discoverable.
def export_data(data, config, current_month, analytics_start, custom_events, output_dir, event_charts=None):
"""Export all analytics data to JSON files.
Args:
data: Dict containing DataFrames and stats from fetch_data.
config: Site config dict (title, logo, colors).
current_month: Current month string (YYYY-MM).
analytics_start: Analytics start date string.
custom_events: List of custom event dicts with results.
output_dir: Output directory for JSON files.
"""
…4825 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2fd2385 to
97ff66f
Compare
Ticket
Closes #4825
Summary
make_event_charts()factory function eliminates config duplication across HCA, AnVIL, and LungMAP generatorsbulk_download_requestedwith different page path filters), reducing API calls from 6 to 5 per appTest plan
🤖 Generated with Claude Code