Files
Ninjaserver/public/js/page-tracking.js
2025-09-23 14:13:24 +02:00

34 lines
1.0 KiB
JavaScript

// Page tracking functionality
function trackPageView(pageName) {
// Get user information
const userAgent = navigator.userAgent;
const referer = document.referrer || '';
// Send tracking data to server
fetch('/api/v1/public/track-page-view', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
page: pageName,
userAgent: userAgent,
ipAddress: null, // Will be determined by server
referer: referer
})
}).catch(error => {
console.log('Page tracking failed:', error);
// Silently fail - don't interrupt user experience
});
}
// Auto-track page on load - only track main page visits
document.addEventListener('DOMContentLoaded', function() {
// Only track the main page (index.html or root path)
const path = window.location.pathname;
if (path === '/' || path === '/index.html') {
trackPageView('main_page_visit');
}
});