Skip to content

feat: add monthly trend charts for export events in static analytics#4842

Merged
MillenniumFalconMechanic merged 1 commit into
mainfrom
mim/4825-export-trend-charts
May 21, 2026
Merged

feat: add monthly trend charts for export events in static analytics#4842
MillenniumFalconMechanic merged 1 commit into
mainfrom
mim/4825-export-trend-charts

Conversation

@MillenniumFalconMechanic
Copy link
Copy Markdown
Contributor

Ticket

Closes #4825

Summary

  • Add bar charts showing monthly trends for export/download events (Export to Terra, curl Command, File Manifest) in the static analytics pages
  • Charts appear below the corresponding stat cards in the Key Metrics section, showing both single-entity and cross-dataset series
  • Shared make_event_charts() factory function eliminates config duplication across HCA, AnVIL, and LungMAP generators
  • Consolidated GA4 API calls for series sharing the same event name (e.g., bulk_download_requested with different page path filters), reducing API calls from 6 to 5 per app
  • Missing months are filled with zero counts to ensure all months in the range appear on charts

Test plan

  • Regenerated and verified HCA static site locally
  • Regenerated and verified AnVIL Explorer static site locally
  • Regenerated and verified LungMAP static site locally
  • Verified charts render correctly with both zero and non-zero months

🤖 Generated with Claude Code

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 threads event_charts through 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.json and 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.

Comment thread analytics/anvil-explorer-sheets/generate_static_site.py
Comment thread analytics/hca-explorer-sheets/generate_static_site.py
Comment thread analytics/lungmap-analytics/sheets/generate_static_site.py
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_data gained an event_charts parameter 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_site now accepts event_charts, but the function docstring’s Args list doesn’t mention it. Please document this parameter (and how it relates to the exported event_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_data added an event_charts parameter, but the docstring Args section doesn’t include it. Please document it (including that it writes event_charts.json when 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>
@MillenniumFalconMechanic MillenniumFalconMechanic force-pushed the mim/4825-export-trend-charts branch from 2fd2385 to 97ff66f Compare May 21, 2026 18:35
@MillenniumFalconMechanic MillenniumFalconMechanic merged commit 2b00f8e into main May 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add monthly trend charts for export events to static analytics pages

3 participants