Skip to content

Insights & Reports: *Change deltas silently switch to absolute counts on a zero base but always render with a % suffix #520

Closed

Description

@gkhngyk

Problem

InsightsSummary.mentionsChange / citationsChange (web/src/lib/actions/tracking.ts) are percentage deltas except when either window is zero, where the formula falls back to an absolute difference:

mentionsChange =
  curMentions > 0 && prevMentions > 0
    ? Math.round(((curMentions - prevMentions) / prevMentions) * 100)
    : curMentions - prevMentions;

Every consumer renders the value with an unconditional % suffix — the Insights KPI cards (DeltaBadge), the report viewer's Delta, and the PDF's DeltaText. So a brand going 0 → 354 mentions shows "+354%" in three surfaces, when the truth is "+354 mentions (new)". The mixed semantics also can't be narrated correctly by the report's AI summary (#514 fixes the prompt for the common percentage case, but the model cannot know which meaning applies to a given value).

Fix direction

Make the field's meaning unambiguous instead of guessing at render time. The least invasive shape:

  • Keep *Change as the percentage delta and set it to null when there is no meaningful base (prev = 0), and
  • Expose the raw previous-period counts (prevMentions, prevCitations) on InsightsSummary so consumers can render the zero-base case honestly (e.g. a "new" badge or "+354" without the % suffix) and the report snapshot carries values the AI summary can narrate safely.

Alternative shapes are fine if they keep one meaning per field — the requirement is that no consumer can render an absolute count with a % suffix.

Consumers to update together (all read the same struct, so they must land in one PR): Insights KPI cards, report viewer Delta, report PDF DeltaText, and the report summary prompt's description of the fields (coordinate with #514). Old report snapshots store the current mixed-meaning values — the viewer/PDF fallback for them should keep today's rendering rather than reinterpreting immutable data.

Acceptance criteria

  • A brand with prev = 0 and cur > 0 never shows a % suffix for that delta on Insights, the report viewer, or the PDF.
  • Percentage deltas keep rendering exactly as today when both windows are non-zero.
  • Reports generated before the change render unchanged.
  • yarn lint, yarn typecheck and yarn format:check pass from web/.

Related

Getting started

See CONTRIBUTING.md for setup. Comment here to claim the issue before opening a PR.

Activity

  1. added
    bug
    help wanted
    on Jul 23, 2026
  2. abdullah91111 commented on Jul 23, 2026

    @abdullah91111
    Contributor

    on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions