mirror of
https://github.com/JonasunderscoreJones/stats.jonasjones.dev.git
synced 2025-10-22 20:19:19 +02:00
Compare commits
3 commits
d7b95a2790
...
6094873f88
Author | SHA1 | Date | |
---|---|---|---|
6094873f88 | |||
50254a8097 | |||
064e3927be |
4 changed files with 949 additions and 644 deletions
1492
package-lock.json
generated
1492
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -5,6 +5,7 @@
|
|||
</script>
|
||||
|
||||
<div class="app">
|
||||
<Header />
|
||||
<main>
|
||||
<slot />
|
||||
</main>
|
||||
|
@ -23,22 +24,4 @@
|
|||
width: 100vw;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
footer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
footer a {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
@media (min-width: 480px) {
|
||||
footer {
|
||||
padding: 12px 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -1,41 +1,21 @@
|
|||
<script>
|
||||
import { page } from '$app/stores';
|
||||
import logo from '$lib/images/svelte-logo.svg';
|
||||
import github from '$lib/images/github.svg';
|
||||
import { onMount } from 'svelte';
|
||||
//import { afterNavigate } from '$app/navigation';
|
||||
import { recordRequest } from './analytics.js';
|
||||
// Function to handle navigation events
|
||||
function handleNavigation() {
|
||||
recordRequest();
|
||||
}
|
||||
// Call the analytics function on initial page load and after each navigation
|
||||
onMount(() => {
|
||||
handleNavigation();
|
||||
afterNavigate(() => {
|
||||
handleNavigation();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<header>
|
||||
<div class="corner">
|
||||
<a href="https://kit.svelte.dev">
|
||||
<img src={logo} alt="SvelteKit" />
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
<svg viewBox="0 0 2 3" aria-hidden="true">
|
||||
<path d="M0,0 L1,2 C1.5,3 1.5,3 2,3 L2,0 Z" />
|
||||
</svg>
|
||||
<ul>
|
||||
<li aria-current={$page.url.pathname === '/' ? 'page' : undefined}>
|
||||
<a href="/">Home</a>
|
||||
</li>
|
||||
<li aria-current={$page.url.pathname === '/about' ? 'page' : undefined}>
|
||||
<a href="/about">About</a>
|
||||
</li>
|
||||
<li aria-current={$page.url.pathname.startsWith('/sverdle') ? 'page' : undefined}>
|
||||
<a href="/sverdle">Sverdle</a>
|
||||
</li>
|
||||
</ul>
|
||||
<svg viewBox="0 0 2 3" aria-hidden="true">
|
||||
<path d="M0,0 L0,3 C0.5,3 0.5,3 1,2 L2,0 Z" />
|
||||
</svg>
|
||||
</nav>
|
||||
|
||||
<div class="corner">
|
||||
<a href="https://github.com/sveltejs/kit">
|
||||
<img src={github} alt="GitHub" />
|
||||
</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<style>
|
||||
|
|
34
src/routes/analytics.js
Normal file
34
src/routes/analytics.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Function to record the request with analytics
|
||||
export async function recordRequest() {
|
||||
|
||||
const analyticsData = {
|
||||
timestamp: Date.now(),
|
||||
domain: window.location.hostname,
|
||||
method: 'GET',
|
||||
path: window.location.pathname,
|
||||
};
|
||||
|
||||
console.log('Recording request:', analyticsData);
|
||||
|
||||
const ANALYTICS_URL = 'https://analytics.jonasjones.dev/requests/record/ipunknown';
|
||||
const ANALYTICS_API_KEY = import.meta.env.VITE_ANALYTICS_API_KEY;
|
||||
|
||||
try {
|
||||
const response = await fetch(ANALYTICS_URL, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': ANALYTICS_API_KEY,
|
||||
},
|
||||
body: JSON.stringify(analyticsData),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
console.log('Request recorded successfully');
|
||||
} else {
|
||||
console.error('Failed to record request:', response.status, await response.text());
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error recording request:', error);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue