var bixgrowUrl = 'https://api.bixgrow.com'; let bgRefHashCode = bgGetParameterByName('bg_ref'); if(bgRefHashCode){ const payload = { shop: Shopify.shop, affiliate_id: bgRefHashCode, url: window.location.href, referral_site: document.referrer } bgUseFetch(`${bixgrowUrl}/api/v2/automatic-coupon-customer`,'GET', payload).then(responseData => { if(Object.keys(responseData).length > 0) { if(!responseData.is_dynamic_coupon){ createCustomerDiscountPopup(responseData.settings,false,responseData?.discount_code); autoAppliedCoupon(responseData?.discount_code); }else if(bgRefHashCode != bgGetCookie('bixgrow_affiliate_referral') ){ createCustomerDiscountPopup(responseData.settings,true,responseData?.discount_code); } } }) } let toolbarsRefHashCode = bgRefHashCode ? bgRefHashCode : bgGetCookie('bgaffilite_id'); if(toolbarsRefHashCode){ getStoreToolBars(toolbarsRefHashCode); } function getStoreToolBars(refHashCode){ const payload = { shop: Shopify.shop, affiliate_id: refHashCode, url: window.location.href } bgUseFetch(`${bixgrowUrl}/api/store-toolbar`,'GET', payload).then(obj => { if(Object.keys(obj).length>0) { var enableToolbar = obj.settings.enable_shopping_with_toolbar; var enableFloatWidget = obj.settings.enable_shopping_with_floating_widget; var shopping_with_toolbar = obj.settings.shopping_with_toolbar; var shopping_with_floating_widget = obj.settings.shopping_with_floating_widget; if(enableToolbar) { let existingToolbarElement = document.getElementById('__bixgrow_topbar'); if (existingToolbarElement) { existingToolbarElement.remove(); } let head = document.head || document.getElementsByTagName('head')[0]; let style = document.createElement('style'); let topBar = document.createElement("div"); topBar.style.width = '100%'; topBar.style.zIndex = '2157484649'; topBar.style.position = 'relative'; topBar.id='__bixgrow_topbar'; window.onscroll = function(){ if(document.body.scrollTop > 5 || document.documentElement.scrollTop > 5){ topBar.classList.add('bixgrow_fixed'); } else{ topBar.classList.remove('bixgrow_fixed'); } } document.body.insertBefore(topBar,document.body.firstChild); let css = ` #__bixgrow_topbar { text-align: ${shopping_with_toolbar.textAlign}; background-color: ${shopping_with_toolbar.bgColor}; color: ${shopping_with_toolbar.textColor}; width: 100%; } #__bixgrow_topbar_style { display: inline-block; line-height: 40px; } .bixgrow_fixed { position: ${shopping_with_toolbar.position} !important; top: 0; width: 100%; z-index: 2157484649; } .bixgrow-toolbar-special-text { color: ${shopping_with_toolbar.special_text}; } `; style.type = 'text/css'; if (style.styleSheet){ // This is required for IE8 and below. style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } head.appendChild(style); let divContent = '
'+ shopping_with_toolbar.textContent +'
'; if(shopping_with_toolbar.textContent){ topBar.insertAdjacentHTML('beforeend',divContent); }else{ topBar.remove(); } } if(enableFloatWidget) { let existingFloatWidgetElement = document.getElementById('__bixgrow_float_widget'); if(existingFloatWidgetElement){ existingFloatWidgetElement.remove(); } let head = document.head || document.getElementsByTagName('head')[0]; let style = document.createElement('style'); let widget = document.createElement("div"); widget.id='__bixgrow_float_widget'; widget.classList.add('bixgrow_div_main'); if(shopping_with_floating_widget.is_show_only_avatar == 0){ widget.classList.add('bixgrow_style_toogle_click'); } document.body.appendChild(widget); let css = '.bixgrow_div_main{'+'overflow: hidden;position: fixed;'+ 'bottom: '+ shopping_with_floating_widget.spacingBottom+'px;'+'z-index: 21111;box-sizing: content-box;'+ shopping_with_floating_widget.position+': '+ shopping_with_floating_widget.spacingRight+'px;'+ 'box-shadow: rgb(0 0 0 / 20%) 0px 4px 8px 0px;'+ 'border-radius: 50%;'+ 'background-color: '+ shopping_with_floating_widget.bgColor+';'+ 'height:auto;'+ '-webkit-box-pack: end;'+ 'justify-content: end;'+ '-webkit-box-align: center;'+ 'align-items: center;'+ 'min-height: 50px;'+ 'display: flex;'+ 'flex-direction: row;'+ 'padding: 8.46667px;}'+ '#__bixgrow_text_floating_widget_style {'+ 'margin-right: 16px; margin-left: 16px; white-space: pre-line;'+ 'color:'+ shopping_with_floating_widget.textColor + ';'+ '}'+ '.bixgrow_style_toogle_click{border-radius:1.2rem '+ shopping_with_floating_widget.size+'px '+shopping_with_floating_widget.size+ 'px ' +'1.2rem;}'+ '.__bixgrow_img_floating_widget_style{border-radius: 50%;overflow: hidden;object-fit: cover;'+ 'width:' +shopping_with_floating_widget.size+'px;'+ 'height:' +shopping_with_floating_widget.size+'px;'+ 'transition: all 0.3s ease 0s;pointer-events: auto;}'+ '.__bixgrow_img_floating_widget_style:hover{'+ 'transform: scale(0.85);'+ '}'+ '.bixgrow-widget-special-text{ color:'+ shopping_with_floating_widget.special_text + '}'; style.type = 'text/css'; if (style.styleSheet){ // This is required for IE8 and below. style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } head.appendChild(style); let divContent = `
`+ shopping_with_floating_widget.textContent +'
'; widget.insertAdjacentHTML('beforeend',divContent); let img = document.createElement('IMG'); img.classList.add('__bixgrow_img_floating_widget_style'); img.src = obj.settings.avatar_link? obj.settings.avatar_link : shopping_with_floating_widget.placeholderIcon; img.addEventListener('click', function(event){ let divContentTemp = document.getElementById("__bixgrow_text_floating_widget_style"); if(divContentTemp.style.display==='none') { divContentTemp.style.display='block'; } else{ divContentTemp.style.display='none'; } widget.classList.toggle("bixgrow_style_toogle_click"); }); widget.appendChild(img); } } }) } function autoAppliedCoupon(discountCode){ discountCode = encodeURIComponent(discountCode); try{ const url = `https://${shopDomainToolbar}/discount/${discountCode}`; bgUseFetch(url,'GET'); }catch(error){ console.log(error); } } async function bgUseFetch(url, method = "GET",params = null,headers = { "Content-Type": "application/json"} ){ try { const options = { method: method, headers: { ...headers } } if(params){ if(method == 'GET'){ const queryString = new URLSearchParams(params).toString(); url += '?' + queryString; }else{ options.body = JSON.stringify(params); } } const response = await fetch(url,options); if(!response.ok){ throw new Error(response.statusText); } const responseData = await response.json().catch(() => null); if(responseData){ return responseData; } } catch (error) { throw error; } } function createCustomerDiscountPopup(settingsData,isDynamicCoupon = false,discountCode){ let styleData = settingsData.style; let textData = settingsData.text; let bgHead = document.head || document.getElementsByTagName('head')[0]; let myBgModal = document.getElementById('bgModal'); if(myBgModal){ myBgModal.remove(); } let referralDiv = document.createElement("div"); referralDiv.id = "bgModal"; referralDiv.classList.add('bgModal'); document.body.appendChild(referralDiv); let bgStyle = document.createElement("style"); let bgCss = `.bgModal{ display:none; position:fixed; z-index:9999; left:0; top:0; width:100%; height:100%; overflow:scroll; background-color: rgb(0,0,0,0.25); -webkit-animation-name: bgAnimatefade; -webkit-animation-duration: 0.4s; animation-name: bgAnimatefade; animation-duration: 0.4s; justify-content:center; align-items:center; } .bgModal--open{ display:flex; } .bgModal__content{ width: 450px; background: ${ styleData.card_background || '#fff'}; padding:24px; border-radius:16px; text-align:center; color:#1B283F; position: relative; box-shadow: 1px 0px 0px 0px rgba(0, 0, 0, 0.13), -1px 0px 0px 0px rgba(0, 0, 0, 0.13), 0px -1px 0px 0px rgba(0, 0, 0, 0.17), 0px 1px 0px 0px rgba(204, 204, 204, 0.50), 0px 8px 16px -4px rgba(26, 26, 26, 0.22); width: 600px; border-radius: 0px; padding: 30px 40px; } .bgBody{ display:flex; gap: 20px; flex-direction: column; justify-content: center; } .bgDescription{ display:flex; gap: 15px; flex-direction: column; justify-content: center; align-items: center; } .bgAvatar{ width: 50px; height: 50px; border-radius: 50%; object-fit:cover; } .bgHeading{ font-size:38px; font-weight:650; color: ${styleData.text_color || 'rgb(0, 0, 0)'}; line-height: normal; } .bgContent{ font-size:21px; font-weight:450; line-height: normal; color: ${styleData.text_color || 'rgb(0, 0, 0)'} } .bgDisplayNone{ display:none !important; } .bgInputWrapper { position: relative; cursor: pointer; display: flex; align-items: center; gap: 10px; justify-content: center; padding: 12px; border: 1px dashed ${styleData.discount_box_border || '#81868b'}; min-width: 200px; background: ${styleData.discount_box_background || '#fff'} } .bgInputWrapper .bgInput { text-align: center; font-weight: 550; line-height: normal; font-size: 18px; color: ${styleData.discount_code_color || '#000'} } .bgInputWrapper .bgInputCopy { width: 20px; height: 20px; flex-shrink: 0; } .bgButtonWrapper{ margin-top:16px; } .bgBtn{ border: none; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; border-radius: 4px; padding: 13px 16px; background: #1B283F; cursor:pointer; display:flex; justify-content:center; align-items:center; width: 100%; } .bgBtn__content{ color: ${styleData.button_text_color || '#fff'}; font-weight:450; line-height:normal; white-space: nowrap; user-select: none; font-size:21px; } .bgBtn--primary{ background: ${styleData.button_background || 'rgba(74, 74, 74, 1)' }; } .bgClose{ position:absolute; top: 10px; right: 12px; cursor: pointer; width: 28px; height: 28px; } .bgDisabled{ pointer-events: none; opacity: 0.5; } .bixgrow-loading .bixgrow-spinner { display: inline-block; } .bixgrow-loading .bgBtn__content { display:none; } @-webkit-keyframes bgAnimatefade { from {opacity:0} to {opacity:1} } @keyframes bgAnimatefade { from {opacity:0} to {opacity:1} } @media (max-width: 600px) { .bgModal__content{ width: 100%; border-radius: 0; padding:20px; } .bgHeading{ font-size: 30px; } .bgContent{ font-size: 18px; } .bgBtn__content{ font-size: 18px; } } ${styleData.custom_css ? styleData.custom_css : ''} `; bgStyle.type = 'text/css'; if (bgStyle.styleSheet){ bgStyle.styleSheet.cssText = css; } else { bgStyle.appendChild(document.createTextNode(bgCss)); } bgHead.appendChild(bgStyle); let bgModalContent = `
${styleData.affiliate_avatar && styleData.show_affiliate_avatar == 1 ?`Avatar`:''}
${textData.headline}
${textData.shop_now_description}
${textData.redeem_description}
${isDynamicCoupon?'':discountCode}
`; referralDiv.insertAdjacentHTML('beforeend',bgModalContent); let bgClose = document.getElementById('bgClose'); bgClose.addEventListener('click',function($event){ referralDiv.classList.remove("bgModal--open"); }) let bgInputWrapper = document.getElementById('bgInputWrapper'); let inputContent = ''; let timeoutId; let bgInput = document.getElementById('bgInput'); bgInputWrapper.addEventListener('click',function($event){ if(!inputContent){ inputContent = bgInput.textContent; } let tempInput = document.createElement('input'); tempInput.value = inputContent; document.body.appendChild(tempInput); tempInput.select(); document.execCommand('copy'); document.body.removeChild(tempInput); if(timeoutId){ clearTimeout(timeoutId); } bgInput.textContent = textData.after_copy_text || 'Copied'; timeoutId = setTimeout(() => { bgInput.textContent = inputContent; inputContent = ''; timeoutId = null; }, 1500); }) let shopNowBtn = document.getElementById('bgBtnShopNow'); shopNowBtn.addEventListener('click',function(){ referralDiv.classList.remove("bgModal--open"); }); let redeemBtn = document.getElementById('bgBtnRedeemCoupon'); redeemBtn.addEventListener('click', async function(event){ // const redeemContent = document.getElementById("redeemContent"); redeemBtn.classList.add('bgDisabled','bixgrow-loading'); // redeemContent.textContent = "Loading..."; const payload = { shop: Shopify.shop, affiliate_id: bgRefHashCode, referral_site: document.referrer } try{ const responseData = await bgUseFetch(`${bixgrowUrl}/api/v2/automatic-coupon-customer`,'POST',payload,{ "Content-Type": "application/json","Accept": "application/json"}); if(responseData && responseData?.discount_code){ redeemBtn.classList.add("bgDisplayNone"); redeemBtn.classList.remove('bgDisabled','bixgrow-loading'); shopNowBtn.classList.remove("bgDisplayNone"); bgInput.innerHTML = responseData?.discount_code; autoAppliedCoupon(responseData?.discount_code); bgInputWrapper.classList.remove("bgDisplayNone"); document.getElementById('bgShopNowContent').classList.remove("bgDisplayNone"); document.getElementById('bgRedeemContent').classList.add("bgDisplayNone"); if(isDynamicCoupon){ bgSetCookie('bixgrow_affiliate_referral', bgRefHashCode, 30); } }else{ document.getElementById('bgModal').remove(); } }catch(error){ } }); window.onclick = function (event) { if (event.target == referralDiv) { referralDiv.classList.remove("bgModal--open"); } }; referralDiv.classList.add("bgModal--open"); } function bgGetCookie(cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(';'); for(var i = 0; i