1import{PANDECTES_RUNTIME_EVENT_NAME,PANDECTES_ANALYTICS_EVENT_NAME,PANDECTES_WINDOW_QUEUE_KEY,PANDECTES_WINDOW_LATEST_DETAIL_KEY,normalizePandectesConsent}from"./pandectes-consent.js";import{calculateDiscount,collectLineItems,collectProductCards,flushBrazeBeforeNavigation,getActiveCurrencyOrDefault,getLocaleData,logBrazeCustomEvent,normalizeEmailForHash,parseCentsToMajorUnits,sha256Hex}from"./braze-events.js";window.dataLayer=window.dataLayer||[],window.addEventListener("message",function(event){event.data&&event.data.type==="ARDENE_ANALYTICS_EVENT"&&window.dataLayer.push(event.data.payload)});function publishAnalytics(eventName,payload){return window.Shopify?.analytics?.publish?(window.Shopify.analytics.publish(eventName,payload),!0):(console.error("Shopify.analytics.publish not available"),!1)}let lastPublishedPandectesConsentSignature="";function publishPandectesConsent(detail){const payload=normalizePandectesConsent(detail);if(!payload)return!1;const payloadSignature=JSON.stringify(payload);if(payloadSignature===lastPublishedPandectesConsentSignature)return!1;const didPublish=publishAnalytics(PANDECTES_ANALYTICS_EVENT_NAME,payload);return didPublish&&(lastPublishedPandectesConsentSignature=payloadSignature),didPublish}function flushPendingPandectesConsent(){const queuedDetails=Array.isArray(window[PANDECTES_WINDOW_QUEUE_KEY])?[...window[PANDECTES_WINDOW_QUEUE_KEY]]:[];if(window[PANDECTES_WINDOW_QUEUE_KEY]=[],queuedDetails.length>0){queuedDetails.forEach(detail=>{publishPandectesConsent(detail)});return}window[PANDECTES_WINDOW_LATEST_DETAIL_KEY]&&publishPandectesConsent(window[PANDECTES_WINDOW_LATEST_DETAIL_KEY])}function initPandectesConsentTracking(){window[PANDECTES_WINDOW_QUEUE_KEY]=Array.isArray(window[PANDECTES_WINDOW_QUEUE_KEY])?window[PANDECTES_WINDOW_QUEUE_KEY]:[],window.addEventListener(PANDECTES_RUNTIME_EVENT_NAME,function(event){publishPandectesConsent(event?.detail)}),flushPendingPandectesConsent()}async function getCustomerEmailSha256ForPixel(){const raw=window.ardeneCustomerEmail;if(!raw||typeof raw!="string")return null;const normalized=normalizeEmailForHash(raw);if(!normalized)return null;try{return await sha256Hex(normalized)}catch(e){return console.error("[Analytics] sha256 customer email failed:",e),null}}function handleSelectItem(e){const{product}=e.detail;if(product)try{if(!window.Shopify?.analytics?.publish){console.error("Shopify.analytics.publish not available");return}const variant=product.selected_variant||product.variants?.find(v=>v?.available)||product.variants?.[0]||{},price=parseCentsToMajorUnits(variant.price??product.price),compareAtPrice=variant.compare_at_price!=null?parseCentsToMajorUnits(variant.compare_at_price):null,discount=calculateDiscount(price,compareAtPrice),item={item_id:product.ardeneStyle?.toString()||"",item_sku:variant.sku||"",item_name:product.title||"",item_brand:"Ardene",price,quantity:1,discount,internalCategory:product.internalCategory||""};compareAtPrice!=null&&(item.compareAtPrice=compareAtPrice);const currency=window.Shopify?.currency?.active||"CAD",payload={item,listId:window.collection?.handle,listName:window.collection?.title,currency};window.Shopify.analytics.publish("ardene:select_item",payload),logBrazeCustomEvent("select_item",payload)}catch(error){console.error("Error dispatching analytics event:",error)}}function handleProductChange(e){const{variant,product}=e.detail;try{if(window.Shopify?.analytics?.publish){const currencyCode=window.Shopify?.currency?.active||"CAD";let priceAmount;variant?.price!=null?priceAmount=parseCentsToMajorUnits(variant.price):product?.price!=null?priceAmount=parseCentsToMajorUnits(product.price):priceAmount=0;const compareAtPriceAmount=variant?.compare_at_price!=null?parseCentsToMajorUnits(variant.compare_at_price):void 0,discount=calculateDiscount(priceAmount,compareAtPriceAmount),rootUrl=window.Shopify?.routes?.root||window.routes?.root_url||"/",imageSrc=variant?.featured_image?.src||variant?.image?.src||variant?.image||product?.featured_image||(Array.isArray(product?.images)&&product.images.length>0?product.images[0]?.src:"")||"",payload={productVariant:{price:{amount:priceAmount||0,currencyCode},compareAtPrice:compareAtPriceAmount!=null?{amount:compareAtPriceAmount,currencyCode}:void 0,discount,product:{title:product?.title||"",vendor:product?.vendor||"Ardene",id:product?.id!=null?String(product.id):void 0,untranslatedTitle:product?.title||"",url:product?.handle?`${rootUrl}products/${product.handle}`:void 0,productType:product?.type||"",internalCategory:product?.internalCategory||"",ardeneStyle:product?.ardeneStyle||"",complexId:product?.complexId||""},id:variant?.id!=null?String(variant.id):void 0,image:{src:imageSrc}
1,sku:variant?.sku||product?.productSku||"",title:variant?.title||"",untranslatedTitle:variant?.title||""}};window.Shopify.analytics.publish("ardene:product_viewed",payload),logBrazeCustomEvent("product_viewed",payload)}else console.error("Shopify.analytics.publish not available")}catch(error){console.error("Error dispatching analytics event:",error)}}function handleCartAdd(e){const{variant,product}=e.detail;try{if(window.Shopify?.analytics?.publish){const currencyCode=window.Shopify?.currency?.active||"CAD";let priceAmount;variant?.price!=null?priceAmount=parseCentsToMajorUnits(variant.price):product?.price!=null?priceAmount=parseCentsToMajorUnits(product.price):priceAmount=void 0;const compareAtPriceAmount=variant?.compare_at_price!=null?parseCentsToMajorUnits(variant.compare_at_price):void 0,discount=calculateDiscount(priceAmount,compareAtPriceAmount),rootUrl=window.Shopify?.routes?.root||window.routes?.root_url||"/",imageSrc=variant?.featured_image?.src||variant?.image?.src||variant?.image||product?.featured_image||(Array.isArray(product?.images)&&product.images.length>0?product.images[0]?.src:"")||"",payload={productVariant:{price:{amount:priceAmount,currencyCode},compareAtPrice:compareAtPriceAmount!=null?{amount:compareAtPriceAmount,currencyCode}:void 0,discount,product:{title:product?.title||"",vendor:product?.vendor||"Ardene",id:product?.id!=null?String(product.id):void 0,untranslatedTitle:product?.title||"",url:product?.handle?`${rootUrl}products/${product.handle}`:void 0,productType:product?.type||"",internalCategory:product?.internalCategory||"",ardeneStyle:product?.ardeneStyle||"",complexId:product?.complexId||""},id:variant?.id!=null?String(variant.id):void 0,image:{src:imageSrc},sku:variant?.sku||product?.productSku||"",title:variant?.title||"",untranslatedTitle:variant?.title||""}};window.Shopify.analytics.publish("ardene:product_added_to_cart",payload)}else console.error("Shopify.analytics.publish not available")}catch(error){console.error("Error dispatching analytics event:",error)}}function handleAddToWishlist(e){const{variant,product}=e.detail;try{if(window.Shopify?.analytics?.publish){const currencyCode=window.Shopify?.currency?.active||"CAD";let priceAmount;variant?.price!=null?priceAmount=parseCentsToMajorUnits(variant.price):product?.price!=null?priceAmount=parseCentsToMajorUnits(product.price):priceAmount=void 0;const compareAtPriceAmount=variant?.compare_at_price!=null?parseCentsToMajorUnits(variant.compare_at_price):void 0,discount=calculateDiscount(priceAmount,compareAtPriceAmount),rootUrl=window.Shopify?.routes?.root||window.routes?.root_url||"/",imageSrc=variant?.featured_image?.src||variant?.image?.src||variant?.image||product?.featured_image||(Array.isArray(product?.images)&&product.images.length>0?product.images[0]?.src:"")||"",payload={productVariant:{price:{amount:priceAmount,currencyCode},compareAtPrice:compareAtPriceAmount!=null?{amount:compareAtPriceAmount,currencyCode}:void 0,discount,product:{title:product?.title||"",vendor:product?.vendor||"Ardene",id:product?.id!=null?String(product.id):void 0,untranslatedTitle:product?.title||"",url:product?.handle?`${rootUrl}products/${product.handle}`:void 0,productType:product?.type||"",internalCategory:product?.internalCategory||"",ardeneStyle:product?.ardeneStyle||"",complexId:product?.complexId||""},id:variant?.id!=null?String(variant.id):void 0,image:{src:imageSrc},sku:variant?.sku||product?.productSku||"",title:variant?.title||"",untranslatedTitle:variant?.title||""}};window.Shopify.analytics.publish("ardene:add_to_wishlist",payload),logBrazeCustomEvent("add_to_wishlist",payload)}else console.error("Shopify.analytics.publish not available")}catch(error){console.error("Error dispatching analytics event:",error)}}function handleProductRemovedFromCart(e){try{if(!!!window.Shopify?.analytics?.publish)return;const item=e.detail?.item;if(!item)return;const currency=getActiveCurrencyOrDefault(),quantity=Number(item.quantity)||0,price=Number(item.price)||0,total=(quantity*price).toFixed(2),cartLine={merchandise:{id:item.item_sku||item.key||"",sku:item.item_sku||"",product:{id:item.item_id!=null?String(item.item_id):"",title:item.item_name||"",productType:item.internalCategory||"",ardeneStyle:item.item_id||"",internalCategory:item.internalCategory||""}},cost:{totalAmount:{amount:total,currencyCode:currency}},compareAtPrice:item.compareAtPrice!=null?{amount:String(item.compareAtPrice),currencyCode:currency}:void 0,discount:item.discount||0,quantity};publishAnalytics("ardene:product_removed_from_cart",{cartLine})}catch(error){console.error("Error dispatching product_removed_from_cart analytics event:",error)}}
1function handleCartViewed(){try{if(!!!window.Shopify?.analytics?.publish)return;const rootUrl=window.Shopify?.routes?.root||window.routes?.root_url||"/",cartUrl=window.Shopify?.routes?.cart_url||window.routes?.cart_url||`${rootUrl}cart`;fetch(`${cartUrl}.js`,{headers:{"Content-Type":"application/json"}}).then(res=>res.ok?res.json():Promise.reject(new Error(`Failed to fetch cart: ${res.status}`))).then(cart=>{const currency=cart?.currency||getActiveCurrencyOrDefault(),value=typeof cart?.total_price=="number"?cart.total_price/100:void 0,payload={cartData:{items:collectLineItems()},currency,value};publishAnalytics("ardene:view_cart",payload),logBrazeCustomEvent("view_cart",payload)}).catch(err=>{console.error("Error fetching cart for view_cart:",err)})}catch(error){console.error("Error dispatching view_cart analytics event:",error)}}function handleProductGridViewed(e){try{if(!!!window.Shopify?.analytics?.publish)return;const grid=e?.detail?.grid||(e?.querySelectorAll?e:document),listId=window.collection?.id||"",listName=window.collection?.title||"",products=collectProductCards(grid);if(!products.length)return;const currency=window.Shopify?.currency?.active||"CAD",payload={listId,listName,products,currency};window.Shopify.analytics.publish("ardene:view_item_list",payload),logBrazeCustomEvent("view_item_list",payload)}catch(error){console.error("Error dispatching view_item_list analytics event:",error)}}function handleBeginCheckoutClick(e){const trigger=e.target.closest("[data-cart-submit]");if(!trigger)return;const isInMinicart=!!trigger.closest("#minicart, minicart-component"),isLink=trigger.tagName==="A",href=isLink?trigger.getAttribute("href"):null;if(!(!isInMinicart||!isLink||!href||!href.includes("/checkout"))&&(e.preventDefault(),trigger.getAttribute("data-processing")!=="true")){trigger.setAttribute("data-processing","true"),trigger.setAttribute("aria-disabled","true");try{if(!!!window.Shopify?.analytics?.publish){window.location.assign(href);return}const items=collectLineItems(),currency=getActiveCurrencyOrDefault(),value=items.reduce((sum,it)=>sum+(Number(it.price)||0)*(Number(it.quantity)||0),0),payload={cartData:{items},currency,value};publishAnalytics("ardene:begin_checkout",payload),logBrazeCustomEvent("begin_checkout",payload),flushBrazeBeforeNavigation(),setTimeout(()=>{window.location.assign(href)},100)}catch(error){console.error("Error dispatching begin_checkout analytics event:",error),window.location.assign(href)}}}function initAnalytics(){document.addEventListener("select-item",handleSelectItem),document.addEventListener("product-change",handleProductChange),document.addEventListener("product-viewed",handleProductChange),document.addEventListener("product-added-to-cart",handleCartAdd),document.addEventListener("add-to-wishlist",handleAddToWishlist),document.addEventListener("cart-viewed",handleCartViewed),document.addEventListener("begin-checkout",handleBeginCheckoutClick),document.addEventListener("product-grid-ready",handleProductGridViewed),document.addEventListener("product-removed-from-cart",handleProductRemovedFromCart)}async function publishCustomerContextForPixel(){try{if(!window.Shopify?.analytics?.publish)return;const customerEmailSha256=await getCustomerEmailSha256ForPixel(),localeData=getLocaleData();publishAnalytics("ardene:customer_context",customerEmailSha256?{email:customerEmailSha256,...localeData}:localeData)}catch(error){console.error("Error publishing ardene:customer_context analytics event:",error)}}async function maybePublishCustomerLoggedIn(){try{if(!!!window.Shopify?.analytics?.publish||!window.sessionStorage)return;const alreadyFired=window.sessionStorage.getItem("customerLoginEventFired")==="true";if(!window.customer){window.sessionStorage.setItem("customerLoginEventFired","false");return}if(alreadyFired)return;const customerEmailSha256=await getCustomerEmailSha256ForPixel();if(!customerEmailSha256)return;const localeData=getLocaleData();publishAnalytics("ardene:customer_logged_in",{email:customerEmailSha256,...localeData}),window.sessionStorage.setItem("customerLoginEventFired","true")}catch(error){console.error("Error dispatching ardene:customer_logged_in analytics event:",error)}}const productViewed=productFormEl=>{const product=productFormEl.parseJsonAttribute("data-product"),ardeneStyle=productFormEl.getAttribute("data-product-style"),sku=productFormEl.getAttribute("data-product-sku"),internalCategory=productFormEl.getAttribute("data-internal-category"),complexId=productFormEl.getAttribute("data-complex-id");if(product){const extendedProduct={...product,ardeneStyle,internalCategory,complexId,productSku:sku};
1handleProductChange({detail:{product:extendedProduct,variant:null}})}return null};initPandectesConsentTracking(),document.addEventListener("DOMContentLoaded",()=>{(async()=>{await publishCustomerContextForPixel(),initAnalytics();const productFormEl=document.querySelector(".js-product-page product-form");productFormEl&&productViewed(productFormEl);const productGridEl=document.querySelector("product-grid");productGridEl&&handleProductGridViewed(productGridEl),await maybePublishCustomerLoggedIn()})()}); 2//# sourceMappingURL=/cdn/shop/t/239/assets/analytics.js.map?v=10851598723383666471790728890
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.