Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

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

Patel Dhrit1b0a8febd13c
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/traffic/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/traffic/page.tsx
index 09b1f26d9..451871e49 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/traffic/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/traffic/page.tsx
@@ -51,6 +51,7 @@ import {
X,
Loader2,
Download,
+ CalendarX2,
} from 'lucide-react';
import { toast } from 'sonner';
import { cn } from '@/lib/utils';
@@ -353,6 +354,23 @@ function EmptyLogsState({ hasFilters }: { hasFilters: boolean }) {
}
}
+function NoTrafficForPeriod({ rangeLabel, onReset }: { rangeLabel: string; onReset: () => void }) {
+ return (
+ <Card>
+ <CardContent className="py-16 text-center">
+ <CalendarX2 className="h-10 w-10 mx-auto text-muted-foreground/50" />
+ <h3 className="text-lg font-semibold mt-4">No traffic in this period</h3>
+ <p className="text-sm text-muted-foreground mt-1 max-w-md mx-auto">
+ No AI-referred visits in the {rangeLabel}. There is traffic data in other time periods.
+ </p>
+ <Button variant="outline" size="sm" className="mt-4" onClick={onReset}>
+ Show all data
+ </Button>
+ </CardContent>
+ </Card>
+ );
+}
+
// ─── Date range ─────────────
type DatePreset = '24h' | '7d' | '30d' | '90d' | 'all' | 'custom';
@@ -664,6 +682,8 @@ function TrafficPageContent({ brand }: { brand: Brand }) {
const topPlatform = summary?.platformBreakdown[0];
const isEmpty = totalVisits === 0 && logs.length === 0;
+ const hasAnyData = summary?.hasAnyData ?? false;
+ const trulyEmpty = isEmpty && !hasAnyData;
return (
<div className="space-y-6">
@@ -703,7 +723,7 @@ function TrafficPageContent({ brand }: { brand: Brand }) {
{/* Snippet Banner */}
<SnippetBanner trackingCode={brand.trackingCode} />
- {isEmpty ? (
+ {trulyEmpty ? (
<Card>
<CardContent className="py-16 text-center">
<Globe className="h-10 w-10 mx-auto text-muted-foreground/50" />
@@ -715,6 +735,11 @@ function TrafficPageContent({ brand }: { brand: Brand }) {
</p>
</CardContent>
</Card>
+ ) : isEmpty ? (
+ <NoTrafficForPeriod
+ rangeLabel={rangeSubLabel}
+ onReset={() => handleDatePresetChange('all')}
+ />
) : (
<>
{/* KPI Cards */}
diff --git a/web/src/lib/actions/traffic.ts b/web/src/lib/actions/traffic.ts
index e906b746a..2e9363efc 100644
--- a/web/src/lib/actions/traffic.ts
+++ b/web/src/lib/actions/traffic.ts
@@ -25,6 +25,7 @@ export interface TrafficSummary {
totalVisitsPrev: number;
platformBreakdown: { platform: string; visits: number; visitsPrev: number }[];
topPages: { url: string; visits: number; visitsPrev: number }[];
+ hasAnyData: boolean;
}
export interface TrafficTrendPoint {
@@ -181,7 +182,11 @@ export async function getTrafficSummary(
const columns = 'source_platform, url, created_at, id';
const hasPrev = Boolean(prevFrom && prevTo);
- const [totalVisits, totalVisitsPrev] = await Promise.all([
+ // The window is already the full lifetime when neither bound is set, so
+ // totalVisits doubles as the lifetime check — only worth a second cheap
+ // count query when the window actually narrows the result.
+ const hasWindow = Boolean(from || to);
+ const [totalVisits, totalVisitsPrev, , , lifetimeVisits] = await Promise.all([
countVisits(from, to, true),
hasPrev ? countVisits(prevFrom, prevTo) : Promise.resolve(0),
scanTrafficLogs(
@@ -198,8 +203,11 @@ export async function getTrafficSummary(
aggregate(platformMapPrev, pageMapPrev),
)
: Promise.resolve(),
+ hasWindow ? countVisits() : Promise.resolve(null),
]);
+ const hasAnyData = hasWindow ? (lifetimeVisits as number) > 0 : totalVisits > 0;
+
const allPlatforms = new Set([...platformMap.keys(), ...platformMapPrev.keys()]);
const platformBreakdown = Array.from(allPlatforms)
.map((platform) => ({
@@ -224,6 +232,7 @@ export async function getTrafficSummary(
totalVisitsPrev,
platformBreakdown,
topPages,
+ hasAnyData,
};
}