sanity-plugin-ga-dashboard 1.0.0
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/api/index.d.mts +15 -0
- package/dist/api/index.d.ts +15 -0
- package/dist/api/index.esm.js +235 -0
- package/dist/api/index.esm.js.map +1 -0
- package/dist/api/index.js +260 -0
- package/dist/api/index.js.map +1 -0
- package/dist/index.d.mts +117 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.esm.js +880 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +890 -0
- package/dist/index.js.map +1 -0
- package/package.json +56 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,890 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __export = (target, all) => {
|
|
21
|
+
for (var name in all)
|
|
22
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
23
|
+
};
|
|
24
|
+
var __copyProps = (to, from, except, desc) => {
|
|
25
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
26
|
+
for (let key of __getOwnPropNames(from))
|
|
27
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
28
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
29
|
+
}
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
|
|
34
|
+
// src/index.ts
|
|
35
|
+
var src_exports = {};
|
|
36
|
+
__export(src_exports, {
|
|
37
|
+
googleAnalyticsPlugin: () => googleAnalyticsPlugin
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(src_exports);
|
|
40
|
+
|
|
41
|
+
// src/plugin.ts
|
|
42
|
+
var import_sanity = require("sanity");
|
|
43
|
+
var import_icons = require("@sanity/icons");
|
|
44
|
+
|
|
45
|
+
// src/components/dashboard.tsx
|
|
46
|
+
var import_react = require("react");
|
|
47
|
+
var import_recharts = require("recharts");
|
|
48
|
+
|
|
49
|
+
// src/utils/ga-api.ts
|
|
50
|
+
async function fetchAnalyticsData(apiUrl, dateRange) {
|
|
51
|
+
const res = await fetch(`${apiUrl}?range=${dateRange}`, { cache: "no-store" });
|
|
52
|
+
if (!res.ok) {
|
|
53
|
+
const err = await res.json().catch(() => null);
|
|
54
|
+
throw new Error(
|
|
55
|
+
(err == null ? void 0 : err.error) || `Analytics API error: ${res.status} ${res.statusText}`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return parseResponse(await res.json());
|
|
59
|
+
}
|
|
60
|
+
var mv = (row, i) => {
|
|
61
|
+
var _a, _b, _c;
|
|
62
|
+
return parseFloat((_c = (_b = (_a = row == null ? void 0 : row.metricValues) == null ? void 0 : _a[i]) == null ? void 0 : _b.value) != null ? _c : "0");
|
|
63
|
+
};
|
|
64
|
+
var dv = (row, i) => {
|
|
65
|
+
var _a, _b, _c;
|
|
66
|
+
return (_c = (_b = (_a = row == null ? void 0 : row.dimensionValues) == null ? void 0 : _a[i]) == null ? void 0 : _b.value) != null ? _c : "";
|
|
67
|
+
};
|
|
68
|
+
function totalOf(data) {
|
|
69
|
+
if (!(data == null ? void 0 : data.rows)) return 0;
|
|
70
|
+
return data.rows.reduce((s, r) => s + mv(r, 0), 0);
|
|
71
|
+
}
|
|
72
|
+
function parseOverview(d) {
|
|
73
|
+
var _a;
|
|
74
|
+
const row = (_a = d == null ? void 0 : d.rows) == null ? void 0 : _a[0];
|
|
75
|
+
if (!row) return { totalUsers: 0, newUsers: 0, sessions: 0, pageViews: 0, avgSessionDuration: 0, bounceRate: 0, engagedSessions: 0, engagementRate: 0, pagesPerSession: 0, eventsPerSession: 0 };
|
|
76
|
+
return {
|
|
77
|
+
totalUsers: mv(row, 0),
|
|
78
|
+
newUsers: mv(row, 1),
|
|
79
|
+
sessions: mv(row, 2),
|
|
80
|
+
pageViews: mv(row, 3),
|
|
81
|
+
avgSessionDuration: mv(row, 4),
|
|
82
|
+
bounceRate: mv(row, 5),
|
|
83
|
+
engagedSessions: mv(row, 6),
|
|
84
|
+
engagementRate: mv(row, 7),
|
|
85
|
+
pagesPerSession: mv(row, 8),
|
|
86
|
+
eventsPerSession: mv(row, 9)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function parseTimeSeries(d) {
|
|
90
|
+
if (!(d == null ? void 0 : d.rows)) return [];
|
|
91
|
+
return d.rows.map((row) => {
|
|
92
|
+
const s = dv(row, 0);
|
|
93
|
+
return {
|
|
94
|
+
date: `${s.slice(0, 4)}-${s.slice(4, 6)}-${s.slice(6, 8)}`,
|
|
95
|
+
displayDate: `${s.slice(4, 6)}/${s.slice(6, 8)}`,
|
|
96
|
+
users: mv(row, 0),
|
|
97
|
+
sessions: mv(row, 1),
|
|
98
|
+
pageViews: mv(row, 2)
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function parseHourly(d) {
|
|
103
|
+
if (!(d == null ? void 0 : d.rows)) return [];
|
|
104
|
+
return d.rows.map((row) => {
|
|
105
|
+
const h = parseInt(dv(row, 0), 10);
|
|
106
|
+
const suffix = h < 12 ? "AM" : "PM";
|
|
107
|
+
const display = h === 0 ? "12AM" : h <= 12 ? `${h}${suffix}` : `${h - 12}${suffix}`;
|
|
108
|
+
return { hour: dv(row, 0), label: display, users: mv(row, 0), sessions: mv(row, 1) };
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function parseTopPages(d) {
|
|
112
|
+
if (!(d == null ? void 0 : d.rows)) return [];
|
|
113
|
+
return d.rows.map((row) => ({ path: dv(row, 0), pageViews: mv(row, 0), users: mv(row, 1) }));
|
|
114
|
+
}
|
|
115
|
+
function parseLandingPages(d) {
|
|
116
|
+
if (!(d == null ? void 0 : d.rows)) return [];
|
|
117
|
+
return d.rows.map((row) => ({
|
|
118
|
+
path: dv(row, 0),
|
|
119
|
+
sessions: mv(row, 0),
|
|
120
|
+
users: mv(row, 1),
|
|
121
|
+
bounceRate: mv(row, 2)
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
function parseWithPercentage(d, dimIdx, metricIdx) {
|
|
125
|
+
if (!(d == null ? void 0 : d.rows)) return [];
|
|
126
|
+
const total = totalOf(d);
|
|
127
|
+
return d.rows.map((row) => {
|
|
128
|
+
const sessions = mv(row, metricIdx);
|
|
129
|
+
return { name: dv(row, dimIdx), sessions, percentage: total > 0 ? Math.round(sessions / total * 1e3) / 10 : 0 };
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function parseDevices(d) {
|
|
133
|
+
return parseWithPercentage(d, 0, 0).map((x) => ({ device: x.name, sessions: x.sessions, percentage: x.percentage }));
|
|
134
|
+
}
|
|
135
|
+
function parseBrowsers(d) {
|
|
136
|
+
return parseWithPercentage(d, 0, 0).map((x) => ({ browser: x.name, sessions: x.sessions, percentage: x.percentage }));
|
|
137
|
+
}
|
|
138
|
+
function parseOS(d) {
|
|
139
|
+
return parseWithPercentage(d, 0, 0).map((x) => ({ os: x.name, sessions: x.sessions, percentage: x.percentage }));
|
|
140
|
+
}
|
|
141
|
+
function parseCountries(d) {
|
|
142
|
+
if (!(d == null ? void 0 : d.rows)) return [];
|
|
143
|
+
return d.rows.map((row) => ({ country: dv(row, 0), users: mv(row, 0), sessions: mv(row, 1) }));
|
|
144
|
+
}
|
|
145
|
+
function parseCities(d) {
|
|
146
|
+
if (!(d == null ? void 0 : d.rows)) return [];
|
|
147
|
+
return d.rows.map((row) => ({ city: dv(row, 0), country: dv(row, 1), users: mv(row, 0), sessions: mv(row, 1) }));
|
|
148
|
+
}
|
|
149
|
+
function parseSources(d) {
|
|
150
|
+
if (!(d == null ? void 0 : d.rows)) return [];
|
|
151
|
+
return d.rows.map((row) => ({
|
|
152
|
+
source: [dv(row, 0), dv(row, 1)].filter(Boolean).join(" / "),
|
|
153
|
+
sessions: mv(row, 0),
|
|
154
|
+
users: mv(row, 1)
|
|
155
|
+
}));
|
|
156
|
+
}
|
|
157
|
+
function parseChannels(d) {
|
|
158
|
+
if (!(d == null ? void 0 : d.rows)) return [];
|
|
159
|
+
return d.rows.map((row) => ({
|
|
160
|
+
channel: dv(row, 0),
|
|
161
|
+
sessions: mv(row, 0),
|
|
162
|
+
users: mv(row, 1),
|
|
163
|
+
engagementRate: mv(row, 2)
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
function parseNewVsReturning(d) {
|
|
167
|
+
if (!(d == null ? void 0 : d.rows)) return [];
|
|
168
|
+
const total = totalOf(d);
|
|
169
|
+
return d.rows.map((row) => {
|
|
170
|
+
const users = mv(row, 0);
|
|
171
|
+
return {
|
|
172
|
+
type: dv(row, 0),
|
|
173
|
+
users,
|
|
174
|
+
percentage: total > 0 ? Math.round(users / total * 1e3) / 10 : 0
|
|
175
|
+
};
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function parseEvents(d) {
|
|
179
|
+
if (!(d == null ? void 0 : d.rows)) return [];
|
|
180
|
+
return d.rows.map((row) => ({ name: dv(row, 0), count: mv(row, 0), usersCount: mv(row, 1) }));
|
|
181
|
+
}
|
|
182
|
+
function parseReferrers(d) {
|
|
183
|
+
if (!(d == null ? void 0 : d.rows)) return [];
|
|
184
|
+
return d.rows.map((row) => ({ referrer: dv(row, 0) || "(direct)", sessions: mv(row, 0), users: mv(row, 1) }));
|
|
185
|
+
}
|
|
186
|
+
function parseActiveUsers(d) {
|
|
187
|
+
var _a, _b, _c, _d, _e;
|
|
188
|
+
return parseInt((_e = (_d = (_c = (_b = (_a = d == null ? void 0 : d.rows) == null ? void 0 : _a[0]) == null ? void 0 : _b.metricValues) == null ? void 0 : _c[0]) == null ? void 0 : _d.value) != null ? _e : "0", 10);
|
|
189
|
+
}
|
|
190
|
+
function parseResponse(raw) {
|
|
191
|
+
return {
|
|
192
|
+
activeUsers: parseActiveUsers(raw.activeUsers),
|
|
193
|
+
overview: parseOverview(raw.overview),
|
|
194
|
+
timeSeries: parseTimeSeries(raw.timeSeries),
|
|
195
|
+
hourlyToday: parseHourly(raw.hourlyToday),
|
|
196
|
+
topPages: parseTopPages(raw.topPages),
|
|
197
|
+
landingPages: parseLandingPages(raw.landingPages),
|
|
198
|
+
devices: parseDevices(raw.devices),
|
|
199
|
+
browsers: parseBrowsers(raw.browsers),
|
|
200
|
+
operatingSystems: parseOS(raw.operatingSystems),
|
|
201
|
+
countries: parseCountries(raw.countries),
|
|
202
|
+
cities: parseCities(raw.cities),
|
|
203
|
+
trafficSources: parseSources(raw.trafficSources),
|
|
204
|
+
channels: parseChannels(raw.channels),
|
|
205
|
+
newVsReturning: parseNewVsReturning(raw.newVsReturning),
|
|
206
|
+
topEvents: parseEvents(raw.topEvents),
|
|
207
|
+
referrers: parseReferrers(raw.referrers)
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// src/components/dashboard.tsx
|
|
212
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
213
|
+
var DATE_RANGES = [
|
|
214
|
+
{ label: "7d", value: "7" },
|
|
215
|
+
{ label: "14d", value: "14" },
|
|
216
|
+
{ label: "30d", value: "30" },
|
|
217
|
+
{ label: "90d", value: "90" }
|
|
218
|
+
];
|
|
219
|
+
var PALETTE = ["#4f8ef7", "#3ecf8e", "#f6b93b", "#e55353", "#a55eea", "#26c0d3", "#fd9644", "#20bf6b"];
|
|
220
|
+
var DEVICE_COLORS = {
|
|
221
|
+
desktop: "#4f8ef7",
|
|
222
|
+
mobile: "#3ecf8e",
|
|
223
|
+
tablet: "#f6b93b"
|
|
224
|
+
};
|
|
225
|
+
var CHANNEL_COLORS = {
|
|
226
|
+
"Organic Search": "#3ecf8e",
|
|
227
|
+
"Direct": "#4f8ef7",
|
|
228
|
+
"Referral": "#f6b93b",
|
|
229
|
+
"Organic Social": "#e55353",
|
|
230
|
+
"Email": "#a55eea",
|
|
231
|
+
"Paid Search": "#26c0d3",
|
|
232
|
+
"Display": "#fd9644"
|
|
233
|
+
};
|
|
234
|
+
var METRIC_INFO = {
|
|
235
|
+
"Total Users": "Unique users who visited your site in the selected period.",
|
|
236
|
+
"New Users": "First-time visitors \u2014 users who have never visited before.",
|
|
237
|
+
"Sessions": "Total browsing sessions. One user can have multiple sessions.",
|
|
238
|
+
"Page Views": "Total pages viewed, including repeated views of the same page.",
|
|
239
|
+
"Avg. Duration": "Average time a user spends in a single session.",
|
|
240
|
+
"Bounce Rate": "Percentage of sessions where the user left without any interaction.",
|
|
241
|
+
"Engaged Sessions": "Sessions lasting 10+ seconds, or with a conversion, or 2+ page views.",
|
|
242
|
+
"Engagement Rate": "Percentage of total sessions that were engaged sessions.",
|
|
243
|
+
"Pages / Session": "Average number of pages a user views per session.",
|
|
244
|
+
"Events / Session": "Average number of events (clicks, scrolls, etc.) fired per session."
|
|
245
|
+
};
|
|
246
|
+
var SECTION_INFO = {
|
|
247
|
+
"Users & Sessions Over Time": "Daily breakdown of users, sessions and page views over the selected date range.",
|
|
248
|
+
"Traffic by Hour \u2014 Today": "How traffic is distributed across each hour of today.",
|
|
249
|
+
"Channel Grouping": "Which marketing channels are driving sessions (Organic, Direct, Social, etc.).",
|
|
250
|
+
"Top Pages": "Most visited pages ranked by page view count.",
|
|
251
|
+
"Top Landing Pages": "First pages users arrive on, ranked by session count. High bounce rate may indicate poor landing experience.",
|
|
252
|
+
"Devices": "Share of sessions split by device type (desktop, mobile, tablet).",
|
|
253
|
+
"New vs Returning": "Ratio of first-time visitors to users who have visited before.",
|
|
254
|
+
"Browsers": "Which web browsers your visitors are using.",
|
|
255
|
+
"Operating Systems": "Which operating systems your visitors are running.",
|
|
256
|
+
"Top Events": "All events fired on your site (clicks, scrolls, form submits, custom events).",
|
|
257
|
+
"Top Countries": "Countries your users are visiting from, ranked by user count.",
|
|
258
|
+
"Top Cities": "Cities your users are visiting from, ranked by user count.",
|
|
259
|
+
"Traffic Sources": "Source and medium pairs showing where your traffic originates.",
|
|
260
|
+
"Top Referrers": "Specific pages on other websites that linked to your site."
|
|
261
|
+
};
|
|
262
|
+
var TABS = [
|
|
263
|
+
{ id: "overview", label: "Overview", icon: "\u25A6" },
|
|
264
|
+
{ id: "traffic", label: "Traffic", icon: "\u2197" },
|
|
265
|
+
{ id: "content", label: "Content", icon: "\u2261" },
|
|
266
|
+
{ id: "audience", label: "Audience", icon: "\u25C9" },
|
|
267
|
+
{ id: "geography", label: "Geography", icon: "\u2295" },
|
|
268
|
+
{ id: "events", label: "Events", icon: "\u26A1" },
|
|
269
|
+
{ id: "acquisition", label: "Acquisition", icon: "\u2934" }
|
|
270
|
+
];
|
|
271
|
+
var fNum = (n) => n >= 1e6 ? `${(n / 1e6).toFixed(1)}M` : n >= 1e3 ? `${(n / 1e3).toFixed(1)}K` : n.toLocaleString();
|
|
272
|
+
var fDur = (s) => {
|
|
273
|
+
const m = Math.floor(s / 60);
|
|
274
|
+
const sec = Math.round(s % 60);
|
|
275
|
+
return m > 0 ? `${m}m ${sec}s` : `${sec}s`;
|
|
276
|
+
};
|
|
277
|
+
var fPct = (v) => `${(v * 100).toFixed(1)}%`;
|
|
278
|
+
var fEngPct = (v) => `${(v * 100).toFixed(0)}%`;
|
|
279
|
+
var GLOBAL_CSS = `
|
|
280
|
+
@keyframes ga-spin { to { transform: rotate(360deg); } }
|
|
281
|
+
@keyframes ga-pulse { 0%,100%{box-shadow:0 0 0 3px rgba(62,207,142,.3)} 50%{box-shadow:0 0 0 7px rgba(62,207,142,.08)} }
|
|
282
|
+
@keyframes ga-fadein { from{opacity:0;transform:translateY(4px)} to{opacity:1;transform:translateY(0)} }
|
|
283
|
+
@keyframes ga-shimmer { 0%{background-position:-600px 0} 100%{background-position:600px 0} }
|
|
284
|
+
.ga-skel {
|
|
285
|
+
background:linear-gradient(90deg,#f1f5f9 25%,#e8eef4 50%,#f1f5f9 75%);
|
|
286
|
+
background-size:1200px 100%; animation:ga-shimmer 1.4s infinite linear; border-radius:4px;
|
|
287
|
+
}
|
|
288
|
+
.ga-tooltip-wrap { position:relative; display:inline-flex; align-items:center; }
|
|
289
|
+
.ga-tooltip-wrap .ga-tip {
|
|
290
|
+
visibility:hidden; opacity:0; pointer-events:none;
|
|
291
|
+
position:absolute; bottom:calc(100% + 6px); left:50%; transform:translateX(-50%);
|
|
292
|
+
background:#1e293b; color:#f1f5f9; font-size:12px; line-height:1.5;
|
|
293
|
+
padding:8px 12px; border-radius:7px; white-space:normal; width:220px;
|
|
294
|
+
box-shadow:0 4px 16px rgba(0,0,0,.18); z-index:9999; transition:opacity .15s;
|
|
295
|
+
}
|
|
296
|
+
.ga-tooltip-wrap .ga-tip::after {
|
|
297
|
+
content:''; position:absolute; top:100%; left:50%; transform:translateX(-50%);
|
|
298
|
+
border:5px solid transparent; border-top-color:#1e293b;
|
|
299
|
+
}
|
|
300
|
+
.ga-tooltip-wrap:hover .ga-tip { visibility:visible; opacity:1; }
|
|
301
|
+
.ga-info-btn {
|
|
302
|
+
width:16px; height:16px; border-radius:50%; border:1.5px solid #94a3b8;
|
|
303
|
+
background:transparent; color:#94a3b8; font-size:10px; font-weight:700;
|
|
304
|
+
cursor:default; display:inline-flex; align-items:center; justify-content:center;
|
|
305
|
+
margin-left:6px; flex-shrink:0; line-height:1; padding:0;
|
|
306
|
+
}
|
|
307
|
+
.ga-info-btn:hover { border-color:#4f8ef7; color:#4f8ef7; }
|
|
308
|
+
.ga-tab-btn { border:none; background:none; cursor:pointer; width:100%; padding:0; }
|
|
309
|
+
.ga-tab-btn:focus { outline:none; }
|
|
310
|
+
.ga-date-btn { border:none; cursor:pointer; }
|
|
311
|
+
.ga-retry-btn { border:none; cursor:pointer; }
|
|
312
|
+
`;
|
|
313
|
+
function InfoIcon({ text }) {
|
|
314
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "ga-tooltip-wrap", children: [
|
|
315
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "ga-info-btn", tabIndex: -1, children: "i" }),
|
|
316
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "ga-tip", children: text })
|
|
317
|
+
] });
|
|
318
|
+
}
|
|
319
|
+
function Skel({ w, h = 14, r = 4, style }) {
|
|
320
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "ga-skel", style: __spreadValues({ width: w != null ? w : "100%", height: h, borderRadius: r, flexShrink: 0 }, style) });
|
|
321
|
+
}
|
|
322
|
+
function Panel({ title, children, info, style }) {
|
|
323
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: __spreadValues({
|
|
324
|
+
background: "#fff",
|
|
325
|
+
border: "1px solid #e2e8f0",
|
|
326
|
+
borderRadius: 10,
|
|
327
|
+
padding: "20px 22px",
|
|
328
|
+
boxSizing: "border-box"
|
|
329
|
+
}, style), children: [
|
|
330
|
+
title && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", marginBottom: 16 }, children: [
|
|
331
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: 13, fontWeight: 600, color: "#1e293b", letterSpacing: "0.01em" }, children: title }),
|
|
332
|
+
info && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InfoIcon, { text: info })
|
|
333
|
+
] }),
|
|
334
|
+
children
|
|
335
|
+
] });
|
|
336
|
+
}
|
|
337
|
+
function SectionLabel({ children }) {
|
|
338
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { fontSize: 11, fontWeight: 700, color: "#94a3b8", textTransform: "uppercase", letterSpacing: "0.08em", marginBottom: 14 }, children });
|
|
339
|
+
}
|
|
340
|
+
function DataTable({ headers, rows, empty = "No data", loading, skeletonRows = 6 }) {
|
|
341
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { width: "100%", overflowX: "auto" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("table", { style: { width: "100%", borderCollapse: "collapse", fontSize: 13, tableLayout: "fixed" }, children: [
|
|
342
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: headers.map((h, i) => {
|
|
343
|
+
var _a;
|
|
344
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { style: {
|
|
345
|
+
padding: "6px 10px",
|
|
346
|
+
textAlign: (_a = h.align) != null ? _a : "left",
|
|
347
|
+
color: "#94a3b8",
|
|
348
|
+
fontWeight: 600,
|
|
349
|
+
fontSize: 11,
|
|
350
|
+
borderBottom: "1px solid #f1f5f9",
|
|
351
|
+
textTransform: "uppercase",
|
|
352
|
+
letterSpacing: "0.05em",
|
|
353
|
+
width: h.width,
|
|
354
|
+
whiteSpace: "nowrap"
|
|
355
|
+
}, children: h.label }, i);
|
|
356
|
+
}) }) }),
|
|
357
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("tbody", { children: loading ? Array.from({ length: skeletonRows }).map((_, ri) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { style: { borderBottom: "1px solid #f8fafc" }, children: headers.map((_h, ci) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { style: { padding: "9px 10px" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skel, { w: ci === 0 ? `${60 + ri * 7 % 30}%` : "70%", h: 12 }) }, ci)) }, ri)) : rows.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { colSpan: headers.length, style: { padding: "28px", textAlign: "center", color: "#cbd5e1", fontSize: 13 }, children: empty }) }) : rows.map((row, ri) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
358
|
+
"tr",
|
|
359
|
+
{
|
|
360
|
+
style: { borderBottom: "1px solid #f8fafc", transition: "background .1s" },
|
|
361
|
+
onMouseEnter: (e) => e.currentTarget.style.background = "#f8fafc",
|
|
362
|
+
onMouseLeave: (e) => e.currentTarget.style.background = "",
|
|
363
|
+
children: row.map((cell, ci) => {
|
|
364
|
+
var _a, _b;
|
|
365
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { style: {
|
|
366
|
+
padding: "9px 10px",
|
|
367
|
+
textAlign: (_b = (_a = headers[ci]) == null ? void 0 : _a.align) != null ? _b : "left",
|
|
368
|
+
color: ci === 0 ? "#334155" : ci === 1 ? "#1e293b" : "#94a3b8",
|
|
369
|
+
fontWeight: ci === 1 ? 600 : 400,
|
|
370
|
+
verticalAlign: "middle"
|
|
371
|
+
}, children: cell }, ci);
|
|
372
|
+
})
|
|
373
|
+
},
|
|
374
|
+
ri
|
|
375
|
+
)) })
|
|
376
|
+
] }) });
|
|
377
|
+
}
|
|
378
|
+
function Donut({ data, colors, info, loading }) {
|
|
379
|
+
if (loading) return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
380
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { display: "flex", justifyContent: "center", padding: "16px 0" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "ga-skel", style: { width: 120, height: 120, borderRadius: "50%" } }) }),
|
|
381
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { display: "flex", flexDirection: "column", gap: 8, marginTop: 4 }, children: Array.from({ length: 3 }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: 8 }, children: [
|
|
382
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "ga-skel", style: { width: 8, height: 8, borderRadius: 2, flexShrink: 0 } }),
|
|
383
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skel, { w: `${50 + i * 12}%`, h: 11 }),
|
|
384
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skel, { w: 30, h: 11, style: { marginLeft: "auto" } })
|
|
385
|
+
] }, i)) })
|
|
386
|
+
] });
|
|
387
|
+
if (data.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { color: "#cbd5e1", fontSize: 13, padding: "20px 0", textAlign: "center" }, children: "No data" });
|
|
388
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
389
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { height: 180 }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_recharts.PieChart, { children: [
|
|
390
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
391
|
+
import_recharts.Pie,
|
|
392
|
+
{
|
|
393
|
+
data,
|
|
394
|
+
dataKey: "value",
|
|
395
|
+
nameKey: "name",
|
|
396
|
+
cx: "50%",
|
|
397
|
+
cy: "50%",
|
|
398
|
+
innerRadius: 48,
|
|
399
|
+
outerRadius: 76,
|
|
400
|
+
paddingAngle: 2,
|
|
401
|
+
children: data.map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.Cell, { fill: colors[i % colors.length] }, i))
|
|
402
|
+
}
|
|
403
|
+
),
|
|
404
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
405
|
+
import_recharts.Tooltip,
|
|
406
|
+
{
|
|
407
|
+
formatter: (v) => fNum(Number(v)),
|
|
408
|
+
contentStyle: { background: "#fff", border: "1px solid #e2e8f0", borderRadius: 7, fontSize: 13 }
|
|
409
|
+
}
|
|
410
|
+
)
|
|
411
|
+
] }) }) }),
|
|
412
|
+
info && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { fontSize: 12, color: "#94a3b8", textAlign: "center", marginBottom: 12 }, children: info }),
|
|
413
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { display: "flex", flexDirection: "column", gap: 7 }, children: data.map((d, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: 8 }, children: [
|
|
414
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { width: 9, height: 9, borderRadius: 2, background: colors[i % colors.length], flexShrink: 0 } }),
|
|
415
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { flex: 1, fontSize: 13, color: "#475569", textTransform: "capitalize" }, children: d.name }),
|
|
416
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { style: { fontSize: 12, color: "#cbd5e1" }, children: [
|
|
417
|
+
d.percentage,
|
|
418
|
+
"%"
|
|
419
|
+
] }),
|
|
420
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: 13, fontWeight: 600, color: "#1e293b", minWidth: 40, textAlign: "right" }, children: fNum(d.value) })
|
|
421
|
+
] }, d.name)) })
|
|
422
|
+
] });
|
|
423
|
+
}
|
|
424
|
+
function MetricCard({ label, value, sub, color, info, loading }) {
|
|
425
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
426
|
+
"div",
|
|
427
|
+
{
|
|
428
|
+
style: {
|
|
429
|
+
flex: "1 1 140px",
|
|
430
|
+
minWidth: 132,
|
|
431
|
+
background: "#fff",
|
|
432
|
+
border: "1px solid #e2e8f0",
|
|
433
|
+
borderRadius: 10,
|
|
434
|
+
padding: "16px 18px",
|
|
435
|
+
boxSizing: "border-box",
|
|
436
|
+
transition: "box-shadow .15s"
|
|
437
|
+
},
|
|
438
|
+
onMouseEnter: (e) => e.currentTarget.style.boxShadow = "0 4px 14px rgba(0,0,0,.07)",
|
|
439
|
+
onMouseLeave: (e) => e.currentTarget.style.boxShadow = "",
|
|
440
|
+
children: [
|
|
441
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", marginBottom: 10 }, children: [
|
|
442
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: 11, color: "#94a3b8", fontWeight: 600, textTransform: "uppercase", letterSpacing: "0.06em", flex: 1 }, children: label }),
|
|
443
|
+
info && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InfoIcon, { text: info })
|
|
444
|
+
] }),
|
|
445
|
+
loading ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
446
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skel, { w: "55%", h: 22, r: 5 }),
|
|
447
|
+
sub && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skel, { w: "40%", h: 11, style: { marginTop: 6 } })
|
|
448
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
449
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { fontSize: 26, fontWeight: 700, color, lineHeight: 1, marginBottom: sub ? 4 : 0 }, children: value }),
|
|
450
|
+
sub && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { fontSize: 12, color: "#94a3b8", marginTop: 3 }, children: sub })
|
|
451
|
+
] })
|
|
452
|
+
]
|
|
453
|
+
}
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
function ActiveBadge({ count, loading }) {
|
|
457
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: {
|
|
458
|
+
display: "inline-flex",
|
|
459
|
+
alignItems: "center",
|
|
460
|
+
gap: 10,
|
|
461
|
+
background: "#f0fdf9",
|
|
462
|
+
border: "1px solid #a7f3d0",
|
|
463
|
+
borderRadius: 10,
|
|
464
|
+
padding: "12px 20px",
|
|
465
|
+
marginBottom: 20
|
|
466
|
+
}, children: [
|
|
467
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: {
|
|
468
|
+
width: 10,
|
|
469
|
+
height: 10,
|
|
470
|
+
borderRadius: "50%",
|
|
471
|
+
background: "#10b981",
|
|
472
|
+
animation: "ga-pulse 2s infinite",
|
|
473
|
+
flexShrink: 0
|
|
474
|
+
} }),
|
|
475
|
+
loading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skel, { w: 80, h: 20, r: 5 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: 22, fontWeight: 700, color: "#065f46" }, children: count.toLocaleString() }),
|
|
476
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: 13, color: "#047857" }, children: "users active right now" }),
|
|
477
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(InfoIcon, { text: "Real-time count of users active on your site in the last 30 minutes." })
|
|
478
|
+
] });
|
|
479
|
+
}
|
|
480
|
+
function PathCell({ path }) {
|
|
481
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { title: path, style: {
|
|
482
|
+
display: "block",
|
|
483
|
+
overflow: "hidden",
|
|
484
|
+
textOverflow: "ellipsis",
|
|
485
|
+
whiteSpace: "nowrap",
|
|
486
|
+
color: "#4f8ef7",
|
|
487
|
+
fontSize: 13
|
|
488
|
+
}, children: path });
|
|
489
|
+
}
|
|
490
|
+
function EmptyTab() {
|
|
491
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { display: "flex", justifyContent: "center", alignItems: "center", minHeight: 300, color: "#cbd5e1", fontSize: 14 }, children: "No data to display" });
|
|
492
|
+
}
|
|
493
|
+
function SkeletonChart({ height }) {
|
|
494
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { position: "relative", height, overflow: "hidden" }, children: [
|
|
495
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skel, { w: "100%", h: height, r: 6 }),
|
|
496
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: {
|
|
497
|
+
position: "absolute",
|
|
498
|
+
bottom: 0,
|
|
499
|
+
left: 0,
|
|
500
|
+
right: 0,
|
|
501
|
+
display: "flex",
|
|
502
|
+
justifyContent: "space-between",
|
|
503
|
+
padding: "0 4px 6px",
|
|
504
|
+
gap: 4,
|
|
505
|
+
pointerEvents: "none"
|
|
506
|
+
}, children: Array.from({ length: 7 }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Skel, { w: 32, h: 10, r: 3 }, i)) })
|
|
507
|
+
] });
|
|
508
|
+
}
|
|
509
|
+
function OverviewTab({ data, loading }) {
|
|
510
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { animation: "ga-fadein .25s ease", overflowX: "hidden" }, children: [
|
|
511
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ActiveBadge, { count: data.activeUsers, loading }),
|
|
512
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SectionLabel, { children: "Key Metrics" }),
|
|
513
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { display: "flex", gap: 10, flexWrap: "wrap", marginBottom: 24 }, children: [
|
|
514
|
+
["Total Users", fNum(data.overview.totalUsers), "#4f8ef7"],
|
|
515
|
+
["New Users", fNum(data.overview.newUsers), "#3ecf8e"],
|
|
516
|
+
["Sessions", fNum(data.overview.sessions), "#f6b93b"],
|
|
517
|
+
["Page Views", fNum(data.overview.pageViews), "#e55353"],
|
|
518
|
+
["Avg. Duration", fDur(data.overview.avgSessionDuration), "#a55eea"],
|
|
519
|
+
["Bounce Rate", fPct(data.overview.bounceRate), "#fd9644"]
|
|
520
|
+
].map(([l, v, c]) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MetricCard, { label: l, value: v, color: c, info: METRIC_INFO[l], loading }, l)) }),
|
|
521
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SectionLabel, { children: "Engagement" }),
|
|
522
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { display: "flex", gap: 10, flexWrap: "wrap" }, children: [
|
|
523
|
+
["Engaged Sessions", fNum(data.overview.engagedSessions), "#26c0d3"],
|
|
524
|
+
["Engagement Rate", fEngPct(data.overview.engagementRate), "#3ecf8e"],
|
|
525
|
+
["Pages / Session", data.overview.pagesPerSession.toFixed(1), "#8b5cf6"],
|
|
526
|
+
["Events / Session", data.overview.eventsPerSession.toFixed(1), "#f59e0b"]
|
|
527
|
+
].map(([l, v, c]) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MetricCard, { label: l, value: v, color: c, info: METRIC_INFO[l], loading }, l)) })
|
|
528
|
+
] });
|
|
529
|
+
}
|
|
530
|
+
function TrafficTab({ data, loading }) {
|
|
531
|
+
const channelBar = data.channels.map((c) => ({ name: c.channel, Sessions: c.sessions, Users: c.users }));
|
|
532
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { animation: "ga-fadein .25s ease", display: "flex", flexDirection: "column", gap: 20 }, children: [
|
|
533
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Panel, { title: "Users, Sessions & Page Views", info: SECTION_INFO["Users & Sessions Over Time"], children: loading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SkeletonChart, { height: 300 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { height: 300 }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_recharts.AreaChart, { data: data.timeSeries, margin: { top: 4, right: 8, left: 0, bottom: 0 }, children: [
|
|
534
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("defs", { children: [["gU", "#4f8ef7"], ["gS", "#3ecf8e"], ["gP", "#e55353"]].map(([id, c]) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("linearGradient", { id, x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
535
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { offset: "5%", stopColor: c, stopOpacity: 0.18 }),
|
|
536
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { offset: "95%", stopColor: c, stopOpacity: 0 })
|
|
537
|
+
] }, id)) }),
|
|
538
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.CartesianGrid, { strokeDasharray: "3 3", stroke: "#f1f5f9" }),
|
|
539
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.XAxis, { dataKey: "displayDate", fontSize: 11, tick: { fill: "#94a3b8" }, axisLine: false, tickLine: false }),
|
|
540
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.YAxis, { fontSize: 11, tick: { fill: "#94a3b8" }, axisLine: false, tickLine: false, width: 36 }),
|
|
541
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.Tooltip, { contentStyle: { background: "#fff", border: "1px solid #e2e8f0", borderRadius: 7, fontSize: 13 }, cursor: { stroke: "#f1f5f9" } }),
|
|
542
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.Legend, { wrapperStyle: { fontSize: 13, paddingTop: 10 } }),
|
|
543
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.Area, { type: "monotone", dataKey: "users", name: "Users", stroke: "#4f8ef7", fill: "url(#gU)", strokeWidth: 2, dot: false }),
|
|
544
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.Area, { type: "monotone", dataKey: "sessions", name: "Sessions", stroke: "#3ecf8e", fill: "url(#gS)", strokeWidth: 2, dot: false }),
|
|
545
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.Area, { type: "monotone", dataKey: "pageViews", name: "Pages", stroke: "#e55353", fill: "url(#gP)", strokeWidth: 2, dot: false })
|
|
546
|
+
] }) }) }) }),
|
|
547
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Panel, { title: "Traffic by Hour \u2014 Today", info: SECTION_INFO["Traffic by Hour \u2014 Today"], children: loading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SkeletonChart, { height: 220 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { height: 220 }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_recharts.BarChart, { data: data.hourlyToday, margin: { top: 4, right: 8, left: 0, bottom: 0 }, barSize: 12, barGap: 3, children: [
|
|
548
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.CartesianGrid, { strokeDasharray: "3 3", stroke: "#f1f5f9", vertical: false }),
|
|
549
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.XAxis, { dataKey: "label", fontSize: 11, tick: { fill: "#94a3b8" }, axisLine: false, tickLine: false, interval: 1 }),
|
|
550
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.YAxis, { fontSize: 11, tick: { fill: "#94a3b8" }, axisLine: false, tickLine: false, width: 32 }),
|
|
551
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.Tooltip, { contentStyle: { background: "#fff", border: "1px solid #e2e8f0", borderRadius: 7, fontSize: 13 } }),
|
|
552
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.Legend, { wrapperStyle: { fontSize: 13, paddingTop: 8 } }),
|
|
553
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.Bar, { dataKey: "users", name: "Users", fill: "#4f8ef7", radius: [3, 3, 0, 0] }),
|
|
554
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.Bar, { dataKey: "sessions", name: "Sessions", fill: "#3ecf8e", radius: [3, 3, 0, 0] })
|
|
555
|
+
] }) }) }) }),
|
|
556
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Panel, { title: "Channel Grouping", info: SECTION_INFO["Channel Grouping"], children: loading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SkeletonChart, { height: 200 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { height: Math.max(200, data.channels.length * 46) }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_recharts.BarChart, { data: channelBar, layout: "vertical", margin: { top: 4, right: 24, left: 8, bottom: 0 }, barSize: 11, children: [
|
|
557
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.CartesianGrid, { strokeDasharray: "3 3", stroke: "#f1f5f9", horizontal: false }),
|
|
558
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.XAxis, { type: "number", fontSize: 11, tick: { fill: "#94a3b8" }, axisLine: false, tickLine: false }),
|
|
559
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.YAxis, { type: "category", dataKey: "name", fontSize: 12, tick: { fill: "#475569" }, axisLine: false, tickLine: false, width: 130 }),
|
|
560
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.Tooltip, { contentStyle: { background: "#fff", border: "1px solid #e2e8f0", borderRadius: 7, fontSize: 13 } }),
|
|
561
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.Legend, { wrapperStyle: { fontSize: 13, paddingTop: 8 } }),
|
|
562
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.Bar, { dataKey: "Sessions", radius: [0, 3, 3, 0], children: channelBar.map((e, i) => {
|
|
563
|
+
var _a;
|
|
564
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.Cell, { fill: (_a = CHANNEL_COLORS[e.name]) != null ? _a : PALETTE[i % PALETTE.length] }, i);
|
|
565
|
+
}) })
|
|
566
|
+
] }) }) }) })
|
|
567
|
+
] });
|
|
568
|
+
}
|
|
569
|
+
function ContentTab({ data, loading }) {
|
|
570
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { animation: "ga-fadein .25s ease", display: "flex", flexDirection: "column", gap: 20 }, children: [
|
|
571
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Panel, { title: "Top Pages", info: SECTION_INFO["Top Pages"], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
572
|
+
DataTable,
|
|
573
|
+
{
|
|
574
|
+
loading,
|
|
575
|
+
headers: [{ label: "Page Path" }, { label: "Views", align: "right", width: "72px" }, { label: "Users", align: "right", width: "62px" }],
|
|
576
|
+
rows: data.topPages.map((p) => [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(PathCell, { path: p.path }, p.path), fNum(p.pageViews), fNum(p.users)])
|
|
577
|
+
}
|
|
578
|
+
) }),
|
|
579
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Panel, { title: "Top Landing Pages", info: SECTION_INFO["Top Landing Pages"], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
580
|
+
DataTable,
|
|
581
|
+
{
|
|
582
|
+
loading,
|
|
583
|
+
headers: [{ label: "Landing Page" }, { label: "Sessions", align: "right", width: "80px" }, { label: "Bounce", align: "right", width: "68px" }],
|
|
584
|
+
rows: data.landingPages.map((p) => [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(PathCell, { path: p.path }, p.path), fNum(p.sessions), fPct(p.bounceRate)])
|
|
585
|
+
}
|
|
586
|
+
) })
|
|
587
|
+
] });
|
|
588
|
+
}
|
|
589
|
+
function AudienceTab({ data, loading }) {
|
|
590
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { animation: "ga-fadein .25s ease", display: "flex", flexDirection: "column", gap: 20 }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "grid", gridTemplateColumns: "minmax(0,1fr) minmax(0,1fr)", gap: 12 }, children: [
|
|
591
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Panel, { title: "Devices", info: SECTION_INFO["Devices"], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
592
|
+
Donut,
|
|
593
|
+
{
|
|
594
|
+
loading,
|
|
595
|
+
data: data.devices.map((d) => ({ name: d.device, value: d.sessions, percentage: d.percentage })),
|
|
596
|
+
colors: data.devices.map((d) => {
|
|
597
|
+
var _a;
|
|
598
|
+
return (_a = DEVICE_COLORS[d.device.toLowerCase()]) != null ? _a : "#4f8ef7";
|
|
599
|
+
})
|
|
600
|
+
}
|
|
601
|
+
) }),
|
|
602
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Panel, { title: "New vs Returning", info: SECTION_INFO["New vs Returning"], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
603
|
+
Donut,
|
|
604
|
+
{
|
|
605
|
+
loading,
|
|
606
|
+
data: data.newVsReturning.map((d) => ({ name: d.type, value: d.users, percentage: d.percentage })),
|
|
607
|
+
colors: ["#4f8ef7", "#3ecf8e"]
|
|
608
|
+
}
|
|
609
|
+
) }),
|
|
610
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Panel, { title: "Browsers", info: SECTION_INFO["Browsers"], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
611
|
+
Donut,
|
|
612
|
+
{
|
|
613
|
+
loading,
|
|
614
|
+
data: data.browsers.map((d) => ({ name: d.browser, value: d.sessions, percentage: d.percentage })),
|
|
615
|
+
colors: PALETTE
|
|
616
|
+
}
|
|
617
|
+
) }),
|
|
618
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Panel, { title: "Operating Systems", info: SECTION_INFO["Operating Systems"], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
619
|
+
Donut,
|
|
620
|
+
{
|
|
621
|
+
loading,
|
|
622
|
+
data: data.operatingSystems.map((d) => ({ name: d.os, value: d.sessions, percentage: d.percentage })),
|
|
623
|
+
colors: PALETTE
|
|
624
|
+
}
|
|
625
|
+
) })
|
|
626
|
+
] }) });
|
|
627
|
+
}
|
|
628
|
+
function GeographyTab({ data, loading }) {
|
|
629
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { animation: "ga-fadein .25s ease", display: "flex", flexDirection: "column", gap: 20 }, children: [
|
|
630
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Panel, { title: "Top Countries", info: SECTION_INFO["Top Countries"], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
631
|
+
DataTable,
|
|
632
|
+
{
|
|
633
|
+
loading,
|
|
634
|
+
headers: [{ label: "Country" }, { label: "Users", align: "right", width: "70px" }, { label: "Sessions", align: "right", width: "78px" }],
|
|
635
|
+
rows: data.countries.map((c) => [c.country, fNum(c.users), fNum(c.sessions)])
|
|
636
|
+
}
|
|
637
|
+
) }),
|
|
638
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Panel, { title: "Top Cities", info: SECTION_INFO["Top Cities"], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
639
|
+
DataTable,
|
|
640
|
+
{
|
|
641
|
+
loading,
|
|
642
|
+
headers: [{ label: "City" }, { label: "Country", width: "110px" }, { label: "Users", align: "right", width: "65px" }, { label: "Sessions", align: "right", width: "75px" }],
|
|
643
|
+
rows: data.cities.map((c) => [
|
|
644
|
+
c.city,
|
|
645
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: 12, color: "#94a3b8" }, children: c.country }, c.city),
|
|
646
|
+
fNum(c.users),
|
|
647
|
+
fNum(c.sessions)
|
|
648
|
+
])
|
|
649
|
+
}
|
|
650
|
+
) })
|
|
651
|
+
] });
|
|
652
|
+
}
|
|
653
|
+
function EventsTab({ data, loading }) {
|
|
654
|
+
if (!loading && data.topEvents.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyTab, {});
|
|
655
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { animation: "ga-fadein .25s ease" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Panel, { title: "Top Events", info: SECTION_INFO["Top Events"], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
656
|
+
DataTable,
|
|
657
|
+
{
|
|
658
|
+
loading,
|
|
659
|
+
headers: [{ label: "Event Name" }, { label: "Count", align: "right", width: "80px" }, { label: "Users", align: "right", width: "70px" }],
|
|
660
|
+
rows: data.topEvents.map((e) => [e.name, fNum(e.count), fNum(e.usersCount)])
|
|
661
|
+
}
|
|
662
|
+
) }) });
|
|
663
|
+
}
|
|
664
|
+
function AcquisitionTab({ data, loading }) {
|
|
665
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { animation: "ga-fadein .25s ease", display: "flex", flexDirection: "column", gap: 20 }, children: [
|
|
666
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Panel, { title: "Traffic Sources", info: SECTION_INFO["Traffic Sources"], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
667
|
+
DataTable,
|
|
668
|
+
{
|
|
669
|
+
loading,
|
|
670
|
+
headers: [{ label: "Source / Medium" }, { label: "Sessions", align: "right", width: "82px" }, { label: "Users", align: "right", width: "65px" }],
|
|
671
|
+
rows: data.trafficSources.map((s) => [s.source || "(direct)", fNum(s.sessions), fNum(s.users)])
|
|
672
|
+
}
|
|
673
|
+
) }),
|
|
674
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Panel, { title: "Top Referrers", info: SECTION_INFO["Top Referrers"], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
675
|
+
DataTable,
|
|
676
|
+
{
|
|
677
|
+
loading,
|
|
678
|
+
headers: [{ label: "Referrer" }, { label: "Sessions", align: "right", width: "82px" }, { label: "Users", align: "right", width: "65px" }],
|
|
679
|
+
rows: data.referrers.map((r) => [
|
|
680
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { title: r.referrer, style: { display: "block", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", fontSize: 13 }, children: r.referrer }, r.referrer),
|
|
681
|
+
fNum(r.sessions),
|
|
682
|
+
fNum(r.users)
|
|
683
|
+
])
|
|
684
|
+
}
|
|
685
|
+
) })
|
|
686
|
+
] });
|
|
687
|
+
}
|
|
688
|
+
function Dashboard({ apiUrl }) {
|
|
689
|
+
var _a;
|
|
690
|
+
const [data, setData] = (0, import_react.useState)(null);
|
|
691
|
+
const [loading, setLoading] = (0, import_react.useState)(true);
|
|
692
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
693
|
+
const [dateRange, setDateRange] = (0, import_react.useState)("30");
|
|
694
|
+
const [activeTab, setActiveTab] = (0, import_react.useState)("overview");
|
|
695
|
+
const loadData = (0, import_react.useCallback)(async () => {
|
|
696
|
+
try {
|
|
697
|
+
setLoading(true);
|
|
698
|
+
setError(null);
|
|
699
|
+
setData(await fetchAnalyticsData(apiUrl, dateRange));
|
|
700
|
+
} catch (err) {
|
|
701
|
+
console.error("Failed to fetch analytics data", err);
|
|
702
|
+
setError(err instanceof Error ? err.message : "Failed to fetch analytics");
|
|
703
|
+
} finally {
|
|
704
|
+
setLoading(false);
|
|
705
|
+
}
|
|
706
|
+
}, [apiUrl, dateRange]);
|
|
707
|
+
(0, import_react.useEffect)(() => {
|
|
708
|
+
loadData();
|
|
709
|
+
}, [loadData]);
|
|
710
|
+
const H = "calc(100vh - 51px)";
|
|
711
|
+
if (loading && !data) return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", justifyContent: "center", alignItems: "center", minHeight: "100vh", flexDirection: "column", gap: 14, background: "#f8fafc" }, children: [
|
|
712
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { width: 36, height: 36, border: "3px solid #e2e8f0", borderTopColor: "#4f8ef7", borderRadius: "50%", animation: "ga-spin .8s linear infinite" } }),
|
|
713
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { color: "#94a3b8", fontSize: 14 }, children: "Loading analytics\u2026" }),
|
|
714
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { children: GLOBAL_CSS })
|
|
715
|
+
] });
|
|
716
|
+
if (error && !data) return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", justifyContent: "center", alignItems: "center", height: H, background: "#f8fafc" }, children: [
|
|
717
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { children: GLOBAL_CSS }),
|
|
718
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { maxWidth: 480, width: "100%", background: "#fff", border: "1px solid #e2e8f0", borderRadius: 12, padding: 32 }, children: [
|
|
719
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { fontWeight: 700, color: "#dc2626", marginBottom: 8, fontSize: 15 }, children: "Failed to load analytics" }),
|
|
720
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { fontSize: 13, color: "#64748b", marginBottom: 20, lineHeight: 1.6 }, children: error }),
|
|
721
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
722
|
+
"button",
|
|
723
|
+
{
|
|
724
|
+
className: "ga-retry-btn",
|
|
725
|
+
onClick: loadData,
|
|
726
|
+
style: { padding: "9px 22px", background: "#4f8ef7", color: "#fff", borderRadius: 7, cursor: "pointer", fontSize: 13, fontWeight: 600 },
|
|
727
|
+
children: "Retry"
|
|
728
|
+
}
|
|
729
|
+
)
|
|
730
|
+
] })
|
|
731
|
+
] });
|
|
732
|
+
if (!data) return null;
|
|
733
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: {
|
|
734
|
+
height: H,
|
|
735
|
+
background: "#f8fafc",
|
|
736
|
+
overflow: "hidden",
|
|
737
|
+
fontFamily: '-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif',
|
|
738
|
+
display: "flex",
|
|
739
|
+
justifyContent: "center",
|
|
740
|
+
alignItems: "stretch"
|
|
741
|
+
}, children: [
|
|
742
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { children: GLOBAL_CSS }),
|
|
743
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: {
|
|
744
|
+
display: "flex",
|
|
745
|
+
width: "100%",
|
|
746
|
+
height: "100%",
|
|
747
|
+
overflow: "hidden",
|
|
748
|
+
boxShadow: "0 0 0 1px #e2e8f0"
|
|
749
|
+
}, children: [
|
|
750
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: {
|
|
751
|
+
width: 180,
|
|
752
|
+
background: "#fff",
|
|
753
|
+
borderRight: "1px solid #e2e8f0",
|
|
754
|
+
display: "flex",
|
|
755
|
+
flexDirection: "column",
|
|
756
|
+
flexShrink: 0,
|
|
757
|
+
overflow: "hidden"
|
|
758
|
+
}, children: [
|
|
759
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { padding: "20px 16px 16px", borderBottom: "1px solid #f1f5f9" }, children: [
|
|
760
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { fontSize: 13, fontWeight: 700, color: "#1e293b", letterSpacing: "0.01em" }, children: "Analytics" }),
|
|
761
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { fontSize: 11, color: "#94a3b8", marginTop: 2 }, children: "Google Analytics 4" })
|
|
762
|
+
] }),
|
|
763
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { padding: "12px 12px 8px" }, children: [
|
|
764
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { fontSize: 10, fontWeight: 700, color: "#cbd5e1", textTransform: "uppercase", letterSpacing: "0.07em", marginBottom: 6 }, children: "Date Range" }),
|
|
765
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { display: "flex", gap: 4, flexWrap: "wrap" }, children: DATE_RANGES.map((r) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
766
|
+
"button",
|
|
767
|
+
{
|
|
768
|
+
className: "ga-date-btn",
|
|
769
|
+
onClick: () => setDateRange(r.value),
|
|
770
|
+
style: {
|
|
771
|
+
padding: "4px 8px",
|
|
772
|
+
fontSize: 11,
|
|
773
|
+
fontWeight: dateRange === r.value ? 700 : 400,
|
|
774
|
+
borderRadius: 5,
|
|
775
|
+
border: dateRange === r.value ? "1.5px solid #4f8ef7" : "1.5px solid #e2e8f0",
|
|
776
|
+
background: dateRange === r.value ? "#eff6ff" : "#fff",
|
|
777
|
+
color: dateRange === r.value ? "#4f8ef7" : "#64748b",
|
|
778
|
+
cursor: "pointer"
|
|
779
|
+
},
|
|
780
|
+
children: r.label
|
|
781
|
+
},
|
|
782
|
+
r.value
|
|
783
|
+
)) })
|
|
784
|
+
] }),
|
|
785
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("nav", { style: { flex: 1, overflow: "auto", padding: "8px 8px" }, children: [
|
|
786
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { fontSize: 10, fontWeight: 700, color: "#cbd5e1", textTransform: "uppercase", letterSpacing: "0.07em", marginBottom: 6, paddingLeft: 8 }, children: "Sections" }),
|
|
787
|
+
TABS.map((tab) => {
|
|
788
|
+
const active = activeTab === tab.id;
|
|
789
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
790
|
+
"button",
|
|
791
|
+
{
|
|
792
|
+
className: "ga-tab-btn",
|
|
793
|
+
onClick: () => setActiveTab(tab.id),
|
|
794
|
+
style: {
|
|
795
|
+
display: "flex",
|
|
796
|
+
alignItems: "center",
|
|
797
|
+
gap: 9,
|
|
798
|
+
padding: "9px 10px",
|
|
799
|
+
borderRadius: 7,
|
|
800
|
+
marginBottom: 2,
|
|
801
|
+
background: active ? "#eff6ff" : "transparent",
|
|
802
|
+
color: active ? "#4f8ef7" : "#64748b",
|
|
803
|
+
fontWeight: active ? 600 : 400,
|
|
804
|
+
fontSize: 13
|
|
805
|
+
},
|
|
806
|
+
children: [
|
|
807
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: 14, opacity: 0.8 }, children: tab.icon }),
|
|
808
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: tab.label }),
|
|
809
|
+
active && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { marginLeft: "auto", width: 4, height: 4, borderRadius: "50%", background: "#4f8ef7" } })
|
|
810
|
+
]
|
|
811
|
+
},
|
|
812
|
+
tab.id
|
|
813
|
+
);
|
|
814
|
+
})
|
|
815
|
+
] }),
|
|
816
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { padding: "12px", borderTop: "1px solid #f1f5f9" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
817
|
+
"button",
|
|
818
|
+
{
|
|
819
|
+
className: "ga-retry-btn",
|
|
820
|
+
onClick: loadData,
|
|
821
|
+
style: {
|
|
822
|
+
width: "100%",
|
|
823
|
+
padding: "8px",
|
|
824
|
+
background: "#f8fafc",
|
|
825
|
+
border: "1px solid #e2e8f0",
|
|
826
|
+
borderRadius: 7,
|
|
827
|
+
fontSize: 12,
|
|
828
|
+
color: loading ? "#94a3b8" : "#475569",
|
|
829
|
+
cursor: "pointer",
|
|
830
|
+
display: "flex",
|
|
831
|
+
alignItems: "center",
|
|
832
|
+
justifyContent: "center",
|
|
833
|
+
gap: 6,
|
|
834
|
+
fontWeight: 500
|
|
835
|
+
},
|
|
836
|
+
children: loading ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
837
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { width: 12, height: 12, border: "2px solid #e2e8f0", borderTopColor: "#4f8ef7", borderRadius: "50%", animation: "ga-spin .8s linear infinite" } }),
|
|
838
|
+
"Refreshing\u2026"
|
|
839
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "\u21BB Refresh" })
|
|
840
|
+
}
|
|
841
|
+
) })
|
|
842
|
+
] }),
|
|
843
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { flex: 1, overflow: "auto", padding: "24px 28px" }, children: [
|
|
844
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 22 }, children: [
|
|
845
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
846
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { style: { margin: 0, fontSize: 18, fontWeight: 700, color: "#1e293b" }, children: (_a = TABS.find((t) => t.id === activeTab)) == null ? void 0 : _a.label }),
|
|
847
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { fontSize: 12, color: "#94a3b8", marginTop: 3 }, children: [
|
|
848
|
+
"Last ",
|
|
849
|
+
dateRange,
|
|
850
|
+
" days"
|
|
851
|
+
] })
|
|
852
|
+
] }),
|
|
853
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { background: "#fffbeb", border: "1px solid #fcd34d", borderRadius: 7, padding: "8px 14px", fontSize: 12, color: "#92400e" }, children: "\u26A0 Showing cached data" })
|
|
854
|
+
] }),
|
|
855
|
+
activeTab === "overview" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OverviewTab, { data, loading }),
|
|
856
|
+
activeTab === "traffic" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TrafficTab, { data, loading }),
|
|
857
|
+
activeTab === "content" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContentTab, { data, loading }),
|
|
858
|
+
activeTab === "audience" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AudienceTab, { data, loading }),
|
|
859
|
+
activeTab === "geography" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GeographyTab, { data, loading }),
|
|
860
|
+
activeTab === "events" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EventsTab, { data, loading }),
|
|
861
|
+
activeTab === "acquisition" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AcquisitionTab, { data, loading })
|
|
862
|
+
] })
|
|
863
|
+
] })
|
|
864
|
+
] });
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
// src/google-analytics-tool.tsx
|
|
868
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
869
|
+
function GoogleAnalyticsTool({ apiUrl }) {
|
|
870
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Dashboard, { apiUrl: apiUrl || "/api/analytics" });
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
// src/plugin.ts
|
|
874
|
+
var googleAnalyticsPlugin = (config = {}) => (0, import_sanity.definePlugin)({
|
|
875
|
+
name: "ga-dashboard",
|
|
876
|
+
tools: (prev) => [
|
|
877
|
+
...prev,
|
|
878
|
+
{
|
|
879
|
+
name: "ga-dashboard",
|
|
880
|
+
title: "Google Analytics",
|
|
881
|
+
icon: import_icons.BarChartIcon,
|
|
882
|
+
component: () => GoogleAnalyticsTool(config)
|
|
883
|
+
}
|
|
884
|
+
]
|
|
885
|
+
})();
|
|
886
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
887
|
+
0 && (module.exports = {
|
|
888
|
+
googleAnalyticsPlugin
|
|
889
|
+
});
|
|
890
|
+
//# sourceMappingURL=index.js.map
|