34 lines
1.0 KiB
JavaScript
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/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');
|
|
}
|
|
});
|