Skip to content

Type and validate ProductUsageEvent against the analytics catalog #548

Description

@jjoonleo

Problem

ProductUsageEvent is currently string/Map based, so event names, workflow/result values, and parameters are not tied to the documented analytics catalog. That leaves privacy-sensitive analytics rules dependent on manual discipline at each call site.

Evidence

  • lib/domain/entities/product_usage_event.dart defines name, workflow, and result as raw Strings and parameters as Map<String, Object>, then spreads the map into Firebase parameters.
  • lib/core/services/product_analytics_service.dart only gates collection and forwards event.name plus event.toAnalyticsParameters(...); it does not validate the event against the catalog.
  • lib/domain/use-cases/track_product_usage_event_use_case.dart catches tracking failures but does not reject unknown events, unknown parameters, forbidden fields, or invalid value categories.
  • docs/Analytics-Event-Catalog.md says optional parameters must be allowlisted per event and forbids identifiers, user-authored content, raw exceptions, and arbitrary maps, but this is only documentation.
  • lib/presentation/schedule_create/bloc/schedule_form_bloc.dart manually builds schedule_created with string keys and runtime-derived values instead of using a typed event factory.
  • Existing tests assert one happy-path schedule_created event but not catalog enforcement.

Proposed direction

Introduce a typed analytics event catalog in code and route Product Usage Event construction through it. Prefer event-specific factories or sealed/enum-backed definitions for known event names, workflows, results, and allowed parameter keys.

Put validation in TrackProductUsageEventUseCase or a dedicated catalog validator before the Firebase service seam, so feature BLoCs cannot accidentally emit undocumented parameters or forbidden data.

Acceptance criteria

  • ProductUsageEvent can no longer be created with arbitrary event names, workflow/result strings, or free-form parameter keys without passing catalog validation.
  • schedule_created is built through a typed factory/helper that owns preparation_mode, preparation_step_count, and minutes_until_schedule.
  • Unknown event names, non-allowlisted parameters, arbitrary nested maps, and forbidden sensitive fields are rejected or stripped before reaching ProductAnalyticsService.
  • The docs catalog and in-code catalog are kept in sync through tests or a single source of truth.
  • Unit tests cover valid schedule_created, unknown event rejection, unknown parameter rejection, forbidden field rejection, and the existing disabled-collection path.

Source: Codex codebase audit on 2026-06-28.

Metadata

Metadata

Assignees

No one assigned

    Labels

    privacyPrivacy, data safety, or account deletion workproduction-readinessWork required before production releaserefactorschedulerelated to schedule featuretest

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions