console.log('growi-embed.liquid, v.5.13.25'); (function () { function waitForUtils(retries = 5) { if (window.growiCookieUtils) { // First check if affiliate ID is available in URL parameters const urlAffiliateId = new URLSearchParams(window.location.search).get('a') || new URLSearchParams(window.location.search).get('snowball'); // Get affiliate info from cookies const cookieInfo = window.growiCookieUtils.manageAffiliateCookies(); // Determine which affiliate ID to use (URL param takes precedence) const affiliateId = urlAffiliateId || cookieInfo.affiliateId; const visitorUid = cookieInfo.visitorUid; // If we have affiliate data from either source, update the cart if (affiliateId && visitorUid) { fetch('/cart/update.js', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ attributes: { __growi_affiliate_id: affiliateId, __growi_visitor_uid: visitorUid, }, }), }) .then((res) => res.json()) .then((data) => { console.log('✅ Cart attributes updated with affiliate & visitor ID', data); }) .catch((err) => { console.error('❌ Failed to update cart attributes', err); }); } } else if (retries > 0) { // Wait and retry setTimeout(() => waitForUtils(retries - 1), 100); } else { console.warn('⚠️ Growi cookie utilities not loaded after multiple retries'); } } // Wait for the script to load and run waitForUtils(); })();