PageSourceSearch

https://perfumania.com/cdn/shop/t/1184/assets/datalayer-track.js?v=57537082050129355811790681272

js perfumania.com collected 2026-10-02 04:58:26 UTC 22,368 bytes, 2 lines download raw bytes

1"use strict";(()=>{const EMAIL_REGEX=/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)+$/,EVENT_MARKER="[data-datalayer-event]",SKIP_CLICK_EVENTS=new Set(["popup_view","newsletter_form_interaction","out_of_stock_view","login","sign_up"]),SKIP_SUBMIT_EVENTS=new Set(["out_of_stock_view","search_bar_click"]);class DatalayerTrack{constructor(){this.lastEventKey="",this.lastEventAt=0,this.viewedOutOfStockIds=new Set,this.pdpProductData=null,this.pdpVariants=null}init(){this.loadPdpJson(),document.addEventListener("click",this.onClick.bind(this),!0),document.addEventListener("submit",this.onSubmit.bind(this),!0),document.addEventListener("focusin",this.onSearchInteract.bind(this),!0),this.bindOutOfStockView(),this.bindIframeMarkerClicks(),this.bindSideCartAuto(),this.bindSearchMenu(),this.bindKlarna()}onClick(event){const target=this.getEventTarget(event);if(!target)return;target.closest("#ltkpopup-submit, #ltkpopup-mobile-submit, .ltkpopup-subscribe")&&this.trackPopupFormSubmit(target);const marker=target.closest(EVENT_MARKER);if(!marker||marker.matches("klarna-placement"))return;const parsed=this.parseMarker(marker);if(!parsed.event||SKIP_CLICK_EVENTS.has(parsed.event)&&!this.isAuthFormSubmit(parsed.event,marker))return;const fields=this.buildFields(parsed.event,marker,target,parsed.sectionName);if(!fields)return;this.pushEvent(parsed.event,fields);const popupName=parsed.event==="announcement_bar_interaction"&&marker.getAttribute("data-popup-name");popupName&&(this.popupFormName=popupName,this.pushFromMarker("popup_view",{form_name:this.orNa(popupName)}))}onSearchInteract(event){const target=this.getEventTarget(event);if(!(target instanceof HTMLInputElement)||target.getAttribute("id")!=="header_search")return;const marker=target.closest(EVENT_MARKER);!marker||this.parseMarker(marker).event!=="search_bar_click"||this.pushEvent("search_bar_click",{})}onSubmit(event){const form=event.target;if(!(form instanceof HTMLFormElement))return;(form.id==="ltkpopup-form"||form.querySelector("#ltkpopup-email, #ltkpopup-mobile"))&&this.trackPopupFormSubmit(event.submitter);const marker=(event.submitter instanceof Element?event.submitter:form).closest(EVENT_MARKER)||form.querySelector(EVENT_MARKER);if(!marker)return;const parsed=this.parseMarker(marker);if(!parsed.event||SKIP_SUBMIT_EVENTS.has(parsed.event))return;const fields=this.buildFields(parsed.event,marker,form,parsed.sectionName);fields&&this.pushEvent(parsed.event,fields)}isAuthFormSubmit(eventName,marker){if(eventName!=="login"&&eventName!=="sign_up"||!marker.matches('[type="submit"]'))return!1;const form=marker.closest("form");return!!(form&&typeof form.checkValidity=="function"&&form.checkValidity())}pushEvent(eventName,fields={}){const eventKey=[eventName,fields.click_text,fields.filter_value,fields.sort_value,fields.interaction_type,fields.section,fields.step].filter(Boolean).join("|"),now=Date.now();if(eventKey&&eventKey===this.lastEventKey&&now-this.lastEventAt<400)return;this.lastEventKey=eventKey,this.lastEventAt=now;const eventFields=this.fillNa({...fields});delete eventFields._ecommerce;const data={event:eventName,...this.getPageContext(),...eventFields};fields._ecommerce&&(data.ecommerce=this.fillNa(fields._ecommerce));try{window.dataLayer=window.dataLayer||[],window.dataLayer.push({ecommerce:null}),window.dataLayer.push(data)}catch(error){console.error("DataLayer push failed:",error)}}trackPopupFormSubmit(target){const named=document.querySelector("[data-popup-name]"),formName=this.orNa(this.popupFormName||named&&named.getAttribute("data-popup-name")),email=document.getElementById("ltkpopup-email"),mobile=document.getElementById("ltkpopup-mobile");if(!!(target&&target.closest&&target.closest("#ltkpopup-mobile-submit")||mobile&&mobile.getClientRects().length&&!(email&&email.getClientRects().length))){if(!this.isPopupFieldValid(mobile))return;this.pushEvent("popup_form_submit",{form_name:formName,form_location:"Popup",step:"2",form_status:"phone number"});return}this.isPopupFieldValid(email)&&this.pushEvent("popup_form_submit",{form_name:formName,form_location:"Popup",step:"1",form_status:"email"})}isPopupFieldValid(input){if(!input||!input.getClientRects().length)return!1;const value=this.normalizeText(input.value);if(!value)return!1;const pattern=input.getAttribute("pattern");
1if(pattern)try{if(new RegExp(pattern).test(value))return!0}catch{}return input.getAttribute("type")==="email"||input.getAttribute("id")==="ltkpopup-email"?EMAIL_REGEX.test(value):value.replace(/\D/g,"").length===10}pushFromMarker(eventName,fields={}){const marker=this.findMarker(eventName);if(!marker)return;const parsed=this.parseMarker(marker),fromMarker=this.buildFields(parsed.event,marker,marker,parsed.sectionName)||{};this.pushEvent(eventName,{...fromMarker,...fields})}bindOutOfStockView(){const form=this.findMarker("out_of_stock_view");if(!form||form.hidden||form.classList.contains("hidden"))return;const product=this.findProduct(form)||this.pdpProductData;if(!this.hasProduct(product)||product.available===!0)return;const item=this.buildItem(product,this.findVariant(form,form),this.getItemList(form));item.stock_status="out_of_stock",!this.viewedOutOfStockIds.has(item.product_id)&&(this.viewedOutOfStockIds.add(item.product_id),this.pushEvent("out_of_stock_view",{stock_status:"out_of_stock",items:[item]}))}bindSideCartAuto(){const original=window._theme&&window._theme.toggleSideCart;typeof original=="function"&&(window._theme.toggleSideCart=(show,callback,isAutoAction)=>{const opening=!!show&&!document.documentElement.classList.contains("cart-show"),result=original.call(window._theme,show,callback,isAutoAction);return opening&&isAutoAction&&this.pushEvent("side_cart_interaction",{interaction_type:"auto"}),result})}bindSearchMenu(){const track=this,push=(type,url)=>{track.pushEvent("search_menu_interaction",{interaction_type:type,click_text:"Search Menu",click_url:url||""})};customElements.whenDefined("header-search").then(()=>{const proto=customElements.get("header-search").prototype,events={open:"open",close:"close",onChange:"interact"};for(const[method,type]of Object.entries(events)){const original=proto[method];proto[method]=function(){const wasOpen=this.isOpen,result=original.apply(this,arguments);return(type==="interact"?this.isOpen:wasOpen!==this.isOpen)&&push(type),result}}}),document.addEventListener("click",event=>{const target=track.getEventTarget(event);if(!target||!document.body.classList.contains("search-active"))return;const root=target.closest("header-search");!root||target.closest('#header_search, [type="reset"], [data-close-search]')||push("interact",track.getClickUrl(root,target))},!0)}bindKlarna(){document.addEventListener("click",event=>{const path=event.composedPath();if(!path.some(node=>node.getAttribute&&node.getAttribute("part")==="osm-cta"))return;const marker=path.find(node=>node.matches&&node.matches("klarna-placement[data-datalayer-event]"));if(!marker)return;const fields=this.buildFields("pdp_interaction",marker,marker,"Klarna");fields&&this.pushEvent("pdp_interaction",fields)},!0)}bindIframeMarkerClicks(){window.addEventListener("blur",()=>{window.setTimeout(()=>{const iframe=document.activeElement;if(!(iframe instanceof HTMLIFrameElement))return;const marker=iframe.closest(EVENT_MARKER);if(!marker)return;const parsed=this.parseMarker(marker);if(parsed.event!=="announcement_bar_interaction")return;const fields=this.buildFields(parsed.event,marker,marker,parsed.sectionName);fields&&this.pushEvent(parsed.event,fields)},0)})}buildFields(eventName,marker,target,sectionName){const itemList=this.getItemList(marker),clickText=this.getClickText(marker,target),clickUrl=this.getClickUrl(marker,target);if(eventName==="select_item")return this.selectItemFields(marker,itemList);if(eventName==="add_to_wishlist"){if(marker.getAttribute("aria-pressed")==="true"||marker.classList.contains("whislist-added"))return null;const fields=this.selectItemFields(marker,itemList);return fields?(fields._ecommerce.value=fields._ecommerce.items[0].price,fields):null}return eventName==="pdp_interaction"?this.pdpFields(marker,target,sectionName,clickText):eventName==="out_of_stock_form_submit"?this.outOfStockSubmitFields(marker,target,clickText):eventName==="search_bar_click"?{}:eventName==="filter_interaction"?this.filterFields(marker,sectionName,clickText):eventName==="sort_interaction"?clickText?{sort_value:clickText}:null:eventName==="cta_interaction"?{click_text:clickText,cta_position:itemList.name!=="NA"?itemList.name:this.orNa(sectionName),click_url:clickUrl}:eventName==="carousel_navigation"?this.carouselFields(marker,sectionName):eventName==="header_menu_interaction"?this.headerFields(marker,target,sectionName):eventName==="side_cart_interaction"?{click_text:clickText,interaction_type:this.orNa(sectionName||clickText)}:eventName==="footer_interaction"?{click_text:clickText,section:this.orNa(sectionName),sub_category:"NA"}:eventName==="social_icon_interaction"?{social_platform:this.orNa(cl
1ickText),click_text:this.orNa(clickText),social_location:this.orNa(sectionName),click_url:clickUrl}:eventName==="announcement_bar_interaction"?{click_text:clickText,click_url:clickUrl}:eventName==="video_interaction"?this.videoFields(marker,itemList,sectionName):eventName==="sign_up"||eventName==="login"?{method:this.orNa(sectionName)}:eventName==="popup_view"?{form_name:this.orNa(clickText),form_location:this.orNa(sectionName)}:eventName==="newsletter_form_interaction"?this.formFields(marker,target,sectionName,clickText):eventName==="back_to_top_interaction"||eventName==="chatbot_interaction"?{}:{click_text:clickText,click_url:clickUrl}}selectItemFields(marker,itemList){const product=this.findProduct(marker);if(!this.hasProduct(product))return null;const item=this.buildItem(product,null,itemList);return item.index=this.getCardIndex(marker),{_ecommerce:{currency:this.getCurrency(),item_list_id:itemList.id,item_list_name:itemList.name,items:[item]}}}pdpFields(marker,target,sectionName,clickText){const product=this.pdpProductData||this.findProduct(marker);if(!this.hasProduct(product))return null;const item=this.buildItem(product,this.findVariant(target,marker),this.getItemList(marker)),quantityInput=(marker.closest("product-form")||marker).querySelector('[name="quantity"]');return quantityInput&&(item.quantity=Number(quantityInput.value)||1),{click_text:clickText,product_name:product.title||"NA",category:this.orNa(product.type),section:this.orNa(sectionName),items:[item]}}carouselFields(marker,sectionName){const named=marker.closest("[data-item-list-name]")||marker;return{interaction_type:this.orNa(this.normalizeText(sectionName).toLowerCase()),carousel_name:this.orNa(named.getAttribute("data-item-list-name")),section:this.getPageSection()}}getPageSection(){const template=this.normalizeText(document.body.getAttribute("data-template")).toLowerCase(),path=window.location.pathname||"/";return path==="/"||template==="index"||template.indexOf("index.")===0?"Homepage":path.indexOf("/cart")===0||template.indexOf("cart")===0?"Cart":path.indexOf("/search")===0||template.indexOf("search")===0?"Search":path.indexOf("/products/")!==-1||template.indexOf("product")===0?"Product":path.indexOf("/collections/")!==-1||template.indexOf("collection")===0?"Collection":template.indexOf("blog")===0||template.indexOf("article")===0?"Blog":"Page"}filterFields(marker,sectionName,clickText){const filterName=this.getFilterName(marker),isApply=this.normalizeText(sectionName).toLowerCase()==="apply",filterValue=isApply&&this.getPriceFilterValue(marker)||clickText;return!filterValue||!isApply&&this.normalizeText(filterValue)===this.normalizeText(filterName)?null:{filter_name:this.orNa(filterName),filter_value:this.orNa(filterValue),interaction_type:this.orNa(sectionName)}}outOfStockSubmitFields(marker,target,clickText){const root=marker.closest("[data-notify-me-modal], [data-backinstockform]")||marker,email=root.querySelector('input[type="email"]');if(email&&!EMAIL_REGEX.test(this.normalizeText(email.value)))return null;const product=this.findProduct(root)||this.pdpProductData,item=product?this.buildItem(product,this.findVariant(target,marker),this.getItemList(marker)):null;return item&&(item.stock_status="out_of_stock"),{click_text:clickText,stock_status:"out_of_stock",items:item?[item]:[]}}headerFields(marker,target,sectionName){const node=target||marker,banner=node.closest("[data-nav-banner]"),lv1=node.closest("[data-nav-lv1]"),lv2=node.closest("[data-nav-lv2]"),lv3=node.closest("[data-nav-lv3]"),heading=lv2&&(lv2.querySelector("[data-nav-heading]")||lv2.querySelector('[role="heading"]')),bannerCol=banner&&banner.closest("[data-nav-banner-col]"),clickText=banner?this.getVisibleText(banner.querySelector("[data-nav-title]"))||this.normalizeText(banner.getAttribute("aria-label")):this.getClickText(marker,target);let subCategory=this.normalizeText(marker.getAttribute("data-sub-category"));return banner?subCategory=this.getVisibleText(bannerCol&&bannerCol.querySelector("[data-nav-banner-head]")):(lv3||lv2)&&(subCategory=this.getVisibleText(heading)||clickText),{click_text:this.orNa(cl
1ickText),section:this.orNa(sectionName),main_menu:this.orNa(this.normalizeText(lv1&&lv1.getAttribute("data-main-menu"))||this.normalizeText(marker.getAttribute("data-main-menu"))||clickText),sub_category:this.orNa(subCategory)}}videoFields(marker,itemList,sectionName){const video=this.getVideo(marker);if(!video)return null;const actionKey=this.normalizeText(sectionName).toLowerCase();let action=video.paused?"start":"pause";return actionKey==="mute"&&(action=video.muted?"unmute":"mute"),actionKey==="fullscreen"&&(action="fullscreen"),actionKey==="play"&&(action=video.paused?"start":"pause"),{video_name:this.orNa(video.getAttribute("aria-label")||video.getAttribute("title")||itemList.name),video_action:action,video_location:itemList.name,video_position:itemList.name}}formFields(marker,target,sectionName,clickText){const root=target&&target.closest("form")||marker&&marker.closest("form")||marker,email=root&&root.querySelector('input[type="email"], #ltkpopup-email');return email&&!EMAIL_REGEX.test(this.normalizeText(email.value))?null:{form_name:this.orNa(clickText),form_location:this.orNa(sectionName)}}findProduct(el){if(!el)return this.pdpProductData;const notify=el.closest("[data-notify-me-modal], [data-backinstockform], notify-me");if(notify){const script=notify.querySelector('script[type="application/json"][data-notify-product], script[type="application/json"][data-product-json]'),parsed=this.parseJson(script&&script.textContent);if(parsed)return parsed}const scripts=(el.closest("product-card, .product-item, [data-product-id]")||el).querySelectorAll('script[type="application/json"][data-product-json], script[data-product-json]');for(const script of scripts){const parsed=this.parseJson(script.textContent);if(this.hasProduct(parsed))return parsed}return this.pdpProductData}findVariant(el,marker){if(!this.pdpVariants||!this.pdpVariants.length)return null;const radio=this.getVariantRadio(el);if(radio){const variantId=radio.value||radio.getAttribute("data-variant-id"),match=this.pdpVariants.find(variant=>String(variant.id)===String(variantId));if(match)return match}const root=marker&&marker.closest("product-form")||marker||el,hiddenId=root&&root.querySelector('[name="id"]'),currentId=hiddenId&&(hiddenId.value||hiddenId.getAttribute("data-vid"));return currentId?this.pdpVariants.find(variant=>String(variant.id)===String(currentId))||this.pdpVariants[0]:this.pdpVariants[0]}buildItem(product,variant,itemList){const productId=product.id||product.product_id||"",variantData=variant||{},variantId=variantData.id||variantData.variant_id||product.variant_id||product.selected_variant_id||"",compareAt=this.toMoney(variantData.compare_at_price||product.compare_at_price||product.compareAtPrice||0,!!variantData.id),price=this.toMoney(variantData.price!=null?variantData.price:product.price!=null?product.price:product.final_price,!!variantData.id),discount=compareAt>price?Number((compareAt-price).toFixed(2)):this.toMoney(product.discount||product.total_discount||0),available=variantData.available!=null?!!variantData.available:product.available!==!1;return{item_id:`shopify_${this.getCountryCode()}_${productId}_${variantId}`,product_id:String(productId),variant_id:String(variantId),item_name:product.title||product.item_name||product.product_title||"NA",quantity:Number(product.quantity||1),price,discount,item_brand:product.vendor||product.item_brand||"NA",item_list_name:itemList?itemList.name:"NA",item_list_id:itemList?itemList.id:"NA",stock_status:available?"in_stock":"out_of_stock"}}getItemList(el){const marker=el&&el.closest("[data-item-list-id], [data-item-list-name]");return{id:this.orNa(marker&&marker.getAttribute("data-item-list-id")),name:this.orNa(marker&&marker.getAttribute("data-item-list-name"))}}getCardIndex(card){if(!card)return 0;const item=card.closest("slideshow-container-item")||card,parent=item.parentElement;if(!parent)return 0;const index=Array.prototype.indexOf.call(parent.children,item);return index>=0?index:0}parseMarker(el){const parts=this.normalizeText(el&&el.getAttribute("data-datalayer-event")||"").split(",").map(part=>
1part.trim()).filter(Boolean);return{event:parts[0]||"",sectionName:parts.slice(1).join(", ")}}findMarker(eventName){const nodes=document.querySelectorAll(EVENT_MARKER);for(const node of nodes)if(this.parseMarker(node).event===eventName)return node;return null}parseJson(text){if(!text)return null;try{return JSON.parse(text)}catch{return null}}loadPdpJson(){const productNode=document.getElementById("pdp_product_data"),variantNode=document.getElementById("variants_data");this.pdpProductData=this.parseJson(productNode&&productNode.textContent),this.pdpVariants=this.parseJson(variantNode&&variantNode.textContent)}hasProduct(product){return!!(product&&(product.id||product.product_id||product.title||product.product_title||product.handle))}getFilterName(marker){const widget=marker&&marker.closest("[data-title]"),fromTitle=this.normalizeText(widget&&widget.getAttribute("data-title"));if(fromTitle)return fromTitle;const priceWrap=marker&&marker.closest("[data-value]");return this.normalizeText(priceWrap&&priceWrap.getAttribute("data-value"))}getPriceFilterValue(marker){const root=marker&&marker.closest("[data-value], [data-title]")||marker;if(!root)return"";const checked=root.querySelector('input[type="radio"]:checked');if(checked){const checkedId=checked.getAttribute("id"),label=checkedId?document.querySelector(`label[for="${checkedId}"]`):null;return this.getVisibleText(label)||this.normalizeText(checked.getAttribute("aria-label")||checked.value)}const minInput=root.querySelector("[data-price-min-input]"),maxInput=root.querySelector("[data-price-max-input]"),minValue=this.normalizeText(minInput&&minInput.value),maxValue=this.normalizeText(maxInput&&maxInput.value);return!minValue&&!maxValue?"":`${minValue||"0"} - ${maxValue||""}`.trim()}getSearchQuery(marker){const root=marker&&marker.closest("form")||marker;if(!root)return"";const input=root.querySelector('input[type="search"], [name="searches"], [name="q"]');return this.normalizeText(input&&input.value)}getClickText(marker,target){if(!marker)return"";const explicit=this.normalizeText(marker.getAttribute("data-click-text"));if(explicit)return explicit;let node=target&&marker.contains(target)?target:marker;for(;node;){const value=this.getVisibleText(node);if(value)return value;if(node===marker)break;node=node.parentElement}const markerId=marker.getAttribute("id");if(markerId){const label=document.querySelector(`label[for="${markerId}"]`),labelText=this.getVisibleText(label);if(labelText)return labelText}const ariaLabel=this.normalizeText(marker.getAttribute("aria-label"));if(ariaLabel)return ariaLabel;const image=marker.querySelector("img[alt]");return this.normalizeText(image&&image.getAttribute("alt"))}getClickUrl(marker,target){const explicit=this.normalizeText(marker&&marker.getAttribute("data-click-url"));if(explicit)return explicit;const link=(target&&marker.contains(target)?target:marker).closest("a[href]");if(!link||!marker.contains(link)&&link!==marker)return"";const href=link.getAttribute("href")||"";return!href||href==="#"||href.indexOf("javascript:")===0?"":link.href||href}getVisibleText(el){return this.normalizeText(el&&el.innerText)}getVariantRadio(el){if(!el)return null;if(el.matches('input[type="radio"]'))return el;const label=el.closest("label");if(!label)return null;const forId=label.getAttribute("for");return forId?document.getElementById(forId):label.querySelector('input[type="radio"]')}getVideo(marker){return marker instanceof HTMLVideoElement?marker:(marker.closest("custom-video")||marker).querySelector("video")}getEventTarget(event){if(event.target instanceof Element)return event.target;const path=typeof event.composedPath=="function"?event.composedPath():[];for(const node of path)if(node instanceof Element)return node;return null}getPageContext(){return{page_path:window.location.pathname,page_location:window.location.href,page_title:document.title}}getCountryCode(){const shopify=window.Shopify||{};return localStorage.getItem("shopCountryCode")||shopify.country||"US"}getCurrency(){const shopify=window.Shopify||{};return shopify.currency&&shopify.currency.active||"USD"}
1toMoney(value,fromCents){if(value==null||value==="")return 0;const raw=String(value).replace(/[^0-9.]/g,""),num=Number(raw);return Number.isNaN(num)?0:fromCents||!raw.includes(".")&&num>=1e3?Number((num/100).toFixed(2)):Number(num.toFixed(2))}orNa(value){return this.normalizeText(value)||"NA"}fillNa(data){if(data==null)return"NA";if(typeof data=="string")return this.orNa(data);if(typeof data!="object")return data;if(Array.isArray(data)){const items=[];for(const item of data)items.push(this.fillNa(item));return items}const out={};for(const key of Object.keys(data))out[key]=this.fillNa(data[key]);return out}normalizeText(value){return String(value||"").replace(/\s+/g," ").trim()}}window._theme=window._theme||{},window._theme.datalayerTrack=new DatalayerTrack,document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>window._theme.datalayerTrack.init()):window._theme.datalayerTrack.init()})();
2//# sourceMappingURL=/cdn/shop/t/1184/assets/datalayer-track.js.map?v=57537082050129355811790681272

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.