var lsNetvisioGTM;(()=>{"use strict";const t=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{cart_id:t.id||null,cart_quantity:t.totalQuantity||0,cart_value:t.cost?.totalAmount?.amount||0,currency:t.cost?.totalAmount?.currencyCode,lines:(t.lines||[]).map((t=>({item_variant:t.merchandise.id,item_id:t.merchandise.product.id,item_sku:t.merchandise.sku,item_name:t.merchandise.product.title,quantity:t.quantity,line_total_price:t.cost.totalAmount.amount,price:t.merchandise.price.amount})))}};const e=function(t){let e={};return t?.data?.checkout?.totalPrice?.hasOwnProperty("amount")&&(e.value=t?.data?.checkout?.totalPrice?.amount?.toString(),e.cart_total=t?.data?.checkout?.totalPrice?.amount?.toString(),e.currency=t?.data?.checkout?.totalPrice?.currencyCode,e.cart_quantity=t?.data?.checkout?.lineItems?.length),"checkout_completed"==t.name&&(e.tax=t?.data?.checkout?.totalTax?.amount,e.shipping=t?.data?.checkout?.shippingLine?.price?.amount,e.transaction_id=t?.data?.checkout?.order?.id,e.coupon=t?.data?.checkout?.discountApplications[0]?.title,e.discount=t?.data?.checkout?.discountApplications[0]?.title,e.discount_amount=t?.data?.checkout?.discountsAmount?.amount??t?.data?.checkout?.discountApplications[0]?.value?.amount,e.discount_percentage=t?.data?.checkout?.discountApplications[0]?.value?.percentage,e.sub_total=t?.data?.checkout?.subtotalPrice?.amount),"collection_viewed"==t.name&&(e.collection_id=t?.data?.collection?.id+"",e.item_list_id=t?.data?.collection?.id+"",e.item_list_name=t?.data?.collection?.title,e.currency=t?.data?.collection?.productVariants[0]?.price?.currencyCode),"search_submitted"==t.name&&(e.search_term=t?.data?.searchResult?.query,e.currency=t?.data?.searchResult?.productVariants[0]?.price?.currencyCode),"cart_viewed"==t.name&&(e.value=t?.data?.cart?.cost?.totalAmount?.amount?.toString(),e.currency=t?.data?.cart?.cost?.totalAmount?.currencyCode),"product_viewed"==t.name&&(e.value=t?.data?.productVariant?.price?.amount?.toString(),e.currency=t?.data?.productVariant?.price?.currencyCode),"product_added_to_cart"==t.name&&(e.value=(1*t?.data?.cartLine?.cost?.totalAmount?.amount).toFixed(2),e.currency=t?.data?.cartLine?.cost?.totalAmount?.currencyCode),"product_removed_from_cart"==t.name&&(e.value=(1*t?.data?.cartLine?.cost?.totalAmount?.amount).toFixed(2),e.currency=t?.data?.cartLine?.cost?.totalAmount?.currencyCode),e};const a=function(t,e){let a=[];const r=!!e?.field_mapping_enabled||!!e?.enabled||!!e?.item_id,i=e?.field_mapping||e||{},o=t=>t?`${t}`.split("/").pop():t,c=t=>{const e=o((t?.product||{}).id||t?.product_id);if(!e)return null;const a=o(t?.id||t?.variant_id),r=window?.productShopStape;if(r&&o(r.id)===e){return{product:r,variant:(r.variants||[]).find((t=>o(t?.id)===a))||null}}const i=(window?.collectionShopStape?.products||[]).find((t=>o(t?.id)===e));if(i){return{product:i,variant:(i.variants||[]).find((t=>o(t?.id)===a))||null}}return null},n="fieldMappingProductStape",d=()=>{try{return JSON.parse(localStorage.getItem(n))||{}}catch(t){return{}}},l=t=>{const e=c(t);if(e?.product)return e.product;const a=o((t?.product||{}).id||t?.product_id);return a&&d()[a]||null},u=(t,e)=>{if(!t||!e)return null;const[a,r]=`${e}`.split("."),i=c(t),o=t?.metafields||t?.product?.metafields||i?.variant?.metafields||i?.product?.metafields||l(t)?.metafields||[];if(Array.isArray(o)){const t=o.find((t=>t?.namespace===a&&t?.key===r));return t?.value||null}return a&&r?o?.[a]?.[r]?.value||o?.[a]?.[r]||null:o?.[e]||null},s=(t,e)=>{const a=e?.product||{};return"country_market_code"===t.value?window?.Shopify?.country||window?.currentShopifyMarketStapeCode||(()=>{try{return JSON.parse(localStorage.getItem("marketShopStape"))||{}}catch(t){return{}}})()?.code||"":"product_id"===t.value?o(a.id||e?.product_id):"variant_id"===t.value?o(e?.id||e?.variant_id):"sku"===t.value?e?.sku:"barcode"===t.value?e?.barcode||c(e)?.variant?.barcode||(t=>{const e=c(t);if(e?.variant)return e.variant;const a=o((t?.product||{}).id||t?.product_id),r=o(t?.id||t?.variant_id);return a&&r&&d()[a]?.variants?.[r]||null})(e)?.barcode:"metafield"===t.value?u(e,t.metafield_name):null},m=(t,e)=>{const a=function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).map((t=>"string"==typeof t?{value:t}:t))}(e?.data_points||[]),r=e?.separator||"",i=e?.prefix||"",o=a.map((e=>s(e,t))).filter(Boolean);return o.length?`${i}${o.join(r)}`:""},p=(t,e,a)=>{const r=t?.product||{};if(!e?.source)return a;if("vendor"===e.source)return r.vendor;if("product_type"===e.source)return r.type;if("product_category"===e.source){const e=r.category||r.productCategory||r.standardProductCategory||l(t)?.category;return("object"==typeof e?e?.name||e?.full_name:e)||null}if("collection"===e.source){const e=l(t)?.collections;return r.collection||r.collections?.[0]?.title||r.collections?.[0]||e?.[0]?.title||e?.[0]}return"metafield"===e.source?u(t,e.metafield_name):a},_=(t,e)=>{if(!r)return t;const a=m(e,i.item_id),o=m(e,i.item_sku);return{...t,item_id:a||t.item_id,item_sku:o||t.item_sku,item_brand:p(e,i.item_brand,t.item_brand)||t.item_brand,item_category:p(e,i.item_category,t.item_category)||t.item_category}},h=t=>{const e=(t.discountAllocations||[]).reduce(((t,e)=>t+(Number(e?.amount?.amount)||0)),0);if(e>0)return e;const a=Number(t.variant?.price?.amount||0)*t.quantity,r=Number(t.finalLinePrice?.amount),i=Number.isFinite(r)?a-r:0;return i>0?i:null};if(t.data?.checkout?.lineItems)for(let e=0;e{const e=c(t),a=e?.product,r=e?.variant,i=o(a?.id),l=o(r?.id||t?.id||t?.variant_id);if(!i)return;if(a.category||a.collections||a.metafields||l&&r?.barcode)try{const t=d(),e=t[i]||{};t[i]={category:a.category||e.category||null,collections:a.collections||e.collections||null,metafields:a.metafields||e.metafields||null,variants:l?{...e.variants,[l]:{barcode:r?.barcode||e.variants?.[l]?.barcode||null}}:e.variants};const o=Object.keys(t);o.length>50&&delete t[o[0]],localStorage.setItem(n,JSON.stringify(t))}catch(t){}})(e),a.push(_({item_id:t.data.cartLine.merchandise.product.id,item_sku:t.data.cartLine.merchandise.sku,item_variant:t.data.cartLine.merchandise.id,item_name:t.data.cartLine.merchandise.product.title,variant_name:t.data.cartLine.merchandise.title,item_category:t.data.cartLine.merchandise.product.type,item_brand:t.data.cartLine.merchandise.product.vendor,item_url:t.data.cartLine.merchandise.product?.url,price:t.data.cartLine.merchandise.price.amount,imageURL:t.data.cartLine.merchandise?.image?.src,quantity:t.data.cartLine.quantity},e))}if(t.data?.productVariant&&a.push(_({item_id:t.data.productVariant.product.id,item_sku:t.data.productVariant.sku,item_variant:t.data.productVariant.id,item_name:t.data.productVariant.product.title,variant_name:t.data.productVariant.title,item_category:t.data.productVariant.product.type,price:t.data.productVariant.price.amount,item_brand:t.data.productVariant.product.vendor,imageURL:t.data.productVariant?.image?.src,item_url:t.data.productVariant?.product?.url,quantity:"1"},t.data.productVariant)),t.data?.collection?.productVariants)for(let e=0;e{r?.id==e?.item_variant&&r?.compare_at_price&&(a[t].compare_at_price=r.compare_at_price/100+"")}))}if(window?.collectionShopStape)for(let t=0;t{r?.variants?.forEach((r=>{r?.id==e?.item_variant&&r?.compare_at_price&&(a[t].compare_at_price=r.compare_at_price+"")}))}))}if(localStorage&&localStorage?.getItem("addedProductStape")){let t=[];try{localStorage.getItem("addedProductStape")&&(t=JSON.parse(localStorage.getItem("addedProductStape"))||[])}catch(t){}for(let e=0;e{t?.item_variant==r?.item_variant&&t.compare_at_price&&(a[e].compare_at_price=t.compare_at_price+"")}))}}}catch(t){}return a},r=window?.dataShopStape?.shop||"{{__SHOP__}}",i=window?.dataShopStape?.shopId||"{{__SHOP_ID__}}";let o;const c=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return Object.fromEntries(Object.entries(t).filter((t=>{let[e,a]=t;return null!=a&&""!==a})))};function n(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:200,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2e3;return new Promise((a=>{try{const r=Date.now(),i=setInterval((()=>{const t=localStorage.getItem("_sbp");if(t)return clearInterval(i),window._sbp=t,void a(!0);Date.now()-r>=e&&(clearInterval(i),a(!1))}),t)}catch(t){a(!1)}}))}(()=>{let d=new Date;Promise.all([fetch(`/apps/widget/setting?shop=${r}&shop_id=${i}`,{method:"GET"}).then((t=>t.json())),n().then((t=>{t?console.log("✅C_ID:",window._sbp):console.log("❌C_ID")})),new Promise((t=>{const e=()=>{const t=window?.Shopify?.customerPrivacy,e=t?.preferencesProcessingAllowed?.()??!1,a=t?.analyticsProcessingAllowed?.()??!1,r=t?.marketingAllowed?.()??!1;return e&&a&&r};"function"!=typeof window?.Shopify?.customerPrivacy?.analyticsProcessingAllowed?window?.Shopify?.loadFeatures?window.Shopify.loadFeatures([{name:"consent-tracking-api",version:"0.1"}],(function(a){if(a)return console.error("Помилка завантаження API приватності:",a),void t(!1);t(e())})):t(!1):t(e())}))]).then((r=>{let[i,n,l]=r;console.log("✅ST_2.0.63 T:",new Date-d);let{data_layer:u,script:s}=i,m={...i.generate};if(m?.use_multy_markets){const t=(i?.generate?.markets||[]).find((t=>t.id.includes(window.currentShopifyMarketStapeId)));if(t&&delete t.cookie_keeper,u?.log_event&&console.log("✅market:",t),!t)return null;s=t.script,m={...m,...t}}window.dataLayer=window.dataLayer||[];let p;function _(){if(!m?.insert_gtm_snipper)return null;let t=s;var e;"string"==typeof t&&t&&((e=document.createElement("script")).innerHTML=t,document.head.appendChild(e),p=!0)}m?.check_customer_privacy?l&&_():_(),document.addEventListener("visitorConsentCollected",(t=>{!p&&t?.detail?.marketingAllowed&&t?.detail?.analyticsAllowed&&t?.detail?.preferencesAllowed&&_()})),document.addEventListener("click",(function(t){const e=t.target.closest("a");if(e&&e.href.includes("/products/")){let t={};try{localStorage.getItem("selectProductStape")&&(t=JSON.parse(localStorage.getItem("selectProductStape"))||{})}catch(t){}const a=()=>"/"==window.location.pathname?"home":window.location.pathname.includes("/products/")?"product":window.location.pathname.includes("/collections/")?"category":window.location.pathname.includes("/search")?"search":"othe";if(o){const t=o.ecommerce;t.items=t.items.filter((t=>e.href.includes(t.item_url)));const r={...o,event:u.hide_sufix_stape?"select_item":"select_item_stape",ecomm_pagetype:a(),ecommerce:t};window.dataLayer.push(r)}else t[e.href]={page:a()},localStorage.setItem("selectProductStape",JSON.stringify(t))}}));const h={product_added_to_cart:"add_to_cart_stape",cart_viewed:"view_cart_stape",product_removed_from_cart:"remove_from_cart_stape",collection_viewed:"view_collection_stape",search_submitted:"search_submitted_stape",product_viewed:"view_item_stape"};u?.enable_checkout_error_tracking&&(h.alert_displayed="alert_displayed_stape",h.ui_extension_errored="ui_extension_errored_stape"),setInterval((()=>{try{let r=localStorage.getItem("stape_events");r&&(r=JSON.parse(r),Object.keys(r).forEach((i=>{const n={...r[i]};u?.log_event&&console.log("✅w_p_e:",n);let d=!0;if(m?.check_customer_privacy&&(d=l),d&&Boolean(h[n.name])){let r=t(n?.cart||{}),i=e(n);if(i.items=a(n,u),"collection_viewed"==n.name&&u?.product_collection_limit){const t=u?.product_collection_limit||10;i.items=i.items.slice(0,t)}var s={event:u.hide_sufix_stape?(h[n.name]||"").replace("_stape",""):h[n.name],user_data:window?.customerShopStape?{...c(window.customerShopStape),...c(n.user_data)}:c(n.user_data),ecommerce:i,cart_state:r,actual_url:window.location.href,ecomm_pagetype:n.ecomm_pagetype};if("collection_viewed"==n.name&&(o={...s,ecommerce:{...s.ecommerce,items:a(n,u)}}),"product_added_to_cart"==n.name){let t=[];try{localStorage.getItem("addedProductStape")&&(t=JSON.parse(localStorage.getItem("addedProductStape"))||[])}catch(t){}i.items.forEach((e=>{!t.some((t=>e.item_variant==t.item_variant&&t.compare_at_price))&&e.compare_at_price&&t.push(e)})),localStorage.setItem("addedProductStape",JSON.stringify(t))}if("product_viewed"==n.name){let t={};try{localStorage.getItem("selectProductStape")&&(t=JSON.parse(localStorage.getItem("selectProductStape"))||{})}catch(t){}if(t[window.location.href]){const e={event:u.hide_sufix_stape?"select_item":"select_item_stape",ecomm_pagetype:t[window.location.href].page||"othe",user_data:s.user_data,ecommerce:i};window.dataLayer.push(e),delete t[window.location.href],localStorage.setItem("selectProductStape",JSON.stringify(t))}}if(["alert_displayed","ui_extension_errored"].includes(n.name)&&(delete s.ecommerce,delete s.cart_state,s={...s,...n?.data?.alert||{}}),s.event){u.ecommerce?window.dataLayer.push({ecommerce:null}):delete s.ecommerce;try{delete s.user_data.lifetime_orders,delete s.user_data.new_customer}catch(t){}u.ecommerce&&window.dataLayer.push(s),u?.log_event&&console.log("✅E_D:",s,window.dataLayer)}else u?.log_event&&console.log("❌E_D:",s,window.dataLayer)}delete r[i],localStorage.setItem("stape_events",JSON.stringify(r))})))}catch(t){console.log("❌E_282:",t)}}),500)})).catch((t=>{console.log("❌E_287",t)}))})(),lsNetvisioGTM={}})();