document.addEventListener('DOMContentLoaded', (event) => { let pop = window.location.pathname.split('/').pop(); let choice = 'none'; if (pop === 'ja') { choice = 'A'; } else if (pop === 'nein') { choice = 'B'; } // set the content of the dom element with the id fan to the value of the url parameter "choice" if (choice === 'A') { document.getElementById('fan').innerHTML = 'Ananas Fan, '; } else { document.getElementById('fan').innerHTML = 'Ananas-Gegner, '; } const navigate = function (target) { if (target === '') { return; } let url; // get the value of the url parameter "choice" switch (target) { case 'A': url = 'https://soniis-calw.de'; break; case 'B': url = 'https://mamma-napoli.com'; break; case 'C': url = 'https://pizza-coach.net'; break; case 'D': url = 'https://piccolino-bremen.net'; break; case 'E': url = 'https://321pizza.de'; break; } // go to the url window.location.href = url + '/pizza-quiz' + '?choice=' + choice; } const agent = navigator.userAgent.toLowerCase(); let device; if (!agent) { device = 'unknown'; } else if (agent.includes('android')) { device = 'android'; } else if (agent.includes('iphone')) { device = 'iphone'; } else if (agent.includes('windows nt')) { device = 'windows'; } else if (agent.includes('macintosh')) { device = 'mac'; } else { device = 'other'; } let userId = localStorage.getItem('userId'); if (!userId) { userId = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); localStorage.setItem('userId', userId); } fetch('https://api.analytics.liefercon.de/tr/e', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ event: 'pizza-quiz-open', eventData: {choice: choice}, sessionId: null, userId: userId, restaurantId: null, website: 'pizzaquiz', device: device, }), }) .then(response => response.text()) // or .json() if you expect a JSON response .then(data => { console.log('visit tracking successful:', data); }) .catch((error) => { console.error('Error visit tracking:', error); }); document.getElementById('pizzaQuizForm').addEventListener('submit', function (e) { e.preventDefault(); // Prevent the actual form submission const selected = document.getElementById('restaurantOptions'); if (!selected) { return; } const selectedValue = selected.value; fetch('https://api.analytics.liefercon.de/tr/e', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ event: 'pizza-quiz-submit', eventData: {value: selectedValue, choice: choice}, sessionId: null, userId: userId, restaurantId: null, website: 'pizzaquiz', device: device, }), }) .then(response => response.text()) // or .json() if you expect a JSON response .then(data => { navigate(selectedValue); }) .catch((error) => { navigate(selectedValue); }); console.log(selectedValue); }); const submitButton = document.querySelector('.submit'); document.getElementById('restaurantOptions').addEventListener('change', function (e) { const selectedValue = e.target.value; if (selectedValue !== "") { submitButton.classList.add('active'); submitButton.disabled = false; } else { submitButton.classList.remove('active'); submitButton.disabled = true; } }); });