mirror of
https://github.com/JonasunderscoreJones/jonasjones.dev.git
synced 2025-10-23 08:59:19 +02:00
Compare commits
No commits in common. "5fb0303145180700c293efb98cac30c54559ac7f" and "941dced72d582f03a90a5dc7cf066f60cce31dcb" have entirely different histories.
5fb0303145
...
941dced72d
2 changed files with 0 additions and 51 deletions
|
@ -1,21 +1,4 @@
|
||||||
<script>
|
<script>
|
||||||
import { onMount } from 'svelte';
|
|
||||||
import { afterNavigate } from '$app/navigation';
|
|
||||||
import { recordRequest } from './analytics';
|
|
||||||
|
|
||||||
// Function to handle navigation events
|
|
||||||
function handleNavigation() {
|
|
||||||
recordRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call the analytics function on initial page load and after each navigation
|
|
||||||
onMount(() => {
|
|
||||||
handleNavigation();
|
|
||||||
afterNavigate(() => {
|
|
||||||
handleNavigation();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
let showMenu = false;
|
let showMenu = false;
|
||||||
|
|
||||||
function toggleMenu() {
|
function toggleMenu() {
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
// Function to record the request with analytics
|
|
||||||
export async function recordRequest() {
|
|
||||||
|
|
||||||
const analyticsData = {
|
|
||||||
timestamp: Date.now(),
|
|
||||||
domain: window.location.hostname,
|
|
||||||
method: 'GET', // Assuming the request method is GET; adjust as necessary
|
|
||||||
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