// Get the referral code from the URL const urlParams = new URLSearchParams(window.location.search); const referralCode = urlParams.get('que'); if (referralCode) { console.log("affiliate_code.js found cookie") // Set the referral code in a cookie const expirationDate = new Date(); expirationDate.setFullYear(expirationDate.getFullYear() + 1); // Set expiration to 1 year from now // Find domain const host = window.location.hostname; // Get the full hostname (e.g., "subdomain.example.com") const parts = host.split('.'); // Split the hostname into its parts if (parts.length >= 2) { const parentDomain = parts.slice(-2).join('.'); // Get the last two parts to form the parent domain console.log(parentDomain); // Create the cookie with domain, path, and expiration date document.cookie = `referralCode=${referralCode}; domain=.${parentDomain}; path=/; expires=${expirationDate.toUTCString()}`; } else { document.cookie = `referralCode=${referralCode}; domain=.${host}; path=/; expires=${expirationDate.toUTCString()}`; } }