Update
This commit is contained in:
33
public/js/page-tracking.js
Normal file
33
public/js/page-tracking.js
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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');
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user