Compare commits

...

3 commits

Author SHA1 Message Date
6094873f88 fixed analytics being recorded twice 2024-12-23 04:39:58 +01:00
50254a8097 added analytics 2024-12-23 04:27:25 +01:00
064e3927be updated deps 2024-12-23 04:27:19 +01:00
4 changed files with 949 additions and 644 deletions

1492
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -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>

View file

@ -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
View 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);
}
}