1class GTMTracking extends HTMLElement{constructor(){super(),this.abortController=null,this.jsonData={page:{type:null,market:null,locale:null,currency:null},product:{category:null,sub_category:null,type:null,color:null,title:null,main_url:null,discount:null}},this.processMessage=this.processMessage.bind(this)}static getJsonData(element){return{page:{type:element.getAttribute("page-type"),market:element.getAttribute("page-market"),locale:element.getAttribute("page-locale"),currency:element.getAttribute("page-currency")},product:{category:element.getAttribute("product-category"),sub_category:element.getAttribute("product-sub-category"),type:element.getAttribute("product-type"),color:element.getAttribute("product-color"),title:element.getAttribute("product-title"),main_url:element.getAttribute("product-main-url"),discount:element.getAttribute("product-discount")}}}processMessage(event){if(!event?.data||!event?.data?.event)return null;switch(window.dataLayer.push({ecommerce:null}),event.data.event.name){case"page_viewed":case"pageView":this.pageViewed();break;case"product_viewed":case"productImpressions":this.productViewed(event.data.event.data);break;case"product_added_to_cart":case"addToCart":this.productAddedToCart(event.data.event.data);break}}connectedCallback(){this.jsonData=GTMTracking.getJsonData(this),window.addEventListener("message",this.processMessage)}disconnectedCallback(){this.abortController.abort(),window.removeListener("message",this.processMessage)}pageViewed(){window.dataLayer.push({event:"pageView",page_info:{url:document.location.href,virtal_url:document.location.origin+document.location.pathname,page_path:document.location.pathname,page_title:document.title.split(" \u2013 ")[0],page_type:this.jsonData.page.type,page_referrer:document.referrer,market:this.jsonData.page.market,locale:this.jsonData.page.locale,currency:this.jsonData.page.currency}})}async cacheProductData(sku){const shortSKU=this.shortenSKU(sku);if(this.jsonData.product.main_url==="")return localStorage.setItem(shortSKU,JSON.stringify(this.jsonData.product)),null;this.abortController=new AbortController;try{const request=await fetch(this.jsonData.product.main_url,{signal:this.abortController.signal}),response=await request.text(),parser=new DOMParser,htmlDoc=parser.parseFromString(response,"text/html"),tags=htmlDoc.getElementsByTagName("gtm-tracking");if(tags.length===0)return null;localStorage.setItem(shortSKU,JSON.stringify(GTMTracking.getJsonData(tags[0]).product))}catch(error){error.name==="AbortError"?console.log("Fetch aborted by user"):console.error(error)}}shortenSKU(sku){return sku?sku.substring(0,sku.lastIndexOf("-")+1):""}getCachedProductItem(sku){const shortSKU=this.shortenSKU(sku),data=localStorage.getItem(shortSKU),jsonData=data?JSON.parse(data):{};return{item_id:shortSKU,item_category:jsonData?.category,item_category2:jsonData?.sub_category,item_category3:jsonData?.type,item_category4:jsonData?.color,
1item_name:jsonData?.title,discount:parseFloat(jsonData?.discount),index:0,coupon:"",quantity:1}}async productViewed(eventData){await this.cacheProductData(eventData?.productVariant?.sku),window.dataLayer.push({event:"productImpressions",ecommerce:{value:eventData?.productVariant?.price?.amount,items:[{...this.getCachedProductItem(eventData?.productVariant?.sku),item_brand:eventData?.productVariant?.product?.vendor,item_variant:eventData?.productVariant?.sku,price:eventData?.productVariant?.price?.amount}]}})}productAddedToCart(eventData){window.dataLayer.push({event:"addToCart",ecommerce:{value:eventData?.cartLine?.cost?.totalAmount.amount,items:[{...this.getCachedProductItem(eventData?.cartLine?.merchandise?.sku),item_brand:eventData?.cartLine?.merchandise?.product?.vendor,item_variant:eventData?.cartLine?.merchandise?.sku,price:eventData?.cartLine?.merchandise?.price?.amount,quantity:eventData?.cartLine?.quantity}]}})}}customElements.define("gtm-tracking",GTMTracking); 2//# sourceMappingURL=/cdn/shop/t/5/assets/gtm-tracking.js.map?v=94053587832734372301778581150
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.