-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: David Dal Busco <[email protected]>
- Loading branch information
1 parent
bd018d2
commit 86783e8
Showing
9 changed files
with
88 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/frontend/src/lib/components/analytics/AnalyticsPageViews.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<script lang="ts"> | ||
import type { AnalyticKey, PageView } from '$declarations/orbiter/orbiter.did'; | ||
import AnalyticsPages from '$lib/components/analytics/AnalyticsPages.svelte'; | ||
import AnalyticsReferrers from '$lib/components/analytics/AnalyticsReferrers.svelte'; | ||
export let pageViews: [AnalyticKey, PageView][] = []; | ||
</script> | ||
|
||
{#if pageViews.length > 0} | ||
<div class="container"> | ||
<AnalyticsReferrers {pageViews} /> | ||
|
||
<AnalyticsPages {pageViews} /> | ||
</div> | ||
{/if} | ||
|
||
<style lang="scss"> | ||
@use '../../styles/mixins/media'; | ||
.container { | ||
margin: var(--padding-4x) 0; | ||
@include media.min-width(large) { | ||
display: grid; | ||
grid-template-columns: repeat(2, 1fr); | ||
gap: var(--padding-4x); | ||
} | ||
} | ||
</style> |
52 changes: 52 additions & 0 deletions
52
src/frontend/src/lib/components/analytics/AnalyticsPages.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<script lang="ts"> | ||
import type { AnalyticKey, PageView } from '$declarations/orbiter/orbiter.did'; | ||
import { i18n } from '$lib/stores/i18n.store'; | ||
export let pageViews: [AnalyticKey, PageView][] = []; | ||
let referrers: Record<string, number> = {}; | ||
$: referrers = pageViews.reduce( | ||
(acc, [_, { href }]) => { | ||
let pages: string; | ||
try { | ||
const { pathname } = new URL(href); | ||
pages = pathname; | ||
} catch (err: unknown) { | ||
pages = href; | ||
} | ||
return { | ||
...acc, | ||
[pages]: (acc[pages] ?? 0) + 1 | ||
}; | ||
}, | ||
{} as Record<string, number> | ||
); | ||
let entries: [string, number][] = []; | ||
$: entries = Object.entries(referrers) | ||
.slice(0, 10) | ||
.sort(([_a, countA], [_b, countB]) => countB - countA); | ||
</script> | ||
|
||
{#if entries.length > 0} | ||
<div class="table-container"> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th> {$i18n.analytics.pages} </th> | ||
<th> {$i18n.analytics.count} </th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
{#each entries as [referrer, count]} | ||
<tr> | ||
<td>{referrer}</td> | ||
<td>{count}</td> | ||
</tr> | ||
{/each} | ||
</tbody> | ||
</table> | ||
</div> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,9 +58,3 @@ | |
</table> | ||
</div> | ||
{/if} | ||
|
||
<style lang="scss"> | ||
.table-container { | ||
margin: var(--padding-4x) 0; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters