function getUserId() { let userId = localStorage.getItem('user_id'); if (!userId) { // Generate a random ID if one doesn't exist userId = 'user-' + Math.random().toString(36).substr(2, 9); localStorage.setItem('user_id', userId); } return userId; } function logInteraction(elementName, actionType) { const userId = getUserId(); // Include the userId in the URL parameters const data = encodeURIComponent(`${userId}-${elementName}-${actionType}`); // Fire the request fetch(`/log?data=${data}`); }