@analytix/dashboard 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AnalyticsDashboard.d.ts +18 -0
- package/dist/AnalyticsDashboard.js +260 -0
- package/dist/AnalyticsDashboardSkeleton.d.ts +1 -0
- package/dist/AnalyticsDashboardSkeleton.js +4 -0
- package/dist/WidgetCustomizePanel.d.ts +8 -0
- package/dist/WidgetCustomizePanel.js +5 -0
- package/dist/dashboard.css +401 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/useDashboardWidgets.d.ts +8 -0
- package/dist/useDashboardWidgets.js +41 -0
- package/package.json +45 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { DashboardWidgetId } from "@analytix/core";
|
|
3
|
+
type ThemeMode = "light" | "dark" | "system";
|
|
4
|
+
export interface AnalyticsDashboardProps {
|
|
5
|
+
siteId: string;
|
|
6
|
+
summaryEndpoint?: string;
|
|
7
|
+
exportEndpoint?: string;
|
|
8
|
+
/** Shown while fetching summary data. Defaults to built-in skeleton. */
|
|
9
|
+
loadingFallback?: ReactNode;
|
|
10
|
+
/** Initial theme. Defaults to system preference. */
|
|
11
|
+
defaultTheme?: ThemeMode;
|
|
12
|
+
/** Site-default widget layout (overridden by localStorage when set). */
|
|
13
|
+
defaultWidgets?: DashboardWidgetId[];
|
|
14
|
+
/** PATCH endpoint to persist widget layout as site default. */
|
|
15
|
+
settingsEndpoint?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function AnalyticsDashboard({ siteId, summaryEndpoint, exportEndpoint, loadingFallback, defaultTheme, defaultWidgets, settingsEndpoint, }: AnalyticsDashboardProps): import("react").JSX.Element;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { DEFAULT_DASHBOARD_WIDGETS, percentChange } from "@analytix/core";
|
|
5
|
+
import { Area, CartesianGrid, ComposedChart, Line, ResponsiveContainer, Tooltip, XAxis, YAxis, } from "recharts";
|
|
6
|
+
import { Download, Eye, Users, Clock, MousePointerClick, Repeat, FileText, UserPlus, UserCheck, Moon, Sun, SlidersHorizontal, } from "lucide-react";
|
|
7
|
+
import { AnalyticsDashboardSkeleton } from "./AnalyticsDashboardSkeleton";
|
|
8
|
+
import { useDashboardWidgets } from "./useDashboardWidgets";
|
|
9
|
+
import { WidgetCustomizePanel } from "./WidgetCustomizePanel";
|
|
10
|
+
function formatBucketLabel(value, granularity) {
|
|
11
|
+
const date = new Date(value);
|
|
12
|
+
if (granularity === "hour") {
|
|
13
|
+
return date.toLocaleString(undefined, { month: "short", day: "numeric", hour: "numeric" });
|
|
14
|
+
}
|
|
15
|
+
return date.toLocaleDateString(undefined, { month: "short", day: "numeric" });
|
|
16
|
+
}
|
|
17
|
+
function formatNumber(value) {
|
|
18
|
+
return new Intl.NumberFormat().format(value);
|
|
19
|
+
}
|
|
20
|
+
function toDateInputValue(date) {
|
|
21
|
+
return date.toISOString().slice(0, 10);
|
|
22
|
+
}
|
|
23
|
+
function Delta({ current, previous }) {
|
|
24
|
+
if (previous === undefined)
|
|
25
|
+
return null;
|
|
26
|
+
const delta = percentChange(current, previous);
|
|
27
|
+
if (delta === null)
|
|
28
|
+
return _jsx("span", { className: "metricDelta", children: "\u2014" });
|
|
29
|
+
const up = delta >= 0;
|
|
30
|
+
return (_jsxs("span", { className: `metricDelta ${up ? "metricDeltaUp" : "metricDeltaDown"}`, children: [up ? "+" : "", delta, "% vs prior period"] }));
|
|
31
|
+
}
|
|
32
|
+
function BreakdownPanel({ title, emptyMessage, rows, }) {
|
|
33
|
+
return (_jsxs("div", { className: "chartPanel", children: [_jsx("div", { className: "panelTitle", children: title }), rows.length === 0 ? (_jsx("p", { className: "emptyState", children: emptyMessage })) : (_jsx("ul", { className: "list", children: rows.map((row) => (_jsxs("li", { children: [_jsx("span", { className: "listLabel", children: row.label }), _jsx("span", { className: "listValue", children: row.value })] }, row.key))) }))] }));
|
|
34
|
+
}
|
|
35
|
+
function useResolvedTheme(mode) {
|
|
36
|
+
const [resolved, setResolved] = useState("light");
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (mode !== "system") {
|
|
39
|
+
setResolved(mode);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const media = window.matchMedia("(prefers-color-scheme: dark)");
|
|
43
|
+
const apply = () => setResolved(media.matches ? "dark" : "light");
|
|
44
|
+
apply();
|
|
45
|
+
media.addEventListener("change", apply);
|
|
46
|
+
return () => media.removeEventListener("change", apply);
|
|
47
|
+
}, [mode]);
|
|
48
|
+
return resolved;
|
|
49
|
+
}
|
|
50
|
+
export function AnalyticsDashboard({ siteId, summaryEndpoint, exportEndpoint, loadingFallback, defaultTheme = "system", defaultWidgets = DEFAULT_DASHBOARD_WIDGETS, settingsEndpoint, }) {
|
|
51
|
+
const summaryUrl = summaryEndpoint ?? `/api/v1/sites/${siteId}/summary`;
|
|
52
|
+
const exportUrl = exportEndpoint ?? `/api/v1/sites/${siteId}/export`;
|
|
53
|
+
const [range, setRange] = useState("7d");
|
|
54
|
+
const [useCustomRange, setUseCustomRange] = useState(false);
|
|
55
|
+
const [customFrom, setCustomFrom] = useState(() => toDateInputValue(new Date(Date.now() - 7 * 24 * 60 * 60 * 1000)));
|
|
56
|
+
const [customTo, setCustomTo] = useState(() => toDateInputValue(new Date()));
|
|
57
|
+
const [granularity, setGranularity] = useState("day");
|
|
58
|
+
const [trafficScope, setTrafficScope] = useState("all");
|
|
59
|
+
const [path, setPath] = useState("");
|
|
60
|
+
const [contentId, setContentId] = useState("");
|
|
61
|
+
const [includeBlogArticles, setIncludeBlogArticles] = useState(false);
|
|
62
|
+
const [summary, setSummary] = useState(null);
|
|
63
|
+
const [initialLoading, setInitialLoading] = useState(true);
|
|
64
|
+
const [refreshing, setRefreshing] = useState(false);
|
|
65
|
+
const [error, setError] = useState("");
|
|
66
|
+
const [themeMode, setThemeMode] = useState(defaultTheme);
|
|
67
|
+
const resolvedTheme = useResolvedTheme(themeMode);
|
|
68
|
+
const hasLoadedRef = useRef(false);
|
|
69
|
+
const [showWidgetCustomize, setShowWidgetCustomize] = useState(false);
|
|
70
|
+
const [savingDefaultWidgets, setSavingDefaultWidgets] = useState(false);
|
|
71
|
+
const { widgets, toggleWidget, resetToDefault, isVisible } = useDashboardWidgets(siteId, defaultWidgets);
|
|
72
|
+
const filterParams = useMemo(() => {
|
|
73
|
+
const params = new URLSearchParams({
|
|
74
|
+
granularity,
|
|
75
|
+
compare: "1",
|
|
76
|
+
});
|
|
77
|
+
if (useCustomRange) {
|
|
78
|
+
params.set("from", new Date(`${customFrom}T00:00:00.000Z`).toISOString());
|
|
79
|
+
params.set("to", new Date(`${customTo}T23:59:59.999Z`).toISOString());
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
params.set("range", range);
|
|
83
|
+
}
|
|
84
|
+
if (trafficScope === "page" && path.trim()) {
|
|
85
|
+
params.set("scope", "page");
|
|
86
|
+
params.set("path", path.trim());
|
|
87
|
+
if (path.trim() === "/blog" && includeBlogArticles) {
|
|
88
|
+
params.set("includeBlogArticles", "1");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else if (trafficScope === "blog") {
|
|
92
|
+
if (contentId.trim()) {
|
|
93
|
+
params.set("scope", "article");
|
|
94
|
+
params.set("contentId", contentId.trim());
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
params.set("scope", "blog");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return params;
|
|
101
|
+
}, [
|
|
102
|
+
range,
|
|
103
|
+
useCustomRange,
|
|
104
|
+
customFrom,
|
|
105
|
+
customTo,
|
|
106
|
+
granularity,
|
|
107
|
+
trafficScope,
|
|
108
|
+
path,
|
|
109
|
+
contentId,
|
|
110
|
+
includeBlogArticles,
|
|
111
|
+
]);
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
let cancelled = false;
|
|
114
|
+
const isFirstLoad = !hasLoadedRef.current;
|
|
115
|
+
if (isFirstLoad) {
|
|
116
|
+
setInitialLoading(true);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
setRefreshing(true);
|
|
120
|
+
}
|
|
121
|
+
setError("");
|
|
122
|
+
fetch(`${summaryUrl}?${filterParams.toString()}`)
|
|
123
|
+
.then(async (res) => {
|
|
124
|
+
if (!res.ok) {
|
|
125
|
+
const payload = await res.json().catch(() => ({}));
|
|
126
|
+
throw new Error(payload.error ?? "Failed to load analytics");
|
|
127
|
+
}
|
|
128
|
+
return res.json();
|
|
129
|
+
})
|
|
130
|
+
.then((payload) => {
|
|
131
|
+
if (!cancelled) {
|
|
132
|
+
hasLoadedRef.current = true;
|
|
133
|
+
setSummary(payload.summary ?? payload);
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
.catch((err) => {
|
|
137
|
+
if (!cancelled)
|
|
138
|
+
setError(err.message);
|
|
139
|
+
})
|
|
140
|
+
.finally(() => {
|
|
141
|
+
if (!cancelled) {
|
|
142
|
+
setInitialLoading(false);
|
|
143
|
+
setRefreshing(false);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
return () => {
|
|
147
|
+
cancelled = true;
|
|
148
|
+
};
|
|
149
|
+
}, [summaryUrl, filterParams]);
|
|
150
|
+
const chartData = useMemo(() => (summary?.buckets ?? []).map((bucket) => ({
|
|
151
|
+
label: formatBucketLabel(bucket.bucket_start, granularity),
|
|
152
|
+
views: bucket.page_views,
|
|
153
|
+
uniques: bucket.unique_visitors,
|
|
154
|
+
})), [summary, granularity]);
|
|
155
|
+
const themeClass = resolvedTheme === "dark" ? "analytix-theme-dark" : "analytix-theme-light";
|
|
156
|
+
if (initialLoading) {
|
|
157
|
+
return (_jsx("div", { className: `analytix-dash ${themeClass}`, children: loadingFallback ?? _jsx(AnalyticsDashboardSkeleton, {}) }));
|
|
158
|
+
}
|
|
159
|
+
if (error) {
|
|
160
|
+
return (_jsx("div", { className: `analytix-dash ${themeClass}`, children: _jsx("p", { className: "error", children: error }) }));
|
|
161
|
+
}
|
|
162
|
+
if (!summary) {
|
|
163
|
+
return (_jsx("div", { className: `analytix-dash ${themeClass}`, children: _jsx("p", { className: "emptyState", children: "No analytics data yet." }) }));
|
|
164
|
+
}
|
|
165
|
+
const prev = summary.previous_period;
|
|
166
|
+
const gridStroke = resolvedTheme === "dark" ? "rgba(148,163,184,0.15)" : "rgba(15,23,42,0.08)";
|
|
167
|
+
const areaFill = resolvedTheme === "dark" ? "rgba(96,165,250,0.18)" : "rgba(0,82,255,0.12)";
|
|
168
|
+
const areaStroke = resolvedTheme === "dark" ? "#60a5fa" : "#0052ff";
|
|
169
|
+
const lineStroke = resolvedTheme === "dark" ? "#34d399" : "#059669";
|
|
170
|
+
async function saveDefaultWidgets() {
|
|
171
|
+
if (!settingsEndpoint)
|
|
172
|
+
return;
|
|
173
|
+
setSavingDefaultWidgets(true);
|
|
174
|
+
try {
|
|
175
|
+
await fetch(settingsEndpoint, {
|
|
176
|
+
method: "PATCH",
|
|
177
|
+
headers: { "Content-Type": "application/json" },
|
|
178
|
+
body: JSON.stringify({ analytics_config: { dashboard_widgets: widgets } }),
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
finally {
|
|
182
|
+
setSavingDefaultWidgets(false);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return (_jsxs("div", { className: `analytix-dash ${themeClass}${refreshing ? " analytix-refreshing" : ""}`, children: [_jsxs("div", { className: "toolbar", children: [_jsxs("span", { className: "realtime", children: [summary.realtime_visitors, " visitors in the last 15 minutes"] }), _jsxs("div", { className: "toolbarActions", children: [_jsx("button", { type: "button", className: "btn btnIcon", onClick: () => setShowWidgetCustomize((open) => !open), "aria-label": "Customize widgets", children: _jsx(SlidersHorizontal, { size: 16 }) }), _jsx("button", { type: "button", className: "btn btnIcon", onClick: () => setThemeMode((current) => current === "dark" || (current === "system" && resolvedTheme === "dark")
|
|
186
|
+
? "light"
|
|
187
|
+
: "dark"), "aria-label": "Toggle theme", children: resolvedTheme === "dark" ? _jsx(Sun, { size: 16 }) : _jsx(Moon, { size: 16 }) }), _jsxs("a", { className: "btn", href: `${exportUrl}?${filterParams.toString()}`, children: [_jsx(Download, { size: 14 }), "Export CSV"] })] })] }), showWidgetCustomize ? (_jsx(WidgetCustomizePanel, { widgets: widgets, onToggle: toggleWidget, onReset: resetToDefault, onSaveDefault: settingsEndpoint ? saveDefaultWidgets : undefined, savingDefault: savingDefaultWidgets })) : null, _jsxs("div", { className: "filters", children: [_jsxs("div", { className: "filterGroup filterGroupWide", children: [_jsx("span", { className: "filterLabel", children: "Range" }), _jsxs("div", { className: "chips", children: [["24h", "7d", "30d", "90d"].map((key) => (_jsx("button", { type: "button", className: !useCustomRange && range === key ? "chipActive" : "chip", onClick: () => {
|
|
188
|
+
setUseCustomRange(false);
|
|
189
|
+
setRange(key);
|
|
190
|
+
}, children: key }, key))), _jsx("button", { type: "button", className: useCustomRange ? "chipActive" : "chip", onClick: () => setUseCustomRange(true), children: "Custom" })] }), useCustomRange && (_jsxs("div", { className: "dateRangeRow", children: [_jsxs("label", { children: [_jsx("span", { className: "filterLabel", children: "From" }), _jsx("input", { type: "date", value: customFrom, max: customTo, onChange: (e) => setCustomFrom(e.target.value) })] }), _jsxs("label", { children: [_jsx("span", { className: "filterLabel", children: "To" }), _jsx("input", { type: "date", value: customTo, min: customFrom, max: toDateInputValue(new Date()), onChange: (e) => setCustomTo(e.target.value) })] })] }))] }), _jsxs("div", { className: "filterGroup", children: [_jsx("span", { className: "filterLabel", children: "Granularity" }), _jsx("div", { className: "chips", children: ["hour", "day"].map((key) => (_jsx("button", { type: "button", className: granularity === key ? "chipActive" : "chip", onClick: () => setGranularity(key), children: key }, key))) })] }), _jsxs("div", { className: "filterGroup", children: [_jsx("span", { className: "filterLabel", children: "Scope" }), _jsx("div", { className: "chips", children: ["all", "page", "blog"].map((key) => (_jsx("button", { type: "button", className: trafficScope === key ? "chipActive" : "chip", onClick: () => setTrafficScope(key), children: key }, key))) })] }), trafficScope === "page" && (_jsxs("div", { className: "filterGroup filterGroupWide textField", children: [_jsx("span", { className: "filterLabel", children: "Path" }), _jsx("input", { value: path, onChange: (e) => setPath(e.target.value), placeholder: "/pricing" }), path.trim() === "/blog" && (_jsxs("label", { className: "checkboxRow", children: [_jsx("input", { type: "checkbox", checked: includeBlogArticles, onChange: (e) => setIncludeBlogArticles(e.target.checked) }), "Include blog articles"] }))] })), trafficScope === "blog" && (_jsxs("div", { className: "filterGroup filterGroupWide textField", children: [_jsx("span", { className: "filterLabel", children: "Content ID (optional)" }), _jsx("input", { value: contentId, onChange: (e) => setContentId(e.target.value), placeholder: "Filter to a single article" })] }))] }), isVisible("metrics") ? (_jsxs("div", { className: "metrics", children: [_jsxs("div", { className: "metricCard", children: [_jsx(Eye, { size: 18 }), _jsx("span", { className: "metricValue", children: formatNumber(summary.total_page_views) }), _jsx("span", { className: "metricLabel", children: "Page views" }), _jsx(Delta, { current: summary.total_page_views, previous: prev?.total_page_views })] }), _jsxs("div", { className: "metricCard", children: [_jsx(Users, { size: 18 }), _jsx("span", { className: "metricValue", children: formatNumber(summary.unique_visitors) }), _jsx("span", { className: "metricLabel", children: "Unique visitors" }), _jsx(Delta, { current: summary.unique_visitors, previous: prev?.unique_visitors })] }), _jsxs("div", { className: "metricCard", children: [_jsx(Repeat, { size: 18 }), _jsx("span", { className: "metricValue", children: formatNumber(summary.total_sessions) }), _jsx("span", { className: "metricLabel", children: "Sessions" }), _jsx(Delta, { current: summary.total_sessions, previous: prev?.total_sessions })] }), _jsxs("div", { className: "metricCard", children: [_jsx(FileText, { size: 18 }), _jsx("span", { className: "metricValue", children: summary.pages_per_session.toFixed(2) }), _jsx("span", { className: "metricLabel", children: "Pages / session" })] }), _jsxs("div", { className: "metricCard", children: [_jsx(UserPlus, { size: 18 }), _jsx("span", { className: "metricValue", children: formatNumber(summary.new_visitors) }), _jsx("span", { className: "metricLabel", children: "New visitors" })] }), _jsxs("div", { className: "metricCard", children: [_jsx(UserCheck, { size: 18 }), _jsx("span", { className: "metricValue", children: formatNumber(summary.returning_visitors) }), _jsx("span", { className: "metricLabel", children: "Returning visitors" })] }), _jsxs("div", { className: "metricCard", children: [_jsx(MousePointerClick, { size: 18 }), _jsxs("span", { className: "metricValue", children: [summary.bounce_rate, "%"] }), _jsx("span", { className: "metricLabel", children: "Bounce rate" }), _jsx(Delta, { current: summary.bounce_rate, previous: prev?.bounce_rate })] }), _jsxs("div", { className: "metricCard", children: [_jsx(Clock, { size: 18 }), _jsxs("span", { className: "metricValue", children: [summary.avg_engagement_seconds, "s"] }), _jsx("span", { className: "metricLabel", children: "Avg engagement" }), _jsx(Delta, { current: summary.avg_engagement_seconds, previous: prev?.avg_engagement_seconds })] })] })) : null, isVisible("chart") ? (_jsxs("div", { className: "chartPanel", children: [_jsx("div", { className: "panelTitle", children: "Traffic over time" }), _jsx("div", { className: "chartContainer", children: _jsx(ResponsiveContainer, { width: "100%", height: "100%", children: _jsxs(ComposedChart, { data: chartData, children: [_jsx(CartesianGrid, { strokeDasharray: "3 3", stroke: gridStroke }), _jsx(XAxis, { dataKey: "label", tick: { fontSize: 12, fill: "var(--ax-muted)" } }), _jsx(YAxis, { tick: { fontSize: 12, fill: "var(--ax-muted)" } }), _jsx(Tooltip, { contentStyle: {
|
|
191
|
+
background: "var(--ax-surface)",
|
|
192
|
+
border: "1px solid var(--ax-border)",
|
|
193
|
+
borderRadius: 10,
|
|
194
|
+
color: "var(--ax-primary)",
|
|
195
|
+
} }), _jsx(Area, { type: "monotone", dataKey: "views", fill: areaFill, stroke: areaStroke, name: "Page views" }), _jsx(Line, { type: "monotone", dataKey: "uniques", stroke: lineStroke, name: "Uniques" })] }) }) })] })) : null, isVisible("top_paths") || isVisible("top_content") ? (_jsxs("div", { className: "splitPanels", children: [isVisible("top_paths") ? (_jsx(BreakdownPanel, { title: "Top paths", emptyMessage: "No path data for this period.", rows: summary.top_paths.map((row) => ({
|
|
196
|
+
key: row.path,
|
|
197
|
+
label: row.path,
|
|
198
|
+
value: `${formatNumber(row.views)} views · ${formatNumber(row.uniques)} uniques`,
|
|
199
|
+
})) })) : null, isVisible("top_content") ? (_jsx(BreakdownPanel, { title: "Top content", emptyMessage: "No content data for this period.", rows: summary.top_content.map((row) => ({
|
|
200
|
+
key: row.content_id || row.content_slug || row.content_title,
|
|
201
|
+
label: row.content_title || row.content_slug || row.content_id,
|
|
202
|
+
value: `${formatNumber(row.views)} views`,
|
|
203
|
+
})) })) : null] })) : null, isVisible("landing_pages") || isVisible("referrers") || isVisible("channels") ? (_jsxs("div", { className: "splitPanels", children: [isVisible("landing_pages") ? (_jsx(BreakdownPanel, { title: "Landing pages", emptyMessage: "No landing page data for this period.", rows: summary.landing_pages.map((row) => ({
|
|
204
|
+
key: row.path,
|
|
205
|
+
label: row.path,
|
|
206
|
+
value: `${formatNumber(row.sessions)} sessions`,
|
|
207
|
+
})) })) : null, isVisible("referrers") ? (_jsx(BreakdownPanel, { title: "Top referrers", emptyMessage: "No referrer data for this period.", rows: summary.referrer_breakdown.map((row) => ({
|
|
208
|
+
key: row.referrer,
|
|
209
|
+
label: row.referrer,
|
|
210
|
+
value: formatNumber(row.count),
|
|
211
|
+
})) })) : null, isVisible("channels") ? (_jsx(BreakdownPanel, { title: "Traffic channels", emptyMessage: "No channel data for this period.", rows: summary.channel_breakdown.map((row) => ({
|
|
212
|
+
key: row.channel,
|
|
213
|
+
label: row.channel,
|
|
214
|
+
value: formatNumber(row.count),
|
|
215
|
+
})) })) : null] })) : null, isVisible("utm") ? (_jsxs(_Fragment, { children: [_jsxs("div", { className: "splitPanels", children: [_jsx(BreakdownPanel, { title: "UTM source", emptyMessage: "No UTM source data for this period.", rows: summary.utm_source_breakdown.map((row) => ({
|
|
216
|
+
key: row.source,
|
|
217
|
+
label: row.source,
|
|
218
|
+
value: formatNumber(row.count),
|
|
219
|
+
})) }), _jsx(BreakdownPanel, { title: "UTM medium", emptyMessage: "No UTM medium data for this period.", rows: summary.utm_medium_breakdown.map((row) => ({
|
|
220
|
+
key: row.medium,
|
|
221
|
+
label: row.medium,
|
|
222
|
+
value: formatNumber(row.count),
|
|
223
|
+
})) })] }), _jsxs("div", { className: "splitPanels", children: [_jsx(BreakdownPanel, { title: "UTM campaign", emptyMessage: "No UTM campaign data for this period.", rows: summary.utm_campaign_breakdown.map((row) => ({
|
|
224
|
+
key: row.campaign,
|
|
225
|
+
label: row.campaign,
|
|
226
|
+
value: formatNumber(row.count),
|
|
227
|
+
})) }), _jsx(BreakdownPanel, { title: "UTM term", emptyMessage: "No UTM term data for this period.", rows: summary.utm_term_breakdown.map((row) => ({
|
|
228
|
+
key: row.term,
|
|
229
|
+
label: row.term,
|
|
230
|
+
value: formatNumber(row.count),
|
|
231
|
+
})) })] }), _jsx(BreakdownPanel, { title: "UTM content", emptyMessage: "No UTM content data for this period.", rows: summary.utm_content_breakdown.map((row) => ({
|
|
232
|
+
key: row.content,
|
|
233
|
+
label: row.content,
|
|
234
|
+
value: formatNumber(row.count),
|
|
235
|
+
})) })] })) : null, isVisible("geo") ? (_jsxs(_Fragment, { children: [_jsxs("div", { className: "splitPanels", children: [_jsx(BreakdownPanel, { title: "Countries", emptyMessage: "No geo data for this period.", rows: summary.country_breakdown.map((row) => ({
|
|
236
|
+
key: row.country,
|
|
237
|
+
label: row.country,
|
|
238
|
+
value: formatNumber(row.count),
|
|
239
|
+
})) }), _jsx(BreakdownPanel, { title: "Regions", emptyMessage: "No region data for this period.", rows: summary.region_breakdown.map((row) => ({
|
|
240
|
+
key: row.region,
|
|
241
|
+
label: row.region,
|
|
242
|
+
value: formatNumber(row.count),
|
|
243
|
+
})) })] }), _jsx(BreakdownPanel, { title: "Languages", emptyMessage: "No language data for this period.", rows: summary.language_breakdown.map((row) => ({
|
|
244
|
+
key: row.language,
|
|
245
|
+
label: row.language,
|
|
246
|
+
value: formatNumber(row.count),
|
|
247
|
+
})) })] })) : null, isVisible("devices") ? (_jsxs("div", { className: "splitPanels", children: [_jsx(BreakdownPanel, { title: "Devices", emptyMessage: "No device data for this period.", rows: summary.device_breakdown.map((row) => ({
|
|
248
|
+
key: row.device_type,
|
|
249
|
+
label: row.device_type,
|
|
250
|
+
value: formatNumber(row.count),
|
|
251
|
+
})) }), _jsx(BreakdownPanel, { title: "Browsers", emptyMessage: "No browser data for this period.", rows: summary.browser_breakdown.map((row) => ({
|
|
252
|
+
key: row.browser,
|
|
253
|
+
label: row.browser,
|
|
254
|
+
value: formatNumber(row.count),
|
|
255
|
+
})) })] })) : null, isVisible("os") ? (_jsx(BreakdownPanel, { title: "Operating systems", emptyMessage: "No OS data for this period.", rows: summary.os_breakdown.map((row) => ({
|
|
256
|
+
key: row.os,
|
|
257
|
+
label: row.os,
|
|
258
|
+
value: formatNumber(row.count),
|
|
259
|
+
})) })) : null] }));
|
|
260
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function AnalyticsDashboardSkeleton(): import("react").JSX.Element;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
export function AnalyticsDashboardSkeleton() {
|
|
3
|
+
return (_jsxs("div", { className: "analytix-dash analytix-skeleton", "aria-busy": "true", "aria-label": "Loading analytics", children: [_jsxs("div", { className: "toolbar", children: [_jsx("div", { className: "sk skRealtime" }), _jsx("div", { className: "sk skBtn" })] }), _jsx("div", { className: "filters", children: Array.from({ length: 4 }).map((_, i) => (_jsxs("div", { className: "filterGroup", children: [_jsx("div", { className: "sk skLabel" }), _jsxs("div", { className: "skRow", children: [_jsx("div", { className: "sk skChip" }), _jsx("div", { className: "sk skChip" }), _jsx("div", { className: "sk skChip" })] })] }, i))) }), _jsx("div", { className: "metrics", children: Array.from({ length: 7 }).map((_, i) => (_jsxs("div", { className: "metricCard", children: [_jsx("div", { className: "sk skIcon" }), _jsx("div", { className: "sk skMetricValue" }), _jsx("div", { className: "sk skMetricLabel" }), _jsx("div", { className: "sk skDelta" })] }, i))) }), _jsxs("div", { className: "chartPanel", children: [_jsx("div", { className: "sk skPanelTitle" }), _jsx("div", { className: "sk skChart" })] }), _jsx("div", { className: "splitPanels", children: Array.from({ length: 2 }).map((_, i) => (_jsxs("div", { className: "chartPanel", children: [_jsx("div", { className: "sk skPanelTitle" }), _jsx("div", { className: "skList", children: Array.from({ length: 5 }).map((__, j) => (_jsx("div", { className: "sk skListRow" }, j))) })] }, i))) })] }));
|
|
4
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type DashboardWidgetId } from "@analytix/core";
|
|
2
|
+
export declare function WidgetCustomizePanel({ widgets, onToggle, onReset, onSaveDefault, savingDefault, }: {
|
|
3
|
+
widgets: DashboardWidgetId[];
|
|
4
|
+
onToggle: (id: DashboardWidgetId) => void;
|
|
5
|
+
onReset: () => void;
|
|
6
|
+
onSaveDefault?: () => void;
|
|
7
|
+
savingDefault?: boolean;
|
|
8
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { DASHBOARD_WIDGET_IDS, DASHBOARD_WIDGET_LABELS, } from "@analytix/core";
|
|
3
|
+
export function WidgetCustomizePanel({ widgets, onToggle, onReset, onSaveDefault, savingDefault, }) {
|
|
4
|
+
return (_jsxs("div", { className: "chartPanel widgetCustomize", children: [_jsx("div", { className: "panelTitle", children: "Dashboard widgets" }), _jsx("div", { className: "widgetGrid", children: DASHBOARD_WIDGET_IDS.map((id) => (_jsxs("label", { className: "widgetToggle", children: [_jsx("input", { type: "checkbox", checked: widgets.includes(id), onChange: () => onToggle(id) }), DASHBOARD_WIDGET_LABELS[id]] }, id))) }), _jsxs("div", { className: "widgetActions", children: [_jsx("button", { type: "button", className: "btn", onClick: onReset, children: "Reset layout" }), onSaveDefault ? (_jsx("button", { type: "button", className: "btn", onClick: onSaveDefault, disabled: savingDefault, children: savingDefault ? "Saving…" : "Save as site default" })) : null] })] }));
|
|
5
|
+
}
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
.analytix-dash {
|
|
2
|
+
--ax-primary: #0f172a;
|
|
3
|
+
--ax-muted: #64748b;
|
|
4
|
+
--ax-accent: #0052ff;
|
|
5
|
+
--ax-surface: rgba(255, 255, 255, 0.72);
|
|
6
|
+
--ax-surface-solid: #ffffff;
|
|
7
|
+
--ax-border: rgba(15, 23, 42, 0.08);
|
|
8
|
+
--ax-success: #047857;
|
|
9
|
+
--ax-success-bg: rgba(5, 150, 105, 0.08);
|
|
10
|
+
--ax-danger: #dc2626;
|
|
11
|
+
--ax-up: #059669;
|
|
12
|
+
--ax-down: #dc2626;
|
|
13
|
+
--ax-chart-grid: rgba(15, 23, 42, 0.08);
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: column;
|
|
16
|
+
gap: 24px;
|
|
17
|
+
width: 100%;
|
|
18
|
+
color: var(--ax-primary);
|
|
19
|
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.analytix-dash.analytix-theme-dark {
|
|
23
|
+
--ax-primary: #e2e8f0;
|
|
24
|
+
--ax-muted: #94a3b8;
|
|
25
|
+
--ax-accent: #60a5fa;
|
|
26
|
+
--ax-surface: rgba(15, 23, 42, 0.72);
|
|
27
|
+
--ax-surface-solid: #0f172a;
|
|
28
|
+
--ax-border: rgba(148, 163, 184, 0.18);
|
|
29
|
+
--ax-success: #34d399;
|
|
30
|
+
--ax-success-bg: rgba(52, 211, 153, 0.12);
|
|
31
|
+
--ax-up: #34d399;
|
|
32
|
+
--ax-down: #f87171;
|
|
33
|
+
--ax-chart-grid: rgba(148, 163, 184, 0.15);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.analytix-dash.analytix-refreshing {
|
|
37
|
+
opacity: 0.72;
|
|
38
|
+
pointer-events: none;
|
|
39
|
+
transition: opacity 0.15s ease;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.analytix-dash .filters {
|
|
43
|
+
display: grid;
|
|
44
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
45
|
+
gap: 14px;
|
|
46
|
+
padding: 18px;
|
|
47
|
+
border: 1px solid var(--ax-border);
|
|
48
|
+
border-radius: 14px;
|
|
49
|
+
background: var(--ax-surface);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.analytix-dash .filterGroup {
|
|
53
|
+
display: flex;
|
|
54
|
+
flex-direction: column;
|
|
55
|
+
gap: 8px;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.analytix-dash .filterGroupWide {
|
|
59
|
+
grid-column: 1 / -1;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.analytix-dash .filterLabel {
|
|
63
|
+
font-size: 0.75rem;
|
|
64
|
+
font-weight: 600;
|
|
65
|
+
letter-spacing: 0.04em;
|
|
66
|
+
text-transform: uppercase;
|
|
67
|
+
color: var(--ax-muted);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.analytix-dash .chips {
|
|
71
|
+
display: flex;
|
|
72
|
+
flex-wrap: wrap;
|
|
73
|
+
gap: 6px;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.analytix-dash .chip,
|
|
77
|
+
.analytix-dash .chipActive {
|
|
78
|
+
padding: 7px 12px;
|
|
79
|
+
border-radius: 999px;
|
|
80
|
+
border: 1px solid var(--ax-border);
|
|
81
|
+
background: var(--ax-surface-solid);
|
|
82
|
+
font-size: 0.8125rem;
|
|
83
|
+
font-weight: 600;
|
|
84
|
+
cursor: pointer;
|
|
85
|
+
color: var(--ax-muted);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.analytix-dash .chipActive {
|
|
89
|
+
background: rgba(0, 82, 255, 0.08);
|
|
90
|
+
border-color: rgba(0, 82, 255, 0.18);
|
|
91
|
+
color: var(--ax-accent);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.analytix-dash.analytix-theme-dark .chipActive {
|
|
95
|
+
background: rgba(96, 165, 250, 0.14);
|
|
96
|
+
border-color: rgba(96, 165, 250, 0.28);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.analytix-dash .dateRangeRow {
|
|
100
|
+
display: flex;
|
|
101
|
+
flex-wrap: wrap;
|
|
102
|
+
gap: 12px;
|
|
103
|
+
margin-top: 4px;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.analytix-dash .dateRangeRow label {
|
|
107
|
+
display: flex;
|
|
108
|
+
flex-direction: column;
|
|
109
|
+
gap: 6px;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.analytix-dash .textField input,
|
|
113
|
+
.analytix-dash .dateRangeRow input,
|
|
114
|
+
.analytix-dash select {
|
|
115
|
+
font: inherit;
|
|
116
|
+
padding: 10px 12px;
|
|
117
|
+
border: 1px solid var(--ax-border);
|
|
118
|
+
border-radius: 10px;
|
|
119
|
+
background: var(--ax-surface-solid);
|
|
120
|
+
color: var(--ax-primary);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.analytix-dash .checkboxRow {
|
|
124
|
+
display: flex;
|
|
125
|
+
align-items: center;
|
|
126
|
+
gap: 8px;
|
|
127
|
+
font-size: 0.875rem;
|
|
128
|
+
color: var(--ax-muted);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.analytix-dash .metrics {
|
|
132
|
+
display: grid;
|
|
133
|
+
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
|
|
134
|
+
gap: 14px;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.analytix-dash .metricCard {
|
|
138
|
+
display: flex;
|
|
139
|
+
flex-direction: column;
|
|
140
|
+
gap: 8px;
|
|
141
|
+
padding: 18px;
|
|
142
|
+
border-radius: 14px;
|
|
143
|
+
border: 1px solid var(--ax-border);
|
|
144
|
+
background: var(--ax-surface);
|
|
145
|
+
color: var(--ax-accent);
|
|
146
|
+
min-width: 0;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.analytix-dash .metricValue {
|
|
150
|
+
font-size: 1.5rem;
|
|
151
|
+
font-weight: 600;
|
|
152
|
+
color: var(--ax-primary);
|
|
153
|
+
line-height: 1.2;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.analytix-dash .metricLabel {
|
|
157
|
+
font-size: 0.8125rem;
|
|
158
|
+
color: var(--ax-muted);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.analytix-dash .metricDelta {
|
|
162
|
+
font-size: 0.75rem;
|
|
163
|
+
color: var(--ax-muted);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.analytix-dash .metricDeltaUp {
|
|
167
|
+
color: var(--ax-up);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.analytix-dash .metricDeltaDown {
|
|
171
|
+
color: var(--ax-down);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.analytix-dash .chartPanel {
|
|
175
|
+
padding: 18px;
|
|
176
|
+
border-radius: 14px;
|
|
177
|
+
border: 1px solid var(--ax-border);
|
|
178
|
+
background: var(--ax-surface);
|
|
179
|
+
min-width: 0;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.analytix-dash .chartContainer {
|
|
183
|
+
width: 100%;
|
|
184
|
+
height: 280px;
|
|
185
|
+
min-height: 280px;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.analytix-dash .panelTitle {
|
|
189
|
+
font-size: 0.875rem;
|
|
190
|
+
font-weight: 700;
|
|
191
|
+
text-transform: uppercase;
|
|
192
|
+
color: var(--ax-muted);
|
|
193
|
+
margin-bottom: 14px;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.analytix-dash .splitPanels {
|
|
197
|
+
display: grid;
|
|
198
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
199
|
+
gap: 14px;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.analytix-dash .list {
|
|
203
|
+
list-style: none;
|
|
204
|
+
margin: 0;
|
|
205
|
+
padding: 0;
|
|
206
|
+
display: flex;
|
|
207
|
+
flex-direction: column;
|
|
208
|
+
gap: 8px;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.analytix-dash .list li {
|
|
212
|
+
display: flex;
|
|
213
|
+
justify-content: space-between;
|
|
214
|
+
gap: 12px;
|
|
215
|
+
font-size: 0.875rem;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
.analytix-dash .listLabel {
|
|
219
|
+
min-width: 0;
|
|
220
|
+
overflow: hidden;
|
|
221
|
+
text-overflow: ellipsis;
|
|
222
|
+
white-space: nowrap;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
.analytix-dash .listValue {
|
|
226
|
+
flex-shrink: 0;
|
|
227
|
+
color: var(--ax-muted);
|
|
228
|
+
font-variant-numeric: tabular-nums;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.analytix-dash .emptyState {
|
|
232
|
+
margin: 0;
|
|
233
|
+
font-size: 0.875rem;
|
|
234
|
+
color: var(--ax-muted);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
.analytix-dash .error {
|
|
238
|
+
color: var(--ax-danger);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
.analytix-dash .toolbar {
|
|
242
|
+
display: flex;
|
|
243
|
+
gap: 12px;
|
|
244
|
+
flex-wrap: wrap;
|
|
245
|
+
align-items: center;
|
|
246
|
+
justify-content: space-between;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
.analytix-dash .toolbarActions {
|
|
250
|
+
display: flex;
|
|
251
|
+
gap: 8px;
|
|
252
|
+
align-items: center;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
.analytix-dash .btn {
|
|
256
|
+
display: inline-flex;
|
|
257
|
+
align-items: center;
|
|
258
|
+
gap: 6px;
|
|
259
|
+
padding: 8px 14px;
|
|
260
|
+
border-radius: 8px;
|
|
261
|
+
border: 1px solid var(--ax-border);
|
|
262
|
+
background: var(--ax-surface-solid);
|
|
263
|
+
cursor: pointer;
|
|
264
|
+
font-size: 0.875rem;
|
|
265
|
+
font-weight: 600;
|
|
266
|
+
color: var(--ax-primary);
|
|
267
|
+
text-decoration: none;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.analytix-dash .btnIcon {
|
|
271
|
+
padding: 8px 10px;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.analytix-dash .realtime {
|
|
275
|
+
padding: 10px 14px;
|
|
276
|
+
border-radius: 10px;
|
|
277
|
+
background: var(--ax-success-bg);
|
|
278
|
+
color: var(--ax-success);
|
|
279
|
+
font-size: 0.875rem;
|
|
280
|
+
font-weight: 600;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/* Skeleton */
|
|
284
|
+
.analytix-dash.analytix-skeleton .sk {
|
|
285
|
+
border-radius: 8px;
|
|
286
|
+
background: linear-gradient(
|
|
287
|
+
90deg,
|
|
288
|
+
rgba(148, 163, 184, 0.12) 0%,
|
|
289
|
+
rgba(148, 163, 184, 0.22) 50%,
|
|
290
|
+
rgba(148, 163, 184, 0.12) 100%
|
|
291
|
+
);
|
|
292
|
+
background-size: 200% 100%;
|
|
293
|
+
animation: analytix-shimmer 1.4s ease-in-out infinite;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
.analytix-dash.analytix-skeleton .skRow {
|
|
297
|
+
display: flex;
|
|
298
|
+
gap: 6px;
|
|
299
|
+
flex-wrap: wrap;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
.analytix-dash.analytix-skeleton .skRealtime {
|
|
303
|
+
width: 260px;
|
|
304
|
+
height: 40px;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
.analytix-dash.analytix-skeleton .skBtn {
|
|
308
|
+
width: 120px;
|
|
309
|
+
height: 36px;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
.analytix-dash.analytix-skeleton .skLabel {
|
|
313
|
+
width: 72px;
|
|
314
|
+
height: 12px;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
.analytix-dash.analytix-skeleton .skChip {
|
|
318
|
+
width: 48px;
|
|
319
|
+
height: 32px;
|
|
320
|
+
border-radius: 999px;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
.analytix-dash.analytix-skeleton .skIcon {
|
|
324
|
+
width: 18px;
|
|
325
|
+
height: 18px;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
.analytix-dash.analytix-skeleton .skMetricValue {
|
|
329
|
+
width: 72px;
|
|
330
|
+
height: 28px;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
.analytix-dash.analytix-skeleton .skMetricLabel {
|
|
334
|
+
width: 96px;
|
|
335
|
+
height: 14px;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
.analytix-dash.analytix-skeleton .skDelta {
|
|
339
|
+
width: 120px;
|
|
340
|
+
height: 12px;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
.analytix-dash.analytix-skeleton .skPanelTitle {
|
|
344
|
+
width: 120px;
|
|
345
|
+
height: 14px;
|
|
346
|
+
margin-bottom: 14px;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
.analytix-dash.analytix-skeleton .skChart {
|
|
350
|
+
width: 100%;
|
|
351
|
+
height: 280px;
|
|
352
|
+
border-radius: 12px;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
.analytix-dash.analytix-skeleton .skList {
|
|
356
|
+
display: flex;
|
|
357
|
+
flex-direction: column;
|
|
358
|
+
gap: 8px;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
.analytix-dash.analytix-skeleton .skListRow {
|
|
362
|
+
width: 100%;
|
|
363
|
+
height: 18px;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
@keyframes analytix-shimmer {
|
|
367
|
+
0% {
|
|
368
|
+
background-position: 200% 0;
|
|
369
|
+
}
|
|
370
|
+
100% {
|
|
371
|
+
background-position: -200% 0;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
@media (max-width: 900px) {
|
|
376
|
+
.analytix-dash .filters,
|
|
377
|
+
.analytix-dash .splitPanels {
|
|
378
|
+
grid-template-columns: 1fr;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
.analytix-dash .widgetCustomize .widgetGrid {
|
|
383
|
+
display: grid;
|
|
384
|
+
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
|
385
|
+
gap: 10px;
|
|
386
|
+
margin-bottom: 14px;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
.analytix-dash .widgetToggle {
|
|
390
|
+
display: flex;
|
|
391
|
+
align-items: center;
|
|
392
|
+
gap: 8px;
|
|
393
|
+
font-size: 0.875rem;
|
|
394
|
+
color: var(--ax-muted);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
.analytix-dash .widgetActions {
|
|
398
|
+
display: flex;
|
|
399
|
+
flex-wrap: wrap;
|
|
400
|
+
gap: 8px;
|
|
401
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { AnalyticsDashboard, type AnalyticsDashboardProps } from "./AnalyticsDashboard";
|
|
2
|
+
export { AnalyticsDashboardSkeleton } from "./AnalyticsDashboardSkeleton";
|
|
3
|
+
export { WidgetCustomizePanel } from "./WidgetCustomizePanel";
|
|
4
|
+
export { useDashboardWidgets } from "./useDashboardWidgets";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type DashboardWidgetId } from "@analytix/core";
|
|
2
|
+
export declare function useDashboardWidgets(siteId: string, defaultWidgets?: DashboardWidgetId[]): {
|
|
3
|
+
widgets: ("metrics" | "chart" | "top_paths" | "top_content" | "landing_pages" | "referrers" | "channels" | "utm" | "geo" | "devices" | "os")[];
|
|
4
|
+
toggleWidget: (id: DashboardWidgetId) => void;
|
|
5
|
+
resetToDefault: () => void;
|
|
6
|
+
isVisible: (id: DashboardWidgetId) => boolean;
|
|
7
|
+
setWidgets: (next: DashboardWidgetId[]) => void;
|
|
8
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import { DASHBOARD_WIDGET_IDS, DEFAULT_DASHBOARD_WIDGETS, } from "@analytix/core";
|
|
3
|
+
function storageKey(siteId) {
|
|
4
|
+
return `analytix_widgets_${siteId}`;
|
|
5
|
+
}
|
|
6
|
+
function readStoredWidgets(siteId) {
|
|
7
|
+
if (typeof window === "undefined")
|
|
8
|
+
return null;
|
|
9
|
+
try {
|
|
10
|
+
const raw = localStorage.getItem(storageKey(siteId));
|
|
11
|
+
if (!raw)
|
|
12
|
+
return null;
|
|
13
|
+
const parsed = JSON.parse(raw);
|
|
14
|
+
const allowed = new Set(DASHBOARD_WIDGET_IDS);
|
|
15
|
+
const filtered = parsed.filter((id) => allowed.has(id));
|
|
16
|
+
return filtered.length ? filtered : null;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function useDashboardWidgets(siteId, defaultWidgets = DEFAULT_DASHBOARD_WIDGETS) {
|
|
23
|
+
const [widgets, setWidgets] = useState(defaultWidgets);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
setWidgets(readStoredWidgets(siteId) ?? defaultWidgets);
|
|
26
|
+
}, [siteId, defaultWidgets]);
|
|
27
|
+
const persist = useCallback((next) => {
|
|
28
|
+
setWidgets(next);
|
|
29
|
+
if (typeof window !== "undefined") {
|
|
30
|
+
localStorage.setItem(storageKey(siteId), JSON.stringify(next));
|
|
31
|
+
}
|
|
32
|
+
}, [siteId]);
|
|
33
|
+
const toggleWidget = useCallback((id) => {
|
|
34
|
+
persist(widgets.includes(id) ? widgets.filter((w) => w !== id) : [...widgets, id]);
|
|
35
|
+
}, [persist, widgets]);
|
|
36
|
+
const resetToDefault = useCallback(() => {
|
|
37
|
+
persist(defaultWidgets);
|
|
38
|
+
}, [defaultWidgets, persist]);
|
|
39
|
+
const isVisible = useCallback((id) => widgets.includes(id), [widgets]);
|
|
40
|
+
return { widgets, toggleWidget, resetToDefault, isVisible, setWidgets: persist };
|
|
41
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@analytix/dashboard",
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"description": "Analytix embeddable analytics dashboard UI",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./styles.css": "./dist/dashboard.css"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public",
|
|
21
|
+
"registry": "https://registry.npmjs.org"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/Shashank519915/analytix.git",
|
|
26
|
+
"directory": "packages/dashboard"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc && node -e \"require('fs').copyFileSync('src/dashboard.css','dist/dashboard.css')\"",
|
|
30
|
+
"prepublishOnly": "npm run build"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"react": ">=18",
|
|
34
|
+
"recharts": ">=2",
|
|
35
|
+
"lucide-react": ">=0.400"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@analytix/core": "^0.2.2"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/react": "^19",
|
|
42
|
+
"typescript": "^5",
|
|
43
|
+
"@analytix/core": "*"
|
|
44
|
+
}
|
|
45
|
+
}
|