Skip to content

Commit

Permalink
feat(analytics): behaviour in analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrumm committed Jan 22, 2024
1 parent f3a6865 commit f7a7c22
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"prettier": "^3.2.4",
"prettier-plugin-tailwindcss": "^0.5.11",
"release-it": "^17.0.1",
"tailwind-scrollbar-hide": "^1.1.7",
"tailwindcss": "^3.4.1",
"typescript": "^5.3.3"
},
Expand Down
28 changes: 22 additions & 6 deletions src/pages/analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const Analytics = () => {
<Hero />
<main className="flex flex-col items-center justify-center">
<div className="container max-w-[1200px] gap-12 px-4 pb-28 pt-8">
<h1>Site Traffic</h1>
<h1>Traffic</h1>
<SimpleGrid
cols={{
xs: 2,
Expand All @@ -83,7 +83,7 @@ const Analytics = () => {
valueAppend="%"
/>
</SimpleGrid>
<h1>Vote analytics</h1>
<h1>Votes</h1>
<SimpleGrid
cols={{
sm: 2,
Expand Down Expand Up @@ -119,15 +119,29 @@ const Analytics = () => {
value={votes.avg_duration_per_vote}
/>
</SimpleGrid>
<h1>Historical data</h1>
<h1>Historical</h1>
<PageViewChart historical={historical} />
<h1 className="mb-2 mt-[60px]">Location data</h1>
<h1 className="pt-8">Behaviour</h1>
<SimpleGrid
cols={{
sm: 1,
md: 3,
}}
spacing="md"
className="pb-8"
>
<AnalyticsCard headline={'Events'} data={behaviour.routes} />
<AnalyticsCard headline={'Join'} data={behaviour.events} />
<AnalyticsCard headline={'Rooms'} data={behaviour.rooms} />
</SimpleGrid>
<h1>Location</h1>
<SimpleGrid
cols={{
sm: 1,
md: 3,
}}
spacing="md"
className="pb-8"
>
<AnalyticsCard
headline={'Countries'}
Expand All @@ -142,13 +156,14 @@ const Analytics = () => {
data={location_and_user_agent.city}
/>
</SimpleGrid>
<h1 className="mb-2 mt-[60px]">User Agent data</h1>
<h1>User Agent</h1>
<SimpleGrid
cols={{
sm: 1,
md: 3,
}}
spacing="md"
className="pb-8"
>
<AnalyticsCard
headline={'Operating Systems'}
Expand Down Expand Up @@ -178,6 +193,7 @@ export const AnalyticsCard = ({
}) => {
const sortedData = Object.entries(data)
.sort((a, b) => b[1] - a[1]) // Sort by value in descending order
.slice(0, 30) // Get the first 30 entries
.map(([name, value]) => ({ name, value })); // Map to objects with name and value

const highestValue = sortedData[0]?.value ?? 0; // Get the highest value
Expand All @@ -189,7 +205,7 @@ export const AnalyticsCard = ({
{headline}
</Title>
</Card.Section>
<Card.Section className="px-2">
<Card.Section className="px-2 overflow-y-scroll max-h-[400px] scrollbar-hide">
{sortedData.map((item, index) => (
<Group key={index} className="relative py-2">
<div
Expand Down
5 changes: 3 additions & 2 deletions src/server/api/routers/analytics.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ export const analyticsRouter = createTRPCRouter({
const countryCounts: Record<string, number> = {};
Object.entries(analytics.location_and_user_agent.country).forEach(
([country, count]) => {
const countryName =
const countryName = `${country} - ${
countryRegions.find((c) => c.countryShortCode === country)
?.countryName ?? country;
?.countryName ?? country
}`;
countryCounts[countryName] = count;
},
);
Expand Down
2 changes: 1 addition & 1 deletion tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export default {
theme: {
extend: {},
},
plugins: [],
plugins: [require('tailwind-scrollbar-hide')],
} satisfies Config;

0 comments on commit f7a7c22

Please sign in to comment.