qarpeo 0.1.18 → 0.1.21

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.
Files changed (237) hide show
  1. package/README.md +96 -96
  2. package/dist/chunks/auth-schema.mjs +3 -1
  3. package/dist/chunks/wrangler.mjs +22 -3
  4. package/dist/cli/index.mjs +448 -221
  5. package/dist/fate/index.d.ts +29 -22
  6. package/dist/fate/index.mjs +1 -3
  7. package/dist/module.d.ts +1 -1
  8. package/dist/module.mjs +103 -82
  9. package/dist/runtime/ai.d.ts +2 -2
  10. package/dist/runtime/app/components/BlobImage.vue +119 -107
  11. package/dist/runtime/app/components/CMSBlocks.vue +104 -93
  12. package/dist/runtime/app/components/CMSContent.vue +24 -23
  13. package/dist/runtime/app/components/CMSImage.vue +49 -49
  14. package/dist/runtime/app/components/CMSLocaleSwitcher.vue +110 -110
  15. package/dist/runtime/app/components/CMSPreviewBanner.vue +83 -79
  16. package/dist/runtime/app/components/CMSVersionBanner.vue +53 -49
  17. package/dist/runtime/app/components/CMSVersionSwitcher.vue +140 -140
  18. package/dist/runtime/app/components/ContentRenderer.vue +83 -80
  19. package/dist/runtime/app/components/FileUpload.vue +200 -196
  20. package/dist/runtime/app/components/ImpersonationBanner.vue +61 -57
  21. package/dist/runtime/app/components/QarpeoWelcome.vue +84 -84
  22. package/dist/runtime/app/components/SignedIn.vue +13 -13
  23. package/dist/runtime/app/components/SignedOut.vue +13 -13
  24. package/dist/runtime/app/components/shiki.css +34 -34
  25. package/dist/runtime/app/composables/ai.d.ts +22 -22
  26. package/dist/runtime/app/composables/ai.mjs +3 -7
  27. package/dist/runtime/app/composables/analytics.mjs +1 -1
  28. package/dist/runtime/app/composables/api-tokens.mjs +1 -1
  29. package/dist/runtime/app/composables/auth.d.ts +6 -7
  30. package/dist/runtime/app/composables/auth.mjs +6 -3
  31. package/dist/runtime/app/composables/chat.mjs +3 -7
  32. package/dist/runtime/app/composables/cms-preview.d.ts +3 -3
  33. package/dist/runtime/app/composables/cms-preview.mjs +1 -1
  34. package/dist/runtime/app/composables/cms.d.ts +3 -5
  35. package/dist/runtime/app/composables/cms.mjs +2 -2
  36. package/dist/runtime/app/composables/docs-version.d.ts +8 -7
  37. package/dist/runtime/app/composables/docs-version.mjs +3 -3
  38. package/dist/runtime/app/composables/impersonation.mjs +1 -1
  39. package/dist/runtime/app/composables/notifications.d.ts +5 -5
  40. package/dist/runtime/app/composables/notifications.mjs +4 -5
  41. package/dist/runtime/app/composables/organization.mjs +1 -1
  42. package/dist/runtime/app/composables/passkey.mjs +1 -1
  43. package/dist/runtime/app/composables/passwordless.mjs +1 -1
  44. package/dist/runtime/app/composables/payments.d.ts +2 -1
  45. package/dist/runtime/app/composables/payments.mjs +1 -1
  46. package/dist/runtime/app/composables/realtime.d.ts +13 -13
  47. package/dist/runtime/app/composables/realtime.mjs +2 -2
  48. package/dist/runtime/app/composables/resumable-upload.d.ts +11 -11
  49. package/dist/runtime/app/composables/resumable-upload.mjs +1 -1
  50. package/dist/runtime/app/composables/site.mjs +1 -1
  51. package/dist/runtime/app/composables/storage.d.ts +151 -11
  52. package/dist/runtime/app/composables/storage.mjs +291 -33
  53. package/dist/runtime/app/composables/turnstile.mjs +1 -1
  54. package/dist/runtime/app/composables/two-factor.mjs +1 -1
  55. package/dist/runtime/app/pages/devtools/agents.vue +716 -716
  56. package/dist/runtime/app/pages/devtools/analytics.vue +616 -616
  57. package/dist/runtime/app/pages/devtools/auth.vue +381 -350
  58. package/dist/runtime/app/pages/devtools/blob.vue +743 -744
  59. package/dist/runtime/app/pages/devtools/db.vue +545 -545
  60. package/dist/runtime/app/pages/devtools/domains.vue +771 -771
  61. package/dist/runtime/app/pages/devtools/kv.vue +827 -828
  62. package/dist/runtime/app/pages/devtools/logs.vue +649 -653
  63. package/dist/runtime/app/pages/devtools/mail.vue +388 -388
  64. package/dist/runtime/app/pages/devtools/overview.vue +391 -389
  65. package/dist/runtime/app/pages/devtools/realtime.vue +89 -27
  66. package/dist/runtime/app/pages/devtools/security.vue +20 -5
  67. package/dist/runtime/app/pages/devtools/settings.vue +559 -559
  68. package/dist/runtime/app/pages/devtools/tasks.vue +26 -10
  69. package/dist/runtime/app/pages/devtools.vue +176 -176
  70. package/dist/runtime/app/plugins/seo.mjs +1 -1
  71. package/dist/runtime/app/plugins/shortcuts.client.d.ts +1 -4
  72. package/dist/runtime/app/public/sw-notifications.mjs +47 -52
  73. package/dist/runtime/blob.mjs +11 -4
  74. package/dist/runtime/browser.d.ts +1 -1
  75. package/dist/runtime/browser.mjs +12 -2
  76. package/dist/runtime/cache.d.ts +2 -1
  77. package/dist/runtime/kv.mjs +4 -1
  78. package/dist/runtime/providers/qarpeo.d.ts +3 -3
  79. package/dist/runtime/server/durable-objects/agent.mjs +1 -1
  80. package/dist/runtime/server/durable-objects/room.d.ts +2 -2
  81. package/dist/runtime/server/durable-objects/room.mjs +5 -5
  82. package/dist/runtime/server/middleware/devtools.mjs +6 -2
  83. package/dist/runtime/server/plugins/cms.d.ts +4 -2
  84. package/dist/runtime/server/plugins/dev-proxy.mjs +1 -1
  85. package/dist/runtime/server/routes/__qarpeo/agents/chat.post.d.ts +2 -2
  86. package/dist/runtime/server/routes/__qarpeo/agents/chat.post.mjs +4 -1
  87. package/dist/runtime/server/routes/__qarpeo/analytics/events.get.d.ts +1 -4
  88. package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.d.ts +2 -2
  89. package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.mjs +5 -1
  90. package/dist/runtime/server/routes/__qarpeo/db/tables.get.d.ts +2 -2
  91. package/dist/runtime/server/routes/__qarpeo/db/tables.get.mjs +1 -1
  92. package/dist/runtime/server/routes/__qarpeo/logs.get.d.ts +4 -1
  93. package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +1 -1
  94. package/dist/runtime/server/routes/__qarpeo/mail/track/open/[id].get.mjs +2 -2
  95. package/dist/runtime/server/routes/__qarpeo/overview.get.d.ts +2 -2
  96. package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.d.ts +2 -2
  97. package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.mjs +1 -1
  98. package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.d.ts +1 -4
  99. package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.mjs +1 -1
  100. package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.d.ts +1 -4
  101. package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.mjs +1 -1
  102. package/dist/runtime/server/routes/__qarpeo/realtime/room.get.d.ts +2 -2
  103. package/dist/runtime/server/routes/__qarpeo/realtime/rooms.get.d.ts +2 -2
  104. package/dist/runtime/server/routes/__qarpeo/security/analytics.get.d.ts +2 -2
  105. package/dist/runtime/server/routes/__qarpeo/security/ban.post.d.ts +1 -4
  106. package/dist/runtime/server/routes/__qarpeo/security/clear.post.d.ts +1 -4
  107. package/dist/runtime/server/routes/__qarpeo/security/unban.post.d.ts +1 -4
  108. package/dist/runtime/server/routes/__qarpeo/settings.get.mjs +1 -1
  109. package/dist/runtime/server/routes/__qarpeo/tasks/run.post.mjs +3 -1
  110. package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +8 -2
  111. package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +8 -2
  112. package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +8 -2
  113. package/dist/runtime/server/routes/ai/embed.post.d.ts +1 -4
  114. package/dist/runtime/server/routes/ai/search.post.d.ts +2 -2
  115. package/dist/runtime/server/routes/auth/account.delete.mjs +1 -1
  116. package/dist/runtime/server/routes/auth/handler.mjs +6 -1
  117. package/dist/runtime/server/routes/auth/magic-link/verify.get.mjs +1 -1
  118. package/dist/runtime/server/routes/auth/organization/members/[id].delete.mjs +7 -1
  119. package/dist/runtime/server/routes/auth/otp/verify.post.mjs +1 -1
  120. package/dist/runtime/server/routes/auth/sso/login.get.mjs +7 -1
  121. package/dist/runtime/server/routes/auth/sso/oidc/callback.get.mjs +8 -2
  122. package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +7 -2
  123. package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +1 -1
  124. package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +7 -2
  125. package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +6 -1
  126. package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +6 -1
  127. package/dist/runtime/server/routes/browser/crawl.post.d.ts +1 -2
  128. package/dist/runtime/server/routes/browser/invoice.post.d.ts +1 -2
  129. package/dist/runtime/server/routes/browser/og-image.post.d.ts +2 -2
  130. package/dist/runtime/server/routes/browser/pdf.post.d.ts +1 -2
  131. package/dist/runtime/server/routes/browser/pdf.post.mjs +6 -1
  132. package/dist/runtime/server/routes/browser/screenshot.post.d.ts +2 -2
  133. package/dist/runtime/server/routes/browser/screenshot.post.mjs +5 -1
  134. package/dist/runtime/server/routes/cms/components/index.get.d.ts +2 -2
  135. package/dist/runtime/server/routes/cms/preview/disable.get.d.ts +4 -3
  136. package/dist/runtime/server/routes/cms/preview/enable.get.d.ts +8 -8
  137. package/dist/runtime/server/routes/cms/search.get.mjs +1 -1
  138. package/dist/runtime/server/routes/cms/webhooks/[provider].post.d.ts +7 -7
  139. package/dist/runtime/server/routes/cms/webhooks/[provider].post.mjs +9 -2
  140. package/dist/runtime/server/routes/docs/search.get.d.ts +9 -9
  141. package/dist/runtime/server/routes/fate.mjs +5 -8
  142. package/dist/runtime/server/routes/mail/bounce.post.d.ts +2 -2
  143. package/dist/runtime/server/routes/mail/unsubscribe.d.ts +2 -2
  144. package/dist/runtime/server/routes/mail/webhooks.post.d.ts +2 -2
  145. package/dist/runtime/server/routes/mail/webhooks.post.mjs +7 -1
  146. package/dist/runtime/server/routes/payments/usage.get.d.ts +8 -8
  147. package/dist/runtime/server/routes/payments/usage.post.d.ts +2 -2
  148. package/dist/runtime/server/routes/realtime/history.delete.d.ts +4 -3
  149. package/dist/runtime/server/routes/realtime/history.get.d.ts +7 -6
  150. package/dist/runtime/server/routes/realtime/ws.get.mjs +6 -1
  151. package/dist/runtime/server/routes/robots.txt.get.mjs +1 -1
  152. package/dist/runtime/server/routes/sitemap.xml.get.mjs +2 -1
  153. package/dist/runtime/server/routes/storage/multipart/abort.post.d.ts +2 -2
  154. package/dist/runtime/server/routes/storage/multipart/complete.post.d.ts +2 -2
  155. package/dist/runtime/server/routes/storage/multipart/complete.post.mjs +2 -2
  156. package/dist/runtime/server/routes/storage/multipart/create.post.d.ts +2 -2
  157. package/dist/runtime/server/routes/storage/multipart/create.post.mjs +7 -3
  158. package/dist/runtime/server/routes/storage/multipart/part.put.d.ts +2 -2
  159. package/dist/runtime/server/routes/storage/multipart/part.put.mjs +1 -1
  160. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +2 -4
  161. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +2 -4
  162. package/dist/runtime/server/routes/tenants/[tenant]/domains/index.get.mjs +1 -1
  163. package/dist/runtime/server/routes/tenants/[tenant]/domains/index.post.mjs +2 -4
  164. package/dist/runtime/server/tasks/cms/publish.mjs +1 -1
  165. package/dist/runtime/server/utils/ai.d.ts +9 -9
  166. package/dist/runtime/server/utils/ai.mjs +3 -3
  167. package/dist/runtime/server/utils/auth.d.ts +12 -16
  168. package/dist/runtime/server/utils/auth.mjs +15 -9
  169. package/dist/runtime/server/utils/bots.mjs +21 -7
  170. package/dist/runtime/server/utils/browser-utils.d.ts +44 -41
  171. package/dist/runtime/server/utils/browser-utils.mjs +14 -4
  172. package/dist/runtime/server/utils/cache.d.ts +5 -5
  173. package/dist/runtime/server/utils/cms/common.d.ts +26 -0
  174. package/dist/runtime/server/utils/cms/common.mjs +68 -0
  175. package/dist/runtime/server/utils/cms/git.d.ts +24 -0
  176. package/dist/runtime/server/utils/cms/git.mjs +240 -0
  177. package/dist/runtime/server/utils/cms/markdown.d.ts +22 -0
  178. package/dist/runtime/server/utils/cms/markdown.mjs +92 -0
  179. package/dist/runtime/server/utils/cms/path.d.ts +51 -0
  180. package/dist/runtime/server/utils/cms/path.mjs +127 -0
  181. package/dist/runtime/server/utils/cms/search.d.ts +22 -0
  182. package/dist/runtime/server/utils/cms/search.mjs +221 -0
  183. package/dist/runtime/server/utils/cms-events.d.ts +1 -1
  184. package/dist/runtime/server/utils/cms-events.mjs +2 -2
  185. package/dist/runtime/server/utils/cms-filter.mjs +2 -2
  186. package/dist/runtime/server/utils/cms.d.ts +17 -149
  187. package/dist/runtime/server/utils/cms.mjs +52 -761
  188. package/dist/runtime/server/utils/config.d.ts +5 -4
  189. package/dist/runtime/server/utils/domains.mjs +7 -4
  190. package/dist/runtime/server/utils/email-templates.d.ts +10 -7
  191. package/dist/runtime/server/utils/email-templates.mjs +20 -5
  192. package/dist/runtime/server/utils/feed.d.ts +2 -2
  193. package/dist/runtime/server/utils/feed.mjs +3 -1
  194. package/dist/runtime/server/utils/mail-suppression.d.ts +8 -24
  195. package/dist/runtime/server/utils/mail-suppression.mjs +2 -2
  196. package/dist/runtime/server/utils/mail.d.ts +7 -8
  197. package/dist/runtime/server/utils/mail.mjs +17 -12
  198. package/dist/runtime/server/utils/multipart-store.d.ts +2 -2
  199. package/dist/runtime/server/utils/notifications.d.ts +9 -23
  200. package/dist/runtime/server/utils/organization.mjs +4 -12
  201. package/dist/runtime/server/utils/passwordless.mjs +1 -1
  202. package/dist/runtime/server/utils/payments.d.ts +2 -6
  203. package/dist/runtime/server/utils/payments.mjs +1 -1
  204. package/dist/runtime/server/utils/queue.d.ts +21 -31
  205. package/dist/runtime/server/utils/rag.d.ts +4 -4
  206. package/dist/runtime/server/utils/rag.mjs +8 -8
  207. package/dist/runtime/server/utils/realtime-store.d.ts +2 -2
  208. package/dist/runtime/server/utils/realtime.d.ts +26 -28
  209. package/dist/runtime/server/utils/scheduled-task.d.ts +1 -3
  210. package/dist/runtime/server/utils/security-store.d.ts +2 -2
  211. package/dist/runtime/server/utils/session.d.ts +9 -11
  212. package/dist/runtime/server/utils/sso.d.ts +9 -15
  213. package/dist/runtime/server/utils/sso.mjs +4 -8
  214. package/dist/runtime/server/utils/storage.d.ts +19 -2
  215. package/dist/runtime/server/utils/storage.mjs +36 -7
  216. package/dist/runtime/server/utils/tenant.mjs +3 -1
  217. package/dist/runtime/server/utils/turnstile.d.ts +3 -5
  218. package/dist/runtime/server/utils/vapid.d.ts +5 -8
  219. package/dist/runtime/server/utils/vapid.mjs +26 -13
  220. package/dist/runtime/service.d.ts +13 -13
  221. package/dist/runtime/service.mjs +4 -2
  222. package/dist/runtime/test-utils.d.ts +20 -30
  223. package/dist/runtime/test-utils.mjs +5 -4
  224. package/dist/runtime/types/auth-globals.d.ts +14 -14
  225. package/dist/runtime/types/imports.d.ts +82 -82
  226. package/dist/runtime/types/index.d.ts +2 -2
  227. package/dist/runtime/types/r2.d.ts +5 -0
  228. package/dist/runtime/types/service.d.ts +11 -18
  229. package/dist/types.d.ts +100 -107
  230. package/dist/utils/auth-schema.d.ts +2 -2
  231. package/dist/utils/cms-sources.d.ts +3 -3
  232. package/dist/utils/local-db.d.ts +3 -3
  233. package/dist/utils/notifications-schema.d.ts +1 -3
  234. package/dist/utils/pkg.d.ts +7 -0
  235. package/dist/utils/queue.d.ts +3 -3
  236. package/dist/utils/tasks.d.ts +3 -2
  237. package/package.json +11 -8
