class Package { constructor(slug, shortName, name, price, plans, logo, retailed, upgradePkg) { this.slug = slug == null ? 'traveller' : slug; this.shortName = shortName == null ? 'Tourist Plan' : shortName; this.name = name == null ? 'cloudigo Traveller Plan' : name; this.price = price == null ? '19.99' : price; this.plans = plans == null ? ['global', 'tourist_activities', 'tourist_activities_me', 'tourist', 'traveller'] : plans; this.logo = logo == null ? '' : logo; this.retailed = retailed == null ? true : retailed; this.upgradePkg = upgradePkg; } } // Global variable for current package passed from the params or the default var package = new Package(); // Fetch package details by API with the given slug fetch('https://web.api.cloudigo.app/package/info?' + new URLSearchParams({ slug: package_param, }), { headers: {'Content-Type': 'application/json'} }).then( function (response) { if (response.ok) return response.json(); else return Promise.reject(response); }).then( function(data) { setPackageContent(data); }).catch(function (err) { console.log(err); // On api error, default package is set to traveller in case user clicks on Traveller paths // which go to checkout where the package information is dependent on local storage and // cookie sessionStorage.setItem('session_package','traveller'); // Essential Cookie var current = new Date(); var future = new Date(current.setDate(current.getDate() + 7)).toUTCString(); document.cookie = `package=traveller; expires=${future}; path=/;`; setPackageContent(); }); function setPackageContent(data) { sessionStorage.removeItem('packageLogo'); if (data) { package = new Package(data.slug, data.shortName, data.name, data.price, data.plans, data.logo_url, data.retailed, data.next); /// Plans are reversed since last one in an array is the most relevant and iframes use it sessionStorage.setItem('plans', data.plans.reverse().join()); } else package = new Package(); // Fallback to the default package if(!package.retailed && !window.location.href.includes('welcome')) window.location.href=`welcome.html?package=${data.slug}`; else { alterContent(); // Tracking placed here for package.price if(document.getElementById('checkout') && 'fbq' in window){ fbq('track', 'InitiateCheckout', { value: package.price, currency: 'EUR' }); } } } function sendFeedback(question, comment, slug) { try { fetch('https://web.api.cloudigo.app/feedback', { headers: {'Content-Type': 'application/json'}, method: "POST", body: JSON.stringify({ question: question, comment: comment, tag: `FEEDBACK_TOURIST_WEB_${slug?.toUpperCase() || "PKG"}_COMMENT` }) }).catch(function (err) { console.log(err); }); } catch (e) {console.log(e);} }