Skip to content

fix(web): show period-specific empty state on AI Traffic page - #631

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
d180:feature/traffic-empty-state-period
Aug 4, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
d180:feature/traffic-empty-state-period

Conversation

@d180

@d180 d180 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

The Traffic page's empty check (totalVisits === 0 && logs.length === 0) was date-range-blind, so a brand with plenty of historical traffic that picks a narrow window (e.g. "Last 24 hours") with no visits in it saw the snippet-onboarding card ("Add the tracking snippet to your website...") — wrongly implying their integration was broken.

This mirrors the NoDataForPeriod pattern already used on the Insights page:

  • getTrafficSummary (web/src/lib/actions/traffic.ts) now returns hasAnyData, a cheap unfiltered count-only check for whether the brand has any lifetime traffic, independent of the selected window.
  • The Traffic page (web/src/app/[locale]/.../traffic/page.tsx) splits the old single isEmpty into isEmpty (nothing in the current window) and trulyEmpty (isEmpty && !hasAnyData). The onboarding card now only shows for trulyEmpty. A new NoTrafficForPeriod state renders when the window is empty but lifetime data exists, naming the selected range with a "Show all data" button that resets to "All time."

Related issue

Closes #608

Type of change

  • fix — Bug fix

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

gkhngyk
gkhngyk previously approved these changes Aug 3, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice touch running the lifetime count only when a window actually narrows the query — the trulyEmpty/isEmpty split matches the Insights pattern exactly. Thanks!

@gkhngyk

gkhngyk commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

This picked up conflicts after #630 (same header/imports area in traffic/page.tsx) and #616 (traffic.ts platform breakdown) merged. Could you rebase onto main and resolve? Note that main's platformBreakdown now filters zero-visit rows — your hasAnyData changes sit right next to that hunk, so just keep both. Approved otherwise, happy to re-review once it's green.

@d180
d180 force-pushed the feature/traffic-empty-state-period branch from 1d3666a to 9a9c265 Compare August 4, 2026 05:33
@d180

d180 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main and resolved the conflicts — kept both the Download/CalendarX2 icon imports in traffic/page.tsx and both the zero-visit platformBreakdown filter and hasAnyData logic in traffic.ts. Ready for re-review.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rebase looks clean — the zero-visit filter from #616 is preserved and hasAnyData sits correctly on top. Thanks for the quick turnaround!

@gkhngyk
gkhngyk merged commit 1b0a8fe into ansvisor:main Aug 4, 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.

AI Traffic: empty date range shows the "add the tracking snippet" onboarding card instead of a period-specific message

2 participants