PageSourceSearch

https://www.ugaoo.com/cdn/shop/t/299/assets/ga4-datalayer.js?v=17369309229971915241790773166

js ugaoo.com collected 2026-10-02 03:19:45 UTC 11,947 bytes, 2 lines download raw bytes

1(()=>{window.dataLayer=window.dataLayer||[];let _cachedCart=null;const fetchCart=async()=>{const res=await fetch("/cart.js");if(!res.ok)throw new Error(`cart ${res.status}`);const cart=await res.json();return _cachedCart=cart,cart},onDOMReady=fn=>{document.readyState==="loading"?document.addEventListener("DOMContentLoaded",fn,{once:!0}):fn()},onIdle=fn=>"requestIdleCallback"in window?requestIdleCallback(fn,{timeout:2e3}):setTimeout(fn,200),buildItems=(items=[])=>items.map((item,index)=>({item_id:item.sku||String(item.variant_id),item_name:item.product_title||item.title,item_brand:item.vendor??"",item_category:item.product_type??"",item_variant:item.variant_title??"",price:item.price/100,quantity:item.quantity,index})),getCoupon=cart=>{const apps=cart?.cart_level_discount_applications;return apps?.length?apps[0].title??"":""},dlPushEcom=event=>{window.dataLayer.push({ecommerce:null}),window.dataLayer.push(event)};let _lastFiredToken=null;const fireViewCart=()=>fetchCart().then(cart=>{cart.token!==_lastFiredToken&&(_lastFiredToken=cart.token,dlPushEcom({event:"view_cart",ecommerce:{currency:cart.currency,value:cart.total_price/100,num_items:cart.item_count,coupon:getCoupon(cart),items:buildItems(cart.items)}}))}).catch(()=>{});window.location.pathname==="/cart"&&onIdle(fireViewCart),onIdle(()=>{_cachedCart||fetchCart().catch(()=>{})}),onDOMReady(()=>{const detailsEl=document.querySelector("cart-drawer details"),summaryEl=detailsEl?.querySelector("summary");summaryEl&&summaryEl.addEventListener("click",()=>{detailsEl.hasAttribute("open")||(_lastFiredToken=null,onIdle(fireViewCart))})}),document.addEventListener("cart:updated",e=>{let newCart;try{const raw=e?.detail?.cart;if(!raw||(newCart=typeof raw=="string"?JSON.parse(raw):raw,!Array.isArray(newCart?.items)))return}catch{return}if(!_cachedCart){_cachedCart=newCart;return}const oldCart=_cachedCart;_cachedCart=newCart;const newItemMap=new Map(newCart.items.map(item=>[item.key,item]));oldCart.items?.forEach((oldItem,i)=>{const removedQty=oldItem.quantity-(newItemMap.get(oldItem.key)?.quantity??0);removedQty<=0||dlPushEcom({event:"remove_from_cart",ecommerce:{currency:newCart.currency,value:oldItem.price*removedQty/100,items:[{item_id:oldItem.sku||String(oldItem.variant_id),item_name:oldItem.product_title||oldItem.title,item_brand:oldItem.vendor??"",item_category:oldItem.product_type??"",item_variant:oldItem.variant_title??"",price:oldItem.price/100,quantity:removedQty,index:i}]}})})});{const match=window.location.pathname.match(/^\/blogs\/([^/]+)\/[^/]+/);if(match){const blogHandle=match[1],TYPE_MAP={"care-guide":"care_guide",care_guide:"care_guide",videos:"video",video:"video",faq:"faq",blog:"blog"};onIdle(()=>{window.dataLayer.push({event:"content_view",content_type:TYPE_MAP[blogHandle]??"blog",content_title:document.querySelector('meta[property="og:title"]')?.getAttribute("content")??document.title,content_category:blogHandle.replace(/-/g," ").replace(/\b\w/g,c=>c.toUpperCase())})})}}const _itemListName=(()=>{const match=window.location.pathname.match(/^\/collections\/([^/]+)/);return match?match[1].replace(/-/g," ").replace(/\b\w/g,c=>c.toUpperCase()):document.title.split("|")[0].trim()})(),getProductCount=()=>document.getElementById("product-grid")?.querySelectorAll("li").length??0,parseFilterType=(name="")=>{const parts=name.split(".");if(parts.includes("price"))return"price";if(parts.includes("availability"))return"availability";if(parts.includes("tag"))return"tag";const optIdx=parts.indexOf("option");return optIdx!==-1&&parts[optIdx+1]?parts[optIdx+1].toLowerCase().replace(/[\s-]+/g,"_"):parts[parts.length-1].toLowerCase().replace(/[\s-]+/g,"_")||"unknown"},SORT_TYPE_MAP={"price-ascending":"price_low_to_high","price-descending":"price_high_to_low","created-descending":"newest","created-ascending":"oldest","best-selling":"bestseller","title-ascending":"title_a_z","title-descending":"title_z_a",manual:"relevance"},FACET_FORMS="#FacetFiltersForm, #FacetSortFiltersForm, #FacetFiltersFormMobile";let _filterObserver=null,_filterTimer=null,_priceDebounce=null;const fireFilterAfterRender=pending=>{_filterObserver?.disconnect(),clearTimeout(_filterTimer);const gridContainer=document.getElementById("ProductGridContainer")??document.getElementById("ajax-product-grid"),pushFilter=()=>window.dataLayer.push({event:"filter_applied",...pending,results_count_after:getProductCount()});if(!gridContainer){pushFilter();return}_filterTimer=setTimeout(()=>{_filterObserver?.disconnect(),_filterObserver=null},5e3),_filterObserver=new MutationObserver((_,obs)=>{obs.disconnect(),_filterObserver=null,clearTimeout(_filterTimer),pushFilter()}),_filterObserver.observe(gridContainer,{childList:!0,subtree:!0})};document.addEventListener("change",e=>{const input=e.target,{name="",type,id,value,checked}=input,form=input.closest(FACET_FORMS);if(!form)return;if(name==="sort_by"){window.dataLayer.push({event:"sort_applied",sort_type:SORT_TYPE_MAP[value]??value.replace(/-/g,"_"),item_list_name:_itemListName,results_count:getProductCount()});return}if(type==="hidden"||type==="checkbox"&&!checked||type==="number")return;const labelEl=(type==="checkbox"||type==="radio")&&id?form.querySelector(`label[for="${id}"]`)??document.querySelector(`label[for="${id}"]`):null,filterValue=labelEl?labelEl.textContent.trim().replace(/\s*\(\d+\)\s
1*$/,"").trim():value;fireFilterAfterRender({filter_type:parseFilterType(name),filter_value:filterValue,item_list_name:_itemListName})},{passive:!0}),document.addEventListener("input",e=>{const input=e.target;if(input.type!=="number"||!input.name?.includes("price"))return;const form=input.closest(FACET_FORMS);form&&(clearTimeout(_priceDebounce),_priceDebounce=setTimeout(()=>{const gte=form.querySelector('[name$="price.gte"]')?.value||"0",lte=form.querySelector('[name$="price.lte"]')?.value||"";fireFilterAfterRender({filter_type:"price",filter_value:lte?`${gte} - ${lte}`:`${gte}+`,item_list_name:_itemListName})},150))},{passive:!0});{const path=window.location.pathname,isLoginPage=path==="/account/login",isRegisterPage=path==="/account/register";if(isLoginPage||isRegisterPage){let _pendingMethod="email";document.addEventListener("click",e=>{const btn=e.target.closest("button, a");if(!btn)return;const label=(btn.textContent+(btn.getAttribute("aria-label")??"")).toLowerCase();label.includes("google")?_pendingMethod="google":(label.includes("otp")||label.includes("phone"))&&(_pendingMethod="otp")},{passive:!0}),document.addEventListener("submit",()=>{sessionStorage.setItem("_ga4_auth",JSON.stringify({event:isLoginPage?"login":"signup",method:_pendingMethod})),_pendingMethod="email"})}if(!isLoginPage&&!isRegisterPage){const raw=sessionStorage.getItem("_ga4_auth");if(raw){sessionStorage.removeItem("_ga4_auth");try{const{event,method}=JSON.parse(raw);onIdle(()=>window.dataLayer.push({event,method}))}catch{}}}}let _pincodeUserInitiated=!1;document.addEventListener("click",e=>{e.target.closest('[name="pincode-submit"]')&&(_pincodeUserInitiated=!0)},{passive:!0}),document.addEventListener("keypress",e=>{e.key==="Enter"&&e.target.closest("pincode-checker, flexi-pincode-checker")&&(_pincodeUserInitiated=!0)},{passive:!0});const _origFetch=window.fetch;window.fetch=async(...args)=>{const url=String(args[0]??""),res=await _origFetch(...args);if(!url.includes("openleaf.tech")||!url.includes("closestTATUnicommerce"))return res;const params=new URL(url).searchParams,pincode=params.get("pincode")??"",sku=params.get("sku")??"",userInitiated=_pincodeUserInitiated;_pincodeUserInitiated=!1;try{const data=await res.clone().json(),values=Array.isArray(data?.values)?data.values:[],isServiceable=values[2]==="true"||values[2]===!0;window.dataLayer.push({event:"pincode_check",pincode,is_serviceable:isServiceable,item_id:sku,estimated_delivery_days:isServiceable&&parseInt(values[0],10)||0,user_initiated:userInitiated})}catch{}return res},onDOMReady(()=>{document.querySelectorAll("[data-promo-id]").forEach(link=>{link.addEventListener("click",()=>{const{promoId="",promoName="",promoSlot="",promoLocation=""}=link.dataset;console.log("[GA4] select_promotion",{promoId,promoName,promoSlot,promoLocation}),dlPushEcom({event:"select_promotion",ecommerce:{promotion_id:promoId,promotion_name:promoName,creative_slot:promoSlot,location_id:promoLocation}})})})}),document.addEventListener("click",e=>{const card=e.target.closest(".product-card.card-wrapper");if(!card||e.target.closest("[data-notify-card-trigger]"))return;const{listId="",listName="",productId="",itemName="",itemBrand="",itemCategory="",price="0",index="0"}=card.dataset;dlPushEcom({event:"select_item",ecommerce:{item_list_id:listId,item_list_name:listName,items:[{item_id:productId,item_name:itemName,item_brand:itemBrand,item_category:itemCategory,price:(parseInt(price,10)||0)/100,index:parseInt(index,10)||0}]}})});let _notifyMeLocation="pdp";document.addEventListener("click",e=>{const cardBtn=e.target.closest("[data-notify-card-trigger]"),pdpBtn=cardBtn?null:e.target.closest("ugaoo-notify-me:not([data-shared]) .ugaoo-notify-me__trigger");if(!cardBtn&&!pdpBtn)return;_notifyMeLocation=cardBtn?"card":"pdp";const productId=cardBtn?cardBtn.dataset.productId:pdpBtn.closest("ugaoo-notify-me").dataset.productId;window.dataLayer.push({event:"notify_me_initiate",location:_notifyMeLocation,product_id:productId??""})},{passive:!0});const _notifyMeFetch=window.fetch;window.fetch=async(...args)=>{const[input,init]=args,url=String(input?.url??input??""),location=_notifyMeLocation,res=await _notifyMeFetch(...args);if(!url.includes("/stock-notifications")||String(init?.method).toUpperCase()!=="POST"||!res.ok)return res;try{window.dataLayer.push({event:"notify_me_filled",location,product_id:String(JSON.parse(init.body)?.product_id??"")})}catch{}return res},document.addEventListener("click",e=>{const btn=e.target.closest(".csr .product-card__atc-btn.product-form__submit");
1if(!btn)return;const card=btn.closest(".product-card.card-wrapper");if(!card)return;const{itemName="",itemBrand="",itemCategory="",price="0",listName="",listId="",index="0"}=card.dataset,variantId=btn.dataset.variantId||"";dlPushEcom({event:"cart_upsell_atc",ecommerce:{currency:window.Shopify?.currency?.active||"",value:(parseInt(price,10)||0)/100,items:[{item_id:variantId,item_name:itemName,item_brand:itemBrand,item_category:itemCategory,price:(parseInt(price,10)||0)/100,quantity:1,index:parseInt(index,10)||0,item_list_id:listId,item_list_name:listName}]}})});{let _pendingCoupon=null;const PENDING_TTL_MS=5e3;document.addEventListener("click",e=>{const button=e.target.closest(".mini-cart__coupon-widget [data-coupon-action]");!button||button.classList.contains("is-loading")||(_pendingCoupon={action:button.dataset.couponAction==="remove"?"remove":"apply",code:button.dataset.discountCode||"",ts:Date.now()})},!0),document.addEventListener("cart:updated",e=>{if(!_pendingCoupon)return;const pending=_pendingCoupon;if(_pendingCoupon=null,Date.now()-pending.ts>PENDING_TTL_MS)return;const cart=e?.detail?.cart;dlPushEcom({event:pending.action==="remove"?"remove_coupon":"apply_coupon",ecommerce:{coupon:pending.code,currency:cart?.currency??"",value:typeof cart?.total_price=="number"?cart.total_price/100:void 0}})})}document.addEventListener("toggle",e=>{!e.target.matches?.(".mini-cart__coupon-drawer")||!e.target.open||window.dataLayer.push({event:"view_coupon_summary"})},!0),document.addEventListener("click",e=>{const btn=e.target.closest(".inline-banner-card__btn");if(!btn)return;const heading=btn.closest(".inline-banner-card")?.querySelector(".inline-banner-card__heading")?.textContent.trim()??"",payload={event:"promotional_banner_click",banner_text:btn.textContent.trim(),banner_url:btn.getAttribute("href")??"",banner_heading:heading,page_location:window.location.pathname};window.dataLayer.push(payload)},{passive:!0})})();
2//# sourceMappingURL=/cdn/shop/t/299/assets/ga4-datalayer.js.map?v=17369309229971915241790773166

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.