<script>
function generateSessionId() {
    return '_' + Math.random().toString(36).substr(2, 9);
}
if (!localStorage.getItem('session_id')) {
    localStorage.setItem('session_id', generateSessionId());
}
fetch('/log_visit.php', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        page: window.location.href,
        referer: document.referrer,
        userAgent: navigator.userAgent,
        sessionId: localStorage.getItem('session_id')
    })
});
</script>
