Skip to content

Commit b6d1e5f

Browse files
committed
add analytics to insight page
1 parent c2ef5eb commit b6d1e5f

File tree

11 files changed

+849
-187
lines changed

11 files changed

+849
-187
lines changed

apps/dashboard/src/@/api/analytics.ts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,29 @@ import type {
1717
import { getAuthToken } from "./auth-token";
1818
import { getChains } from "./chain";
1919

20+
export interface InsightChainStats {
21+
date: string;
22+
chainId: string;
23+
totalRequests: number;
24+
}
25+
26+
export interface InsightStatusCodeStats {
27+
date: string;
28+
httpStatusCode: number;
29+
totalRequests: number;
30+
}
31+
32+
export interface InsightEndpointStats {
33+
date: string;
34+
endpoint: string;
35+
totalRequests: number;
36+
}
37+
38+
export interface InsightUsageStats {
39+
date: string;
40+
totalRequests: number;
41+
}
42+
2043
async function fetchAnalytics(
2144
input: string | URL,
2245
init?: RequestInit,
@@ -424,3 +447,95 @@ export async function getEngineCloudMethodUsage(
424447
const json = await res.json();
425448
return json.data as EngineCloudStats[];
426449
}
450+
451+
export async function getInsightChainUsage(
452+
params: AnalyticsQueryParams,
453+
): Promise<InsightChainStats[]> {
454+
const searchParams = buildSearchParams(params);
455+
const res = await fetchAnalytics(
456+
`v2/insight/usage/by-chain?${searchParams.toString()}`,
457+
{
458+
method: "GET",
459+
},
460+
);
461+
462+
if (res?.status !== 200) {
463+
const reason = await res?.text();
464+
console.error(
465+
`Failed to fetch Insight chain usage: ${res?.status} - ${res.statusText} - ${reason}`,
466+
);
467+
return [];
468+
}
469+
470+
const json = await res.json();
471+
return json.data as InsightChainStats[];
472+
}
473+
474+
export async function getInsightStatusCodeUsage(
475+
params: AnalyticsQueryParams,
476+
): Promise<InsightStatusCodeStats[]> {
477+
const searchParams = buildSearchParams(params);
478+
const res = await fetchAnalytics(
479+
`v2/insight/usage/by-status-code?${searchParams.toString()}`,
480+
{
481+
method: "GET",
482+
},
483+
);
484+
485+
if (res?.status !== 200) {
486+
const reason = await res?.text();
487+
console.error(
488+
`Failed to fetch Insight status code usage: ${res?.status} - ${res.statusText} - ${reason}`,
489+
);
490+
return [];
491+
}
492+
493+
const json = await res.json();
494+
return json.data as InsightStatusCodeStats[];
495+
}
496+
497+
export async function getInsightEndpointUsage(
498+
params: AnalyticsQueryParams,
499+
): Promise<InsightEndpointStats[]> {
500+
const searchParams = buildSearchParams(params);
501+
const res = await fetchAnalytics(
502+
`v2/insight/usage/by-endpoint?${searchParams.toString()}`,
503+
{
504+
method: "GET",
505+
},
506+
);
507+
508+
if (res?.status !== 200) {
509+
const reason = await res?.text();
510+
console.error(
511+
`Failed to fetch Insight endpoint usage: ${res?.status} - ${res.statusText} - ${reason}`,
512+
);
513+
return [];
514+
}
515+
516+
const json = await res.json();
517+
return json.data as InsightEndpointStats[];
518+
}
519+
520+
export async function getInsightUsage(
521+
params: AnalyticsQueryParams,
522+
): Promise<InsightUsageStats[]> {
523+
const searchParams = buildSearchParams(params);
524+
const res = await fetchAnalytics(
525+
`v2/insight/usage?${searchParams.toString()}`,
526+
{
527+
method: "GET",
528+
},
529+
);
530+
531+
if (res?.status !== 200) {
532+
const reason = await res?.text();
533+
console.error(
534+
`Failed to fetch Insight usage: ${res?.status} - ${res.statusText} - ${reason}`,
535+
);
536+
return [];
537+
}
538+
539+
const json = await res.json();
540+
return json.data as InsightUsageStats[];
541+
}

apps/dashboard/src/@/types/analytics.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,5 @@ export interface AnalyticsQueryParams {
7878
from?: Date;
7979
to?: Date;
8080
period?: "day" | "week" | "month" | "year" | "all";
81+
limit?: number;
8182
}

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/insight/blueprint-card.tsx

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)