@@ -1,616 +1,616 @@
1
- <script setup lang="ts">
2
- import { computed, onMounted, ref, watch } from "vue"
3
-
4
- type AnalyticsRange = "24h" | "7d" | "30d" | "90d"
5
-
6
- const analyticsRange = ref<AnalyticsRange>("7d")
7
- const analyticsLoading = ref(false)
8
- const initialLoading = ref(true)
9
- const summaryData = ref<any>(null)
10
- const customEvents = ref<any[]>([])
11
- const activeTab = ref<"overview" | "events">("overview")
12
- const sendingEvent = ref(false)
13
-
14
- const fallbackData = {
15
- totalPageviews: 18450,
16
- uniqueVisitors: 4120,
17
- totalEvents: 1240,
18
- avgDurationMs: 3.2,
19
- topPages: [
20
- { path: "/", views: 6840 },
21
- { path: "/docs", views: 4210 },
22
- { path: "/blog/edge-computing", views: 2890 },
23
- { path: "/pricing", views: 1640 },
24
- { path: "/about", views: 980 },
25
- { path: "/login", views: 890 },
26
- ],
27
- topReferrers: [
28
- { referrer: "Direct / Organic", count: 8200 },
29
- { referrer: "github.com", count: 4100 },
30
- { referrer: "google.com", count: 3200 },
31
- { referrer: "x.com", count: 1850 },
32
- { referrer: "news.ycombinator.com", count: 1100 },
33
- ],
34
- countries: [
35
- { country: "United States", code: "US", count: 7200 },
36
- { country: "Germany", code: "DE", count: 2850 },
37
- { country: "United Kingdom", code: "GB", count: 2420 },
38
- { country: "Japan", code: "JP", count: 1810 },
39
- { country: "France", code: "FR", count: 1240 },
40
- { country: "Canada", code: "CA", count: 980 },
41
- ],
42
- devices: [
43
- { name: "Desktop (Mac / Windows / Linux)", count: 11400, percent: 62 },
44
- { name: "Mobile (iOS / Android)", count: 5600, percent: 30 },
45
- { name: "Tablet (iPad / Android Tablet)", count: 1450, percent: 8 },
46
- ],
47
- }
48
-
49
- const fallbackEvents = [
50
- {
51
- name: "auth_passkey_register",
52
- count: 240,
53
- lastSeen: new Date(Date.now() - 1000 * 60 * 5).toISOString(),
54
- sampleMetadata: { method: "webauthn", authenticator: "platform" },
55
- },
56
- {
57
- name: "kv_cache_purge",
58
- count: 512,
59
- lastSeen: new Date(Date.now() - 1000 * 60 * 18).toISOString(),
60
- sampleMetadata: { tags: ["cms", "blog"] },
61
- },
62
- {
63
- name: "cms_entry_publish",
64
- count: 88,
65
- lastSeen: new Date(Date.now() - 1000 * 60 * 42).toISOString(),
66
- sampleMetadata: { collection: "posts", id: "edge-performance" },
67
- },
68
- {
69
- name: "agent_chat_query",
70
- count: 380,
71
- lastSeen: new Date(Date.now() - 1000 * 60 * 75).toISOString(),
72
- sampleMetadata: { agent: "agent_chat", stream: true },
73
- },
74
- ]
75
-
76
- const isPreviewMode = ref(false)
77
-
78
- async function loadAnalytics() {
79
- analyticsLoading.value = true
80
- try {
81
- const [summaryRes, eventsRes] = await Promise.all([
82
- $fetch<any>("/_qarpeo/api/analytics/summary", {
83
- query: { range: analyticsRange.value },
84
- }).catch(() => null),
85
- $fetch<any>("/_qarpeo/api/analytics/events", {
86
- query: { range: analyticsRange.value },
87
- }).catch(() => null),
88
- ])
89
-
90
- if (summaryRes && summaryRes.totalPageviews !== undefined) {
91
- summaryData.value = summaryRes
92
- isPreviewMode.value = Boolean(summaryRes.preview)
93
- } else {
94
- summaryData.value = fallbackData
95
- isPreviewMode.value = true
96
- }
97
-
98
- if (eventsRes && Array.isArray(eventsRes.events)) {
99
- customEvents.value = eventsRes.events
100
- } else {
101
- customEvents.value = fallbackEvents
102
- }
103
- } finally {
104
- analyticsLoading.value = false
105
- initialLoading.value = false
106
- }
107
- }
108
-
109
- const maxPageViews = computed(() => {
110
- const pages = summaryData.value?.topPages || []
111
- return pages.length > 0 ? Math.max(...pages.map((p: any) => p.views)) : 1
112
- })
113
-
114
- const maxReferrers = computed(() => {
115
- const refs = summaryData.value?.topReferrers || []
116
- return refs.length > 0 ? Math.max(...refs.map((r: any) => r.count)) : 1
117
- })
118
-
119
- const maxCountries = computed(() => {
120
- const list = summaryData.value?.countries || []
121
- return list.length > 0 ? Math.max(...list.map((c: any) => c.count)) : 1
122
- })
123
-
124
- function fmtDate(iso?: string) {
125
- if (!iso) return "—"
126
- return new Date(iso).toLocaleTimeString([], {
127
- hour: "2-digit",
128
- minute: "2-digit",
129
- })
130
- }
131
-
132
- async function emitTestEvent() {
133
- sendingEvent.value = true
134
- try {
135
- const eventNames = ["user_signup", "checkout_completed", "export_downloaded", "agent_invoked"]
136
- const chosen = eventNames[Math.floor(Math.random() * eventNames.length)]
137
-
138
- // Send real event to API
139
- await $fetch("/api/analytics/events", {
140
- method: "POST",
141
- body: {
142
- event: chosen,
143
- metadata: { source: "devtools_simulator", site: "playground" },
144
- },
145
- }).catch(() => {})
146
-
147
- const existing = customEvents.value.find((e) => e.name === chosen)
148
- if (existing) {
149
- existing.count++
150
- existing.lastSeen = new Date().toISOString()
151
- } else {
152
- customEvents.value.unshift({
153
- name: chosen,
154
- count: 1,
155
- lastSeen: new Date().toISOString(),
156
- sampleMetadata: { source: "devtools_simulator", site: "playground" },
157
- })
158
- }
159
- } finally {
160
- sendingEvent.value = false
161
- }
162
- }
163
-
164
- watch(analyticsRange, () => {
165
- loadAnalytics()
166
- })
167
-
168
- onMounted(() => {
169
- loadAnalytics()
170
- })
171
- </script>
172
-
173
- <template>
174
- <UDashboardPanel id="devtools-analytics">
175
- <template #header>
176
- <UDashboardNavbar>
177
- <template #title>
178
- <div class="flex items-center gap-2">
179
- <UIcon name="i-lucide-bar-chart-3" class="w-4 h-4 text-primary" />
180
- <span class="font-bold text-sm text-highlighted">Edge Analytics</span>
181
- <UBadge size="xs" color="primary" variant="subtle">Zero-Cookie</UBadge>
182
- <UBadge size="xs" color="neutral" variant="subtle">Cloudflare AE</UBadge>
183
- <UBadge
184
- v-if="isPreviewMode"
185
- size="xs"
186
- color="warning"
187
- variant="subtle"
188
- icon="i-lucide-flask-conical"
189
- >Preview Data</UBadge
190
- >
191
- </div>
192
- </template>
193
-
194
- <template #right>
195
- <div class="flex items-center gap-2">
196
- <UButton
197
- icon="i-lucide-plus"
198
- label="Simulate Event"
199
- size="xs"
200
- color="neutral"
201
- variant="subtle"
202
- :loading="sendingEvent"
203
- @click="emitTestEvent"
204
- />
205
- <UButton
206
- icon="i-lucide-refresh-cw"
207
- size="xs"
208
- color="neutral"
209
- variant="ghost"
210
- title="Refresh metrics"
211
- :loading="analyticsLoading"
212
- @click="loadAnalytics"
213
- />
214
- </div>
215
- </template>
216
- </UDashboardNavbar>
217
-
218
- <!-- Time Range & View Mode Toolbar -->
219
- <UDashboardToolbar>
220
- <div class="flex items-center justify-between w-full flex-wrap gap-2">
221
- <!-- Time Range Segmented Control -->
222
- <div class="flex items-center gap-1 bg-muted p-0.5 rounded border border-default">
223
- <UButton
224
- v-for="r in ['24h', '7d', '30d', '90d'] as const"
225
- :key="r"
226
- :label="r.toUpperCase()"
227
- size="xs"
228
- :color="analyticsRange === r ? 'primary' : 'neutral'"
229
- :variant="analyticsRange === r ? 'subtle' : 'ghost'"
230
- @click="analyticsRange = r"
231
- />
232
- </div>
233
-
234
- <!-- View Mode Tabs -->
235
- <div class="flex items-center gap-1 bg-muted p-0.5 rounded border border-default">
236
- <UButton
237
- label="Overview"
238
- icon="i-lucide-layout-grid"
239
- size="xs"
240
- :color="activeTab === 'overview' ? 'primary' : 'neutral'"
241
- :variant="activeTab === 'overview' ? 'subtle' : 'ghost'"
242
- @click="activeTab = 'overview'"
243
- />
244
- <UButton
245
- label="Custom Events"
246
- icon="i-lucide-activity"
247
- size="xs"
248
- :color="activeTab === 'events' ? 'primary' : 'neutral'"
249
- :variant="activeTab === 'events' ? 'subtle' : 'ghost'"
250
- @click="activeTab = 'events'"
251
- >
252
- <template #trailing>
253
- <UBadge size="xs" color="neutral" variant="subtle">
254
- {{ customEvents.length }}
255
- </UBadge>
256
- </template>
257
- </UButton>
258
- </div>
259
- </div>
260
- </UDashboardToolbar>
261
- </template>
262
-
263
- <template #body>
264
- <!-- ── TAB 1: OVERVIEW METRICS ──────────────────────────────────── -->
265
- <template v-if="activeTab === 'overview'">
266
- <!-- Skeleton: Top Summary Cards -->
267
- <div v-if="initialLoading" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
268
- <UCard v-for="i in 4" :key="`kpi-skel-${i}`">
269
- <div class="h-3 w-24 rounded bg-muted animate-pulse mb-2"></div>
270
- <div class="h-7 w-32 rounded bg-muted animate-pulse mb-2"></div>
271
- <div class="h-2 w-28 rounded bg-muted animate-pulse"></div>
272
- </UCard>
273
- </div>
274
-
275
- <!-- KPI Top Summary Cards -->
276
- <div v-else class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
277
- <UCard>
278
- <div class="flex items-center justify-between text-xs text-muted mb-1">
279
- <span>Total Pageviews</span>
280
- <UIcon name="i-lucide-eye" class="w-4 h-4 text-primary" />
281
- </div>
282
- <div class="text-2xl font-extrabold text-highlighted">
283
- {{
284
- (
285
- summaryData?.totalPageviews ||
286
- summaryData?.summary?.totalPageviews ||
287
- 0
288
- ).toLocaleString()
289
- }}
290
- </div>
291
- <div class="text-[11px] text-muted mt-1">Zero-cookie edge counts</div>
292
- </UCard>
293
-
294
- <UCard>
295
- <div class="flex items-center justify-between text-xs text-muted mb-1">
296
- <span>Unique Visitors</span>
297
- <UIcon name="i-lucide-users" class="w-4 h-4 text-primary" />
298
- </div>
299
- <div class="text-2xl font-extrabold text-primary">
300
- {{
301
- (
302
- summaryData?.uniqueVisitors ||
303
- summaryData?.summary?.uniqueVisitors ||
304
- 0
305
- ).toLocaleString()
306
- }}
307
- </div>
308
- <div class="text-[11px] text-muted mt-1">Daily rotated anonymous hash</div>
309
- </UCard>
310
-
311
- <UCard>
312
- <div class="flex items-center justify-between text-xs text-muted mb-1">
313
- <span>Custom Events</span>
314
- <UIcon name="i-lucide-zap" class="w-4 h-4 text-success" />
315
- </div>
316
- <div class="text-2xl font-extrabold text-success">
317
- {{
318
- (
319
- summaryData?.totalEvents ||
320
- summaryData?.summary?.totalEvents ||
321
- 0
322
- ).toLocaleString()
323
- }}
324
- </div>
325
- <div class="text-[11px] text-muted mt-1">Conversions & actions</div>
326
- </UCard>
327
-
328
- <UCard>
329
- <div class="flex items-center justify-between text-xs text-muted mb-1">
330
- <span>Average Response</span>
331
- <UIcon name="i-lucide-gauge" class="w-4 h-4 text-warning" />
332
- </div>
333
- <div class="text-2xl font-extrabold text-highlighted">
334
- {{ summaryData?.avgDurationMs ?? 3.4 }} ms
335
- </div>
336
- <div class="text-[11px] text-muted mt-1">Cloudflare Edge compute</div>
337
- </UCard>
338
- </div>
339
-
340
- <!-- Skeleton: Distribution Breakdown Grid -->
341
- <div v-if="initialLoading" class="grid grid-cols-1 lg:grid-cols-2 gap-6">
342
- <UCard v-for="c in 4" :key="`dist-skel-${c}`">
343
- <template #header>
344
- <div class="h-4 w-32 rounded bg-muted animate-pulse"></div>
345
- </template>
346
- <div class="space-y-4">
347
- <div v-for="r in 4" :key="r" class="space-y-1.5">
348
- <div class="flex justify-between">
349
- <div class="h-3 w-36 rounded bg-muted animate-pulse"></div>
350
- <div class="h-3 w-16 rounded bg-muted animate-pulse"></div>
351
- </div>
352
- <div class="h-2 w-full rounded bg-muted animate-pulse"></div>
353
- </div>
354
- </div>
355
- </UCard>
356
- </div>
357
-
358
- <!-- Distribution Breakdown Grid -->
359
- <div v-else class="grid grid-cols-1 lg:grid-cols-2 gap-6">
360
- <!-- Top Paths with Percentage Meters -->
361
- <UCard>
362
- <template #header>
363
- <div class="flex items-center justify-between">
364
- <span class="font-bold text-sm text-highlighted flex items-center gap-2">
365
- <UIcon name="i-lucide-file-text" class="w-4 h-4 text-primary" />
366
- Top Visited Paths
367
- </span>
368
- <span class="text-xs text-muted font-mono"
369
- >{{ (summaryData?.topPages || []).length }} paths</span
370
- >
371
- </div>
372
- </template>
373
-
374
- <div class="space-y-3">
375
- <div
376
- v-for="item in summaryData?.topPages || []"
377
- :key="item.path"
378
- class="space-y-1 text-xs"
379
- >
380
- <div class="flex items-center justify-between font-mono">
381
- <span class="text-default font-semibold truncate">{{ item.path }}</span>
382
- <span class="text-muted shrink-0 ml-2"
383
- >{{ item.views.toLocaleString() }} views</span
384
- >
385
- </div>
386
- <!-- Progress Bar -->
387
- <div class="w-full bg-muted/40 h-1.5 rounded-full overflow-hidden">
388
- <div
389
- class="bg-primary h-full rounded-full transition-all duration-500"
390
- :style="{
391
- width: `${Math.round((item.views / maxPageViews) * 100)}%`,
392
- }"
393
- ></div>
394
- </div>
395
- </div>
396
- </div>
397
- </UCard>
398
-
399
- <!-- Top Referrers with Percentage Meters -->
400
- <UCard>
401
- <template #header>
402
- <div class="flex items-center justify-between">
403
- <span class="font-bold text-sm text-highlighted flex items-center gap-2">
404
- <UIcon name="i-lucide-compass" class="w-4 h-4 text-primary" />
405
- Top Referrers
406
- </span>
407
- <span class="text-xs text-muted font-mono"
408
- >{{ (summaryData?.topReferrers || []).length }} sources</span
409
- >
410
- </div>
411
- </template>
412
-
413
- <div class="space-y-3">
414
- <div
415
- v-for="item in summaryData?.topReferrers || []"
416
- :key="item.referrer"
417
- class="space-y-1 text-xs"
418
- >
419
- <div class="flex items-center justify-between">
420
- <span class="text-default font-semibold truncate">{{ item.referrer }}</span>
421
- <span class="text-muted shrink-0 font-mono ml-2"
422
- >{{ item.count.toLocaleString() }} visits</span
423
- >
424
- </div>
425
- <!-- Progress Bar -->
426
- <div class="w-full bg-muted/40 h-1.5 rounded-full overflow-hidden">
427
- <div
428
- class="bg-info h-full rounded-full transition-all duration-500"
429
- :style="{
430
- width: `${Math.round((item.count / maxReferrers) * 100)}%`,
431
- }"
432
- ></div>
433
- </div>
434
- </div>
435
- </div>
436
- </UCard>
437
-
438
- <!-- Top Countries -->
439
- <UCard>
440
- <template #header>
441
- <div class="flex items-center justify-between">
442
- <span class="font-bold text-sm text-highlighted flex items-center gap-2">
443
- <UIcon name="i-lucide-globe" class="w-4 h-4 text-primary" />
444
- Top Countries
445
- </span>
446
- <span class="text-xs text-muted font-mono"
447
- >{{ (summaryData?.countries || []).length }} countries</span
448
- >
449
- </div>
450
- </template>
451
-
452
- <div class="space-y-3">
453
- <div
454
- v-for="c in summaryData?.countries || []"
455
- :key="c.country"
456
- class="space-y-1 text-xs"
457
- >
458
- <div class="flex items-center justify-between">
459
- <span class="flex items-center gap-1.5 text-default font-semibold">
460
- <UBadge size="xs" color="neutral" variant="subtle">{{ c.code || "—" }}</UBadge>
461
- {{ c.country }}
462
- </span>
463
- <span class="text-muted font-mono">{{ c.count.toLocaleString() }} visitors</span>
464
- </div>
465
- <div class="w-full bg-muted/40 h-1.5 rounded-full overflow-hidden">
466
- <div
467
- class="bg-success h-full rounded-full transition-all duration-500"
468
- :style="{
469
- width: `${Math.round((c.count / maxCountries) * 100)}%`,
470
- }"
471
- ></div>
472
- </div>
473
- </div>
474
- </div>
475
- </UCard>
476
-
477
- <!-- Devices Distribution -->
478
- <UCard>
479
- <template #header>
480
- <div class="flex items-center justify-between">
481
- <span class="font-bold text-sm text-highlighted flex items-center gap-2">
482
- <UIcon name="i-lucide-monitor" class="w-4 h-4 text-primary" />
483
- Device Distribution
484
- </span>
485
- </div>
486
- </template>
487
-
488
- <div class="space-y-4">
489
- <div
490
- v-for="d in summaryData?.devices || []"
491
- :key="d.name"
492
- class="space-y-1.5 text-xs"
493
- >
494
- <div class="flex items-center justify-between">
495
- <span class="text-default font-semibold">{{ d.name }}</span>
496
- <span class="text-muted font-mono"
497
- >{{ d.count.toLocaleString() }} ({{
498
- d.percent ?? Math.round((d.count / (summaryData?.totalPageviews || 1)) * 100)
499
- }}%)</span
500
- >
501
- </div>
502
- <div class="w-full bg-muted/40 h-2 rounded-full overflow-hidden">
503
- <div
504
- class="bg-primary h-full rounded-full transition-all duration-500"
505
- :style="{
506
- width: `${
507
- d.percent ??
508
- Math.round((d.count / (summaryData?.totalPageviews || 1)) * 100)
509
- }%`,
510
- }"
511
- ></div>
512
- </div>
513
- </div>
514
- </div>
515
- </UCard>
516
- </div>
517
- </template>
518
-
519
- <!-- ── TAB 2: CUSTOM EVENTS ────────────────────────────────────── -->
520
- <template v-else>
521
- <UCard :ui="{ body: 'p-0 overflow-hidden' }">
522
- <template #header>
523
- <div class="flex items-center justify-between">
524
- <div>
525
- <h3 class="font-bold text-sm text-highlighted flex items-center gap-2">
526
- <UIcon name="i-lucide-activity" class="w-4 h-4 text-primary" />
527
- Custom Edge Events
528
- </h3>
529
- <p class="text-xs text-muted mt-0.5">
530
- Tracked via
531
- <code class="font-mono text-primary"
532
- >qarpeo.analytics.track("event_name", { ... })</code
533
- >
534
- </p>
535
- </div>
536
- <UButton
537
- label="Simulate New Event"
538
- icon="i-lucide-plus"
539
- size="xs"
540
- color="primary"
541
- :loading="sendingEvent"
542
- @click="emitTestEvent"
543
- />
544
- </div>
545
- </template>
546
-
547
- <div class="overflow-x-auto">
548
- <table class="w-full text-left text-xs">
549
- <thead>
550
- <tr class="border-b border-default bg-muted/40 text-muted font-mono">
551
- <th class="py-2.5 px-4 font-semibold">Event Name</th>
552
- <th class="py-2.5 px-4 font-semibold">Occurrences</th>
553
- <th class="py-2.5 px-4 font-semibold">Last Recorded</th>
554
- <th class="py-2.5 px-4 font-semibold">Sample Payload</th>
555
- </tr>
556
- </thead>
557
- <tbody class="divide-y divide-default font-mono">
558
- <!-- Skeleton rows during loading -->
559
- <tr
560
- v-if="initialLoading"
561
- v-for="i in 5"
562
- :key="`ev-skel-${i}`"
563
- class="animate-pulse"
564
- >
565
- <td class="py-3 px-4">
566
- <div class="h-3.5 w-36 rounded bg-muted"></div>
567
- </td>
568
- <td class="py-3 px-4">
569
- <div class="h-4 w-10 rounded bg-muted"></div>
570
- </td>
571
- <td class="py-3 px-4">
572
- <div class="h-3.5 w-20 rounded bg-muted"></div>
573
- </td>
574
- <td class="py-3 px-4">
575
- <div class="h-4 w-48 rounded bg-muted"></div>
576
- </td>
577
- </tr>
578
-
579
- <template v-else>
580
- <tr
581
- v-for="ev in customEvents"
582
- :key="ev.name"
583
- class="hover:bg-elevated/50 transition-colors"
584
- >
585
- <td class="py-3 px-4 font-bold text-primary">
586
- {{ ev.name }}
587
- </td>
588
- <td class="py-3 px-4 text-default">
589
- <UBadge size="xs" color="neutral" variant="subtle">
590
- {{ ev.count?.toLocaleString() || 1 }}
591
- </UBadge>
592
- </td>
593
- <td class="py-3 px-4 text-muted">
594
- {{ fmtDate(ev.lastSeen) }}
595
- </td>
596
- <td class="py-3 px-4">
597
- <pre
598
- class="text-[10px] text-muted bg-muted/30 p-1.5 rounded inline-block max-w-sm truncate"
599
- :title="JSON.stringify(ev.sampleMetadata)"
600
- >{{ JSON.stringify(ev.sampleMetadata) }}</pre>
601
- </td>
602
- </tr>
603
- <tr v-if="!customEvents.length">
604
- <td colspan="4" class="text-center py-12 text-muted text-xs font-sans">
605
- No custom events recorded yet. Click "Simulate New Event" above.
606
- </td>
607
- </tr>
608
- </template>
609
- </tbody>
610
- </table>
611
- </div>
612
- </UCard>
613
- </template>
614
- </template>
615
- </UDashboardPanel>
616
- </template>
1
+ <script setup lang="ts">
2
+ import { computed, onMounted, ref, watch } from "vue"
3
+
4
+ type AnalyticsRange = "24h" | "7d" | "30d" | "90d"
5
+
6
+ const analyticsRange = ref<AnalyticsRange>("7d")
7
+ const analyticsLoading = ref(false)
8
+ const initialLoading = ref(true)
9
+ const summaryData = ref<any>(null)
10
+ const customEvents = ref<any[]>([])
11
+ const activeTab = ref<"overview" | "events">("overview")
12
+ const sendingEvent = ref(false)
13
+
14
+ const fallbackData = {
15
+ totalPageviews: 18450,
16
+ uniqueVisitors: 4120,
17
+ totalEvents: 1240,
18
+ avgDurationMs: 3.2,
19
+ topPages: [
20
+ { path: "/", views: 6840 },
21
+ { path: "/docs", views: 4210 },
22
+ { path: "/blog/edge-computing", views: 2890 },
23
+ { path: "/pricing", views: 1640 },
24
+ { path: "/about", views: 980 },
25
+ { path: "/login", views: 890 },
26
+ ],
27
+ topReferrers: [
28
+ { referrer: "Direct / Organic", count: 8200 },
29
+ { referrer: "github.com", count: 4100 },
30
+ { referrer: "google.com", count: 3200 },
31
+ { referrer: "x.com", count: 1850 },
32
+ { referrer: "news.ycombinator.com", count: 1100 },
33
+ ],
34
+ countries: [
35
+ { country: "United States", code: "US", count: 7200 },
36
+ { country: "Germany", code: "DE", count: 2850 },
37
+ { country: "United Kingdom", code: "GB", count: 2420 },
38
+ { country: "Japan", code: "JP", count: 1810 },
39
+ { country: "France", code: "FR", count: 1240 },
40
+ { country: "Canada", code: "CA", count: 980 },
41
+ ],
42
+ devices: [
43
+ { name: "Desktop (Mac / Windows / Linux)", count: 11400, percent: 62 },
44
+ { name: "Mobile (iOS / Android)", count: 5600, percent: 30 },
45
+ { name: "Tablet (iPad / Android Tablet)", count: 1450, percent: 8 },
46
+ ],
47
+ }
48
+
49
+ const fallbackEvents = [
50
+ {
51
+ name: "auth_passkey_register",
52
+ count: 240,
53
+ lastSeen: new Date(Date.now() - 1000 * 60 * 5).toISOString(),
54
+ sampleMetadata: { method: "webauthn", authenticator: "platform" },
55
+ },
56
+ {
57
+ name: "kv_cache_purge",
58
+ count: 512,
59
+ lastSeen: new Date(Date.now() - 1000 * 60 * 18).toISOString(),
60
+ sampleMetadata: { tags: ["cms", "blog"] },
61
+ },
62
+ {
63
+ name: "cms_entry_publish",
64
+ count: 88,
65
+ lastSeen: new Date(Date.now() - 1000 * 60 * 42).toISOString(),
66
+ sampleMetadata: { collection: "posts", id: "edge-performance" },
67
+ },
68
+ {
69
+ name: "agent_chat_query",
70
+ count: 380,
71
+ lastSeen: new Date(Date.now() - 1000 * 60 * 75).toISOString(),
72
+ sampleMetadata: { agent: "agent_chat", stream: true },
73
+ },
74
+ ]
75
+
76
+ const isPreviewMode = ref(false)
77
+
78
+ async function loadAnalytics() {
79
+ analyticsLoading.value = true
80
+ try {
81
+ const [summaryRes, eventsRes] = await Promise.all([
82
+ $fetch<any>("/_qarpeo/api/analytics/summary", {
83
+ query: { range: analyticsRange.value },
84
+ }).catch(() => null),
85
+ $fetch<any>("/_qarpeo/api/analytics/events", {
86
+ query: { range: analyticsRange.value },
87
+ }).catch(() => null),
88
+ ])
89
+
90
+ if (summaryRes && summaryRes.totalPageviews !== undefined) {
91
+ summaryData.value = summaryRes
92
+ isPreviewMode.value = Boolean(summaryRes.preview)
93
+ } else {
94
+ summaryData.value = fallbackData
95
+ isPreviewMode.value = true
96
+ }
97
+
98
+ if (eventsRes && Array.isArray(eventsRes.events)) {
99
+ customEvents.value = eventsRes.events
100
+ } else {
101
+ customEvents.value = fallbackEvents
102
+ }
103
+ } finally {
104
+ analyticsLoading.value = false
105
+ initialLoading.value = false
106
+ }
107
+ }
108
+
109
+ const maxPageViews = computed(() => {
110
+ const pages = summaryData.value?.topPages || []
111
+ return pages.length > 0 ? Math.max(...pages.map((p: any) => p.views)) : 1
112
+ })
113
+
114
+ const maxReferrers = computed(() => {
115
+ const refs = summaryData.value?.topReferrers || []
116
+ return refs.length > 0 ? Math.max(...refs.map((r: any) => r.count)) : 1
117
+ })
118
+
119
+ const maxCountries = computed(() => {
120
+ const list = summaryData.value?.countries || []
121
+ return list.length > 0 ? Math.max(...list.map((c: any) => c.count)) : 1
122
+ })
123
+
124
+ function fmtDate(iso?: string) {
125
+ if (!iso) return "—"
126
+ return new Date(iso).toLocaleTimeString([], {
127
+ hour: "2-digit",
128
+ minute: "2-digit",
129
+ })
130
+ }
131
+
132
+ async function emitTestEvent() {
133
+ sendingEvent.value = true
134
+ try {
135
+ const eventNames = ["user_signup", "checkout_completed", "export_downloaded", "agent_invoked"]
136
+ const chosen = eventNames[Math.floor(Math.random() * eventNames.length)]
137
+
138
+ // Send real event to API
139
+ await $fetch("/api/analytics/events", {
140
+ method: "POST",
141
+ body: {
142
+ event: chosen,
143
+ metadata: { source: "devtools_simulator", site: "playground" },
144
+ },
145
+ }).catch(() => {})
146
+
147
+ const existing = customEvents.value.find((e) => e.name === chosen)
148
+ if (existing) {
149
+ existing.count++
150
+ existing.lastSeen = new Date().toISOString()
151
+ } else {
152
+ customEvents.value.unshift({
153
+ name: chosen,
154
+ count: 1,
155
+ lastSeen: new Date().toISOString(),
156
+ sampleMetadata: { source: "devtools_simulator", site: "playground" },
157
+ })
158
+ }
159
+ } finally {
160
+ sendingEvent.value = false
161
+ }
162
+ }
163
+
164
+ watch(analyticsRange, () => {
165
+ loadAnalytics()
166
+ })
167
+
168
+ onMounted(() => {
169
+ loadAnalytics()
170
+ })
171
+ </script>
172
+
173
+ <template>
174
+ <UDashboardPanel id="devtools-analytics">
175
+ <template #header>
176
+ <UDashboardNavbar>
177
+ <template #title>
178
+ <div class="flex items-center gap-2">
179
+ <UIcon name="i-lucide-bar-chart-3" class="w-4 h-4 text-primary" />
180
+ <span class="font-bold text-sm text-highlighted">Edge Analytics</span>
181
+ <UBadge size="xs" color="primary" variant="subtle">Zero-Cookie</UBadge>
182
+ <UBadge size="xs" color="neutral" variant="subtle">Cloudflare AE</UBadge>
183
+ <UBadge
184
+ v-if="isPreviewMode"
185
+ size="xs"
186
+ color="warning"
187
+ variant="subtle"
188
+ icon="i-lucide-flask-conical"
189
+ >Preview Data</UBadge
190
+ >
191
+ </div>
192
+ </template>
193
+
194
+ <template #right>
195
+ <div class="flex items-center gap-2">
196
+ <UButton
197
+ icon="i-lucide-plus"
198
+ label="Simulate Event"
199
+ size="xs"
200
+ color="neutral"
201
+ variant="subtle"
202
+ :loading="sendingEvent"
203
+ @click="emitTestEvent"
204
+ />
205
+ <UButton
206
+ icon="i-lucide-refresh-cw"
207
+ size="xs"
208
+ color="neutral"
209
+ variant="ghost"
210
+ title="Refresh metrics"
211
+ :loading="analyticsLoading"
212
+ @click="loadAnalytics"
213
+ />
214
+ </div>
215
+ </template>
216
+ </UDashboardNavbar>
217
+
218
+ <!-- Time Range & View Mode Toolbar -->
219
+ <UDashboardToolbar>
220
+ <div class="flex items-center justify-between w-full flex-wrap gap-2">
221
+ <!-- Time Range Segmented Control -->
222
+ <div class="flex items-center gap-1 bg-muted p-0.5 rounded border border-default">
223
+ <UButton
224
+ v-for="r in ['24h', '7d', '30d', '90d'] as const"
225
+ :key="r"
226
+ :label="r.toUpperCase()"
227
+ size="xs"
228
+ :color="analyticsRange === r ? 'primary' : 'neutral'"
229
+ :variant="analyticsRange === r ? 'subtle' : 'ghost'"
230
+ @click="analyticsRange = r"
231
+ />
232
+ </div>
233
+
234
+ <!-- View Mode Tabs -->
235
+ <div class="flex items-center gap-1 bg-muted p-0.5 rounded border border-default">
236
+ <UButton
237
+ label="Overview"
238
+ icon="i-lucide-layout-grid"
239
+ size="xs"
240
+ :color="activeTab === 'overview' ? 'primary' : 'neutral'"
241
+ :variant="activeTab === 'overview' ? 'subtle' : 'ghost'"
242
+ @click="activeTab = 'overview'"
243
+ />
244
+ <UButton
245
+ label="Custom Events"
246
+ icon="i-lucide-activity"
247
+ size="xs"
248
+ :color="activeTab === 'events' ? 'primary' : 'neutral'"
249
+ :variant="activeTab === 'events' ? 'subtle' : 'ghost'"
250
+ @click="activeTab = 'events'"
251
+ >
252
+ <template #trailing>
253
+ <UBadge size="xs" color="neutral" variant="subtle">
254
+ {{ customEvents.length }}
255
+ </UBadge>
256
+ </template>
257
+ </UButton>
258
+ </div>
259
+ </div>
260
+ </UDashboardToolbar>
261
+ </template>
262
+
263
+ <template #body>
264
+ <!-- ── TAB 1: OVERVIEW METRICS ──────────────────────────────────── -->
265
+ <template v-if="activeTab === 'overview'">
266
+ <!-- Skeleton: Top Summary Cards -->
267
+ <div v-if="initialLoading" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
268
+ <UCard v-for="i in 4" :key="`kpi-skel-${i}`">
269
+ <div class="h-3 w-24 rounded bg-muted animate-pulse mb-2"></div>
270
+ <div class="h-7 w-32 rounded bg-muted animate-pulse mb-2"></div>
271
+ <div class="h-2 w-28 rounded bg-muted animate-pulse"></div>
272
+ </UCard>
273
+ </div>
274
+
275
+ <!-- KPI Top Summary Cards -->
276
+ <div v-else class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
277
+ <UCard>
278
+ <div class="flex items-center justify-between text-xs text-muted mb-1">
279
+ <span>Total Pageviews</span>
280
+ <UIcon name="i-lucide-eye" class="w-4 h-4 text-primary" />
281
+ </div>
282
+ <div class="text-2xl font-extrabold text-highlighted">
283
+ {{
284
+ (
285
+ summaryData?.totalPageviews ||
286
+ summaryData?.summary?.totalPageviews ||
287
+ 0
288
+ ).toLocaleString()
289
+ }}
290
+ </div>
291
+ <div class="text-[11px] text-muted mt-1">Zero-cookie edge counts</div>
292
+ </UCard>
293
+
294
+ <UCard>
295
+ <div class="flex items-center justify-between text-xs text-muted mb-1">
296
+ <span>Unique Visitors</span>
297
+ <UIcon name="i-lucide-users" class="w-4 h-4 text-primary" />
298
+ </div>
299
+ <div class="text-2xl font-extrabold text-primary">
300
+ {{
301
+ (
302
+ summaryData?.uniqueVisitors ||
303
+ summaryData?.summary?.uniqueVisitors ||
304
+ 0
305
+ ).toLocaleString()
306
+ }}
307
+ </div>
308
+ <div class="text-[11px] text-muted mt-1">Daily rotated anonymous hash</div>
309
+ </UCard>
310
+
311
+ <UCard>
312
+ <div class="flex items-center justify-between text-xs text-muted mb-1">
313
+ <span>Custom Events</span>
314
+ <UIcon name="i-lucide-zap" class="w-4 h-4 text-success" />
315
+ </div>
316
+ <div class="text-2xl font-extrabold text-success">
317
+ {{
318
+ (
319
+ summaryData?.totalEvents ||
320
+ summaryData?.summary?.totalEvents ||
321
+ 0
322
+ ).toLocaleString()
323
+ }}
324
+ </div>
325
+ <div class="text-[11px] text-muted mt-1">Conversions & actions</div>
326
+ </UCard>
327
+
328
+ <UCard>
329
+ <div class="flex items-center justify-between text-xs text-muted mb-1">
330
+ <span>Average Response</span>
331
+ <UIcon name="i-lucide-gauge" class="w-4 h-4 text-warning" />
332
+ </div>
333
+ <div class="text-2xl font-extrabold text-highlighted">
334
+ {{ summaryData?.avgDurationMs ?? 3.4 }} ms
335
+ </div>
336
+ <div class="text-[11px] text-muted mt-1">Cloudflare Edge compute</div>
337
+ </UCard>
338
+ </div>
339
+
340
+ <!-- Skeleton: Distribution Breakdown Grid -->
341
+ <div v-if="initialLoading" class="grid grid-cols-1 lg:grid-cols-2 gap-6">
342
+ <UCard v-for="c in 4" :key="`dist-skel-${c}`">
343
+ <template #header>
344
+ <div class="h-4 w-32 rounded bg-muted animate-pulse"></div>
345
+ </template>
346
+ <div class="space-y-4">
347
+ <div v-for="r in 4" :key="r" class="space-y-1.5">
348
+ <div class="flex justify-between">
349
+ <div class="h-3 w-36 rounded bg-muted animate-pulse"></div>
350
+ <div class="h-3 w-16 rounded bg-muted animate-pulse"></div>
351
+ </div>
352
+ <div class="h-2 w-full rounded bg-muted animate-pulse"></div>
353
+ </div>
354
+ </div>
355
+ </UCard>
356
+ </div>
357
+
358
+ <!-- Distribution Breakdown Grid -->
359
+ <div v-else class="grid grid-cols-1 lg:grid-cols-2 gap-6">
360
+ <!-- Top Paths with Percentage Meters -->
361
+ <UCard>
362
+ <template #header>
363
+ <div class="flex items-center justify-between">
364
+ <span class="font-bold text-sm text-highlighted flex items-center gap-2">
365
+ <UIcon name="i-lucide-file-text" class="w-4 h-4 text-primary" />
366
+ Top Visited Paths
367
+ </span>
368
+ <span class="text-xs text-muted font-mono"
369
+ >{{ (summaryData?.topPages || []).length }} paths</span
370
+ >
371
+ </div>
372
+ </template>
373
+
374
+ <div class="space-y-3">
375
+ <div
376
+ v-for="item in summaryData?.topPages || []"
377
+ :key="item.path"
378
+ class="space-y-1 text-xs"
379
+ >
380
+ <div class="flex items-center justify-between font-mono">
381
+ <span class="text-default font-semibold truncate">{{ item.path }}</span>
382
+ <span class="text-muted shrink-0 ml-2"
383
+ >{{ item.views.toLocaleString() }} views</span
384
+ >
385
+ </div>
386
+ <!-- Progress Bar -->
387
+ <div class="w-full bg-muted/40 h-1.5 rounded-full overflow-hidden">
388
+ <div
389
+ class="bg-primary h-full rounded-full transition-all duration-500"
390
+ :style="{
391
+ width: `${Math.round((item.views / maxPageViews) * 100)}%`,
392
+ }"
393
+ ></div>
394
+ </div>
395
+ </div>
396
+ </div>
397
+ </UCard>
398
+
399
+ <!-- Top Referrers with Percentage Meters -->
400
+ <UCard>
401
+ <template #header>
402
+ <div class="flex items-center justify-between">
403
+ <span class="font-bold text-sm text-highlighted flex items-center gap-2">
404
+ <UIcon name="i-lucide-compass" class="w-4 h-4 text-primary" />
405
+ Top Referrers
406
+ </span>
407
+ <span class="text-xs text-muted font-mono"
408
+ >{{ (summaryData?.topReferrers || []).length }} sources</span
409
+ >
410
+ </div>
411
+ </template>
412
+
413
+ <div class="space-y-3">
414
+ <div
415
+ v-for="item in summaryData?.topReferrers || []"
416
+ :key="item.referrer"
417
+ class="space-y-1 text-xs"
418
+ >
419
+ <div class="flex items-center justify-between">
420
+ <span class="text-default font-semibold truncate">{{ item.referrer }}</span>
421
+ <span class="text-muted shrink-0 font-mono ml-2"
422
+ >{{ item.count.toLocaleString() }} visits</span
423
+ >
424
+ </div>
425
+ <!-- Progress Bar -->
426
+ <div class="w-full bg-muted/40 h-1.5 rounded-full overflow-hidden">
427
+ <div
428
+ class="bg-info h-full rounded-full transition-all duration-500"
429
+ :style="{
430
+ width: `${Math.round((item.count / maxReferrers) * 100)}%`,
431
+ }"
432
+ ></div>
433
+ </div>
434
+ </div>
435
+ </div>
436
+ </UCard>
437
+
438
+ <!-- Top Countries -->
439
+ <UCard>
440
+ <template #header>
441
+ <div class="flex items-center justify-between">
442
+ <span class="font-bold text-sm text-highlighted flex items-center gap-2">
443
+ <UIcon name="i-lucide-globe" class="w-4 h-4 text-primary" />
444
+ Top Countries
445
+ </span>
446
+ <span class="text-xs text-muted font-mono"
447
+ >{{ (summaryData?.countries || []).length }} countries</span
448
+ >
449
+ </div>
450
+ </template>
451
+
452
+ <div class="space-y-3">
453
+ <div
454
+ v-for="c in summaryData?.countries || []"
455
+ :key="c.country"
456
+ class="space-y-1 text-xs"
457
+ >
458
+ <div class="flex items-center justify-between">
459
+ <span class="flex items-center gap-1.5 text-default font-semibold">
460
+ <UBadge size="xs" color="neutral" variant="subtle">{{ c.code || "—" }}</UBadge>
461
+ {{ c.country }}
462
+ </span>
463
+ <span class="text-muted font-mono">{{ c.count.toLocaleString() }} visitors</span>
464
+ </div>
465
+ <div class="w-full bg-muted/40 h-1.5 rounded-full overflow-hidden">
466
+ <div
467
+ class="bg-success h-full rounded-full transition-all duration-500"
468
+ :style="{
469
+ width: `${Math.round((c.count / maxCountries) * 100)}%`,
470
+ }"
471
+ ></div>
472
+ </div>
473
+ </div>
474
+ </div>
475
+ </UCard>
476
+
477
+ <!-- Devices Distribution -->
478
+ <UCard>
479
+ <template #header>
480
+ <div class="flex items-center justify-between">
481
+ <span class="font-bold text-sm text-highlighted flex items-center gap-2">
482
+ <UIcon name="i-lucide-monitor" class="w-4 h-4 text-primary" />
483
+ Device Distribution
484
+ </span>
485
+ </div>
486
+ </template>
487
+
488
+ <div class="space-y-4">
489
+ <div
490
+ v-for="d in summaryData?.devices || []"
491
+ :key="d.name"
492
+ class="space-y-1.5 text-xs"
493
+ >
494
+ <div class="flex items-center justify-between">
495
+ <span class="text-default font-semibold">{{ d.name }}</span>
496
+ <span class="text-muted font-mono"
497
+ >{{ d.count.toLocaleString() }} ({{
498
+ d.percent ?? Math.round((d.count / (summaryData?.totalPageviews || 1)) * 100)
499
+ }}%)</span
500
+ >
501
+ </div>
502
+ <div class="w-full bg-muted/40 h-2 rounded-full overflow-hidden">
503
+ <div
504
+ class="bg-primary h-full rounded-full transition-all duration-500"
505
+ :style="{
506
+ width: `${
507
+ d.percent ??
508
+ Math.round((d.count / (summaryData?.totalPageviews || 1)) * 100)
509
+ }%`,
510
+ }"
511
+ ></div>
512
+ </div>
513
+ </div>
514
+ </div>
515
+ </UCard>
516
+ </div>
517
+ </template>
518
+
519
+ <!-- ── TAB 2: CUSTOM EVENTS ────────────────────────────────────── -->
520
+ <template v-else>
521
+ <UCard :ui="{ body: 'p-0 overflow-hidden' }">
522
+ <template #header>
523
+ <div class="flex items-center justify-between">
524
+ <div>
525
+ <h3 class="font-bold text-sm text-highlighted flex items-center gap-2">
526
+ <UIcon name="i-lucide-activity" class="w-4 h-4 text-primary" />
527
+ Custom Edge Events
528
+ </h3>
529
+ <p class="text-xs text-muted mt-0.5">
530
+ Tracked via
531
+ <code class="font-mono text-primary"
532
+ >qarpeo.analytics.track("event_name", { ... })</code
533
+ >
534
+ </p>
535
+ </div>
536
+ <UButton
537
+ label="Simulate New Event"
538
+ icon="i-lucide-plus"
539
+ size="xs"
540
+ color="primary"
541
+ :loading="sendingEvent"
542
+ @click="emitTestEvent"
543
+ />
544
+ </div>
545
+ </template>
546
+
547
+ <div class="overflow-x-auto">
548
+ <table class="w-full text-left text-xs">
549
+ <thead>
550
+ <tr class="border-b border-default bg-muted/40 text-muted font-mono">
551
+ <th class="py-2.5 px-4 font-semibold">Event Name</th>
552
+ <th class="py-2.5 px-4 font-semibold">Occurrences</th>
553
+ <th class="py-2.5 px-4 font-semibold">Last Recorded</th>
554
+ <th class="py-2.5 px-4 font-semibold">Sample Payload</th>
555
+ </tr>
556
+ </thead>
557
+ <tbody class="divide-y divide-default font-mono">
558
+ <!-- Skeleton rows during loading -->
559
+ <tr
560
+ v-if="initialLoading"
561
+ v-for="i in 5"
562
+ :key="`ev-skel-${i}`"
563
+ class="animate-pulse"
564
+ >
565
+ <td class="py-3 px-4">
566
+ <div class="h-3.5 w-36 rounded bg-muted"></div>
567
+ </td>
568
+ <td class="py-3 px-4">
569
+ <div class="h-4 w-10 rounded bg-muted"></div>
570
+ </td>
571
+ <td class="py-3 px-4">
572
+ <div class="h-3.5 w-20 rounded bg-muted"></div>
573
+ </td>
574
+ <td class="py-3 px-4">
575
+ <div class="h-4 w-48 rounded bg-muted"></div>
576
+ </td>
577
+ </tr>
578
+
579
+ <template v-else>
580
+ <tr
581
+ v-for="ev in customEvents"
582
+ :key="ev.name"
583
+ class="hover:bg-elevated/50 transition-colors"
584
+ >
585
+ <td class="py-3 px-4 font-bold text-primary">
586
+ {{ ev.name }}
587
+ </td>
588
+ <td class="py-3 px-4 text-default">
589
+ <UBadge size="xs" color="neutral" variant="subtle">
590
+ {{ ev.count?.toLocaleString() || 1 }}
591
+ </UBadge>
592
+ </td>
593
+ <td class="py-3 px-4 text-muted">
594
+ {{ fmtDate(ev.lastSeen) }}
595
+ </td>
596
+ <td class="py-3 px-4">
597
+ <pre
598
+ class="text-[10px] text-muted bg-muted/30 p-1.5 rounded inline-block max-w-sm truncate"
599
+ :title="JSON.stringify(ev.sampleMetadata)"
600
+ >{{ JSON.stringify(ev.sampleMetadata) }}</pre>
601
+ </td>
602
+ </tr>
603
+ <tr v-if="!customEvents.length">
604
+ <td colspan="4" class="text-center py-12 text-muted text-xs font-sans">
605
+ No custom events recorded yet. Click "Simulate New Event" above.
606
+ </td>
607
+ </tr>
608
+ </template>
609
+ </tbody>
610
+ </table>
611
+ </div>
612
+ </UCard>
613
+ </template>
614
+ </template>
615
+ </UDashboardPanel>
616
+ </template>