Skip to content

Commit 908ff50

Browse files
committed
feat(analytics): updated flag usage metrics dashboard
1 parent 533d7ff commit 908ff50

3 files changed

Lines changed: 22 additions & 9 deletions

File tree

apps/web/app/(main)/projects/[project]/analytics/page-client.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default function AnalyticsPageClient() {
3636
usageData.flagDistribution.length > 0 &&
3737
!selectedFlagKey
3838
) {
39-
setSelectedFlagKey(usageData.flagDistribution[0]?.flagKey || "");
39+
setSelectedFlagKey(usageData.flagDistribution[0]?.flag_key || "");
4040
}
4141
}, [usageData, selectedFlagKey]);
4242

apps/web/components/analytics/flag-usage-metrics.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { pivotAnalyticsData } from "@/utils/analytics";
3030
import { CustomTooltipForFlagUageMetrics } from "@/utils/chart";
3131
import { AnalyticsContentSkeleton } from "./analytics-content-skeleton";
3232

33-
type FlagSummary = { flagKey: string; total: number };
33+
type FlagSummary = { flag_key: string; total: number };
3434

3535
type FlagUsageMetricsProps = {
3636
data: FlagUsageData;
@@ -79,7 +79,18 @@ export function FlagUsageMetrics({
7979
if (variationChartData.length === 0) {
8080
return [];
8181
}
82-
return Object.keys(variationChartData[0]).filter((k) => k !== "date");
82+
83+
const keys = new Set<string>();
84+
85+
for (const day of variationChartData) {
86+
for (const key of Object.keys(day)) {
87+
if (key !== "date") {
88+
keys.add(key);
89+
}
90+
}
91+
}
92+
93+
return Array.from(keys);
8394
}, [variationChartData]);
8495

8596
if (isLoading) {
@@ -94,7 +105,7 @@ export function FlagUsageMetrics({
94105
const topFlagsKeys = data.flagDistribution
95106
.sort((a, b) => (Number(b.total) || 0) - (Number(a.total) || 0))
96107
.slice(0, 5)
97-
.map((f) => f.flagKey);
108+
.map((f) => f.flag_key);
98109

99110
const chartTitle =
100111
!selectedFlagKey || selectedFlagKey === "project-wide"
@@ -169,8 +180,8 @@ export function FlagUsageMetrics({
169180
Project-Wide Aggregate
170181
</SelectItem>
171182
{allFlags.map((flag) => (
172-
<SelectItem key={flag.flagKey} value={flag.flagKey}>
173-
{flag.flagKey}
183+
<SelectItem key={flag.flag_key} value={flag.flag_key}>
184+
{flag.flag_key}
174185
</SelectItem>
175186
))}
176187
</SelectContent>
@@ -188,8 +199,9 @@ export function FlagUsageMetrics({
188199
<Legend />
189200
{variationKeys.map((key, index) => (
190201
<Line
202+
connectNulls
191203
dataKey={key}
192-
dot={false}
204+
dot={true}
193205
key={key}
194206
name={key}
195207
stroke={CHART_LINE_COLORS[index % CHART_LINE_COLORS.length]}
@@ -215,8 +227,9 @@ export function FlagUsageMetrics({
215227
<Legend />
216228
{topFlagsKeys.map((key, index) => (
217229
<Line
230+
connectNulls
218231
dataKey={key}
219-
dot={false}
232+
dot={true}
220233
key={key}
221234
stroke={CHART_LINE_COLORS[index % CHART_LINE_COLORS.length]}
222235
type="monotone"

apps/web/lib/queries/analytics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { TimeRange } from "@/types/analytics";
1010
export type DailyUsage = { date: string; impressions: number };
1111

1212
export type FlagVariationDistribution = {
13-
flagKey: string;
13+
flag_key: string;
1414
[variationName: string]: string | number;
1515
total: number;
1616
};

0 commit comments

Comments
 (0)