// Initialize deferredPrompt for use later to show browser install prompt. let deferredPrompt; window.addEventListener('beforeinstallprompt', (e) => { /* // Prevent the mini-infobar from appearing on mobile e.preventDefault(); // Stash the event so it can be triggered later. deferredPrompt = e; // Update UI notify the user they can install the PWA showInstallPromotion(); // Optionally, send analytics event that PWA install promo was shown. console.log(`'beforeinstallprompt' event was fired.`); */ var formData = new FormData(); var token = document.getElementById("track-token").content; formData.append("trackToken",token); formData.append("action","beforeinstallprompt"); navigator.sendBeacon("https://online-wunsch-liste.de/api/track-pwa.php",formData); }); window.addEventListener('appinstalled', () => { /* // Hide the app-provided install promotion hideInstallPromotion(); // Clear the deferredPrompt so it can be garbage collected deferredPrompt = null; // Optionally, send analytics event to indicate successful install console.log('PWA was installed'); */ var formData = new FormData(); var token = document.getElementById("track-token").content; formData.append("trackToken",token); formData.append("action","appinstalled"); navigator.sendBeacon("https://online-wunsch-liste.de/api/track-pwa.php",formData); }); function getPWADisplayMode() { const isStandalone = window.matchMedia('(display-mode: standalone)').matches; if (document.referrer.startsWith('android-app://')) { return 'pwa'; } else if (navigator.standalone || isStandalone) { return 'standalone'; } return 'browser'; } function loadModules(){ if(getPWADisplayMode()=='browser'){ dynamicallyLoadScript("https://online-wunsch-liste.de/js/main.php?v=29.09.2023.1"); }else{ dynamicallyLoadScript("https://online-wunsch-liste.de/js/main-pwa.php?v=29.09.2023.1"); } if(!checkCookieExists("webAppId")){ setCookie("webAppId", create_UUID(), 1825); } } function create_UUID(){ var dt = new Date().getTime(); var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = (dt + Math.random()*16)%16 | 0; dt = Math.floor(dt/16); return (c=='x' ? r :(r&0x3|0x8)).toString(16); }); return uuid; } function dynamicallyLoadScript(url) { var script = document.createElement("script"); // create a script DOM node script.src = url; // set its src to the provided URL document.head.appendChild(script); // add it to the end of the head section of the page (could change 'head' to 'body' to add it to the end of the body section instead) script.onload = function() { initTracking(); }; } function checkCookieExists(name) {   let cookie = getCookie(name); if (cookie != "") { return true;   } else {     return false;   } } function getCookie(cname) {   let name = cname + "="; let ca = document.cookie.split(';'); for(let i = 0; i < ca.length; i++) { let c = ca[i]; while (c.charAt(0) == ' ') {       c = c.substring(1);     }     if (c.indexOf(name) == 0) { return c.substring(name.length, c.length);     }   } return ""; } function setCookie(cname, cvalue, exdays) { const d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));   let expires = "expires="+d.toUTCString();   document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; }