Skip to content

Commit 7fa68c2

Browse files
feat: basic analytics
1 parent 854f80b commit 7fa68c2

File tree

4 files changed

+93
-5
lines changed

4 files changed

+93
-5
lines changed

frontend/src/Layout.vue

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
<template>
22
<div class="flex h-screen w-full flex-row bg-surface-white shadow">
3-
<Sidebar :header="{title: 'LinkLite', menuItems: [ { label: 'Toggle Theme', icon: Moon, onClick: toggleTheme },] }" />
4-
<div class="w-full">
3+
<Sidebar :header="{
4+
title: 'LinkLite',
5+
menuItems: [ { label: 'Toggle Theme', icon: Moon, onClick: toggleTheme },]
6+
}"
7+
8+
:sections="[
9+
{
10+
label: '',
11+
items: [
12+
{label: 'Links', icon: Link, to: '/'},
13+
{label: 'Analytics', icon: ChartColumn, to: '/analytics'}
14+
]
15+
}
16+
]"/>
17+
<div class="w-full m-5">
518
<slot></slot>
619
</div>
720
</div>
821
</template>
922

1023
<script setup>
1124
import Moon from '~icons/lucide/moon';
25+
import Link from "~icons/lucide/link";
26+
import ChartColumn from "~icons/lucide/chart-column";
1227
import { Sidebar } from 'frappe-ui';
1328
1429
function toggleTheme() {

frontend/src/pages/Analytics.vue

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<template>
2+
<div>
3+
<h2 class="font-bold text-gray-800">Analytics</h2>
4+
</div>
5+
<div class="grid grid-cols-5 justify-start items-start">
6+
<NumberChart
7+
:config="{
8+
title: 'Total Clicks',
9+
value: analyticsData.totalClicks,
10+
}"
11+
/>
12+
13+
<div class="col-span-2">
14+
<AxisChart
15+
:config="{
16+
data: analyticsData.clicksByLink,
17+
title: 'Clicks by Link',
18+
subtitle: 'Number of clicks per link',
19+
xAxis: {
20+
key: 'link',
21+
title: 'Link',
22+
type: 'category',
23+
},
24+
yAxis: {
25+
title: 'Clicks',
26+
},
27+
swapXY: true,
28+
series: [
29+
{
30+
name: 'clicks',
31+
type: 'bar',
32+
},
33+
],
34+
}"
35+
/>
36+
</div>
37+
</div>
38+
</template>
39+
40+
<script setup>
41+
import { NumberChart, AxisChart, createResource, createListResource } from 'frappe-ui';
42+
import { reactive } from 'vue';
43+
44+
const analyticsData = reactive({
45+
totalClicks: 0,
46+
clicksByLink: []
47+
})
48+
49+
createResource({
50+
url: 'frappe.client.get_count',
51+
params: {
52+
doctype: 'Short Link Click'
53+
},
54+
onSuccess(count) {
55+
analyticsData.totalClicks = count;
56+
},
57+
auto: true
58+
})
59+
60+
createListResource({
61+
doctype: 'Short Link Click',
62+
fields: ['link', 'count(name) as clicks'],
63+
groupBy: 'link',
64+
onSuccess(data) {
65+
analyticsData.clicksByLink = data;
66+
},
67+
auto: true
68+
})
69+
</script>

frontend/src/pages/Home.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="m-5">
2+
33

44
<div class="flex items-baseline justify-between mb-4">
55
<h2 class=" text-gray-900 font-semibold">Links</h2>
@@ -187,7 +187,6 @@
187187
</div>
188188
</template>
189189
</Dialog>
190-
</div>
191190
</template>
192191

193192
<script setup>

frontend/src/router.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ const routes = [
77
path: '/',
88
name: 'Home',
99
component: () => import('@/pages/Home.vue'),
10+
},
11+
{
12+
path: '/analytics',
13+
name: 'Analytics',
14+
component: () => import('@/pages/Analytics.vue'),
1015
}
1116
]
1217

13-
let router = createRouter({
18+
const router = createRouter({
1419
history: createWebHistory('/frontend'),
1520
routes,
1621
})

0 commit comments

Comments
 (0)