window.getCookie=name=>{const match=document.cookie.match(new RegExp(`(^| )${name}=([^;]+)`));if(match)return match[2]},window.setCookie=(name,value,days=30)=>{let expires="";if(days){const date=new Date;date.setTime(date.getTime()+days*24*60*60*1e3),expires=`expires=${date.toUTCString()};`}const path="path=/;",domain=`Domain=${getRootDomain()};`;document.cookie=`${name}=${value||""};${expires}${path}${domain}`};const parseGid=gid=>{if(gid.startsWith("gid://shopify/")){const match=gid.match(/gid:\/\/shopify\/[^/]+\/([a-f0-9-]+)/);if(match)return match[1]}return gid},escapeSingleQuote=string=>string.replace("'","'"),gtag=data=>{try{const userData=getUserData();window.dataLayer=window.dataLayer||[],window.dataLayer.push({...data,customer:{...userData,...data.customer}})}catch(error){console.error("gtag error",error)}},returnCat2=type=>type==="Bridesmaid Dress"?"Bridesmaid Dresses":type==="Swatch"?"Swatches":type==="Groomsmen Accessory"||type==="Groomsmen Suiting"?"Groomsmen":type==="Party Stuff"||type==="Apparel"||type==="Swag"||type==="Getting Ready"||type==="Face Mask"||type==="Jewelry"||type==="Shoes"||type==="Seamless Underwear"||type==="Gifts"||type==="Complete the Look"||type==="Hair Accessories"?"NDC":type==="Gift Card"?"Gift Cards":"Other",fabricMap={chiffon:"Chiffon",tulle:"Tulle",mesh:"Mesh",satin:"Satin",crepe:"Crepe",knit:"Knit"},returnCat3=({type,tags})=>{function getMaterialLabel(productType,productTags){const fabric=productTags.find(tag=>tag.includes(fabricMap[tag]));return fabric?`${fabric} ${productType}`:`${productType} of Indeterminate Material`}return(type==="Bridesmaid Dress"||type==="Swatch")&&getMaterialLabel(type,tags),type==="Groomsmen Accessory"?"Groomsmen Accessories":type==="Groomsmen Suiting"?"Groomsmen Suiting":type==="Party Stuff"||type==="Apparel"||type==="Swag"?"Party":type==="Getting Ready"?"Getting Ready":type==="Face Mask"||type==="Jewelry"||type==="Shoes"||type==="Seamless Underwear"||type==="Hair Accessories"?"Complete the Look":type==="Gifts"?"Gifts":type==="Gift Card"?"Gift Cards":"Other"},returnCat4=({type,title,tags})=>{function getFabricAndColor(productType,productTags,productTitle){const fabric=productTags.find(tag=>tag.includes(fabricMap[tag]))||"Indeterminate Material",newTitleParts=productTitle.split("-");return`${newTitleParts.length>1?newTitleParts[1].replace(fabric,"").replace("in","").trim():"Indeterminate Color"} ${productType}`}return(type==="Bridesmaid Dresses"||type==="Swatch")&&getFabricAndColor(type,tags,title),type==="Groomsmen Accessory"?tags.includes("Bow Tie")?"Bow Ties":tags.includes("Pocket Square")?"Pocket Squares":tags.includes("Necktie")?"Neck Ties":"Indeterminate Groomsmen Accessories":type==="Groomsmen Suiting"?"Groomsmen Suiting":type==="Party Stuff"||type==="Apparel"||type==="Swag"?type:type==="Getting Ready"?tags.includes("Robes")?"Robes":tags.includes("Pajamas")?"Pajamas":tags.includes("Slippers")||tags.includes("Socks")||tags.includes("Sleep Masks")?"Getting Ready Accessories":"Indeterminate Getting Ready":type==="Face Mask"||type==="Jewelry"||type==="Shoes"||type==="Seamless Underwear"||type==="Hair Accessories"?type:type==="Gifts"?"Gifts":type==="Gift Card"?"Gift Cards":"Other"},getAttributionData=()=>{const data={},storageToAttribution={iT:"initial_timestamp",iS:"initial_source",iM:"initial_medium",iC:"initial_campaign",iCo:"initial_content",vT:"visit_timestamp",vS:"visit_source",vM:"visit_medium",vC:"visit_campaign",vCo:"visit_content"};return Object.keys(storageToAttribution).forEach(key=>{localStorage[key]&&(data[storageToAttribution[key]]=localStorage[key])}),data},getLineItemShippingState=lineItem=>{let shippingState="";const props=lineItem?.properties||{};return"_READY-TO-SHIP"in props||"_QUICK_SWATCH"in props?shippingState="RTS":"_MADE-TO-ORDER"in props?shippingState="MTO":"_PREORDER"in props&&(shippingState="PREORDER"),shippingState},getEventId=()=>Math.floor(Math.random()*1e9).toString(),getUserData=()=>JSON.parse(getCookie("bg_user_data")||"{}"),processImageUrl=productImageURL=>{let processedImageUrl=productImageURL;return/^https?:\/\//.test(productImageURL)||(processedImageUrl=`https:${productImageURL.startsWith("//")?productImageURL:`//${productImageURL}`}`),processedImageUrl},setUserData=(data={})=>{const updatedData={...getUserData(),...data};return window.setCookie("bg_user_data",JSON.stringify(updatedData)),null},getProductReviews=()=>{const reviewCount=parseInt(window.updateReviewCount().reviewCount,10),reviewRating=parseFloat(window.updateReviewCount().ratingValue);return{reviewCount:reviewCount||0,reviewRating:reviewRating||null}},getVideosCount=()=>document.querySelectorAll(".product-video-thumb").length||0,getSsProductIds=crossSell=>{const productIds=window.searchspring.controller[crossSell].events.product;return Object.keys(productIds)||[]},getRushFeePrice=()=>{const fee=document.querySelector("[data-rush-fee]")?.dataset.rushFee;return parseFloat(fee?.replace("$",""))||0},getColorPosition=()=>document.querySelector("variant-colors input:checked").dataset.index||0,getBarColors=(page=null)=>{const colors=[];return page==="homepage"?(document.querySelectorAll(".swatch-lp-color-bar-b #color-carousel a[href]").forEach(el=>{const color=el.getAttribute("data-color");colors.push(color)}),colors):(document.querySelectorAll('.filter-swatch[href*="filter:tags_color_bar"]').forEach(el=>{const matches=el.getAttribute("href").match(/filter:tags_color_bar:([a-zA-Z0-9$%]+)/g);matches&&matches.forEach(match=>{const rawColor=match.split(":").pop(),decodedColor=decodeURIComponent(rawColor.replace(/\$2520/g,"%20"));colors.includes(decodedColor)||colors.push(decodedColor)})}),colors)},getMoreToLove=()=>{const moreToLove=[],section=document.querySelector("[data-section-title='more-to-love']");return section?(section.querySelectorAll("[data-collection-id]").forEach(el=>{const collectionId=el.getAttribute("data-collection-id");moreToLove.push(collectionId)}),moreToLove):void 0},getFeaturedDresses=()=>{const featuredDresses=[],section=document.querySelector("#best-seller-panel");return section?(section.querySelectorAll(".featured-product-grid-item").forEach(el=>{const productId=el.getAttribute("data-product-id");featuredDresses.push(productId)}),featuredDresses):void 0},getActualPrice=()=>{const priceText=document.querySelector("#product-price").textContent.trim(),numericValue=parseFloat(priceText.replace(/[^0-9.]/g,""));return isNaN(numericValue)?null:numericValue},getProductionAvailability=(inventoryList,rushFee)=>{if(!Array.isArray(inventoryList))return{};const getEnabled=item=>item?.inventory>0||item?.inventory_policy==="continue",mtoItem=inventoryList.find(v=>v.shipping_details==="Standard Production"),rtsItem=inventoryList.find(v=>v.shipping_details==="Rush Production"),mtoEnabled=getEnabled(mtoItem)&&rushFee>0,rtsEnabled=getEnabled(rtsItem);return{mto_enabled:mtoEnabled,rts_enabled:rtsEnabled}},getFabric=()=>document.querySelector(".product-wrapper #fabric-legend")?.textContent.trim()||"";function getStyle(name){return name.split("-")[0].trim().split(" ")[0]}const trackNavigationClick=(type,page,link,image)=>{["nav_click","sub_nav_click"].includes(type)?gtag({event:type,eventID:getEventId(),eventData:{destinationPage:page,destinationURL:link}}):gtag({event:"sub_nav_feature_click",eventID:getEventId(),eventData:{image:processImageUrl(image),ctaText:page,ctaURL:link}})},trackAddToCart=(lineItem,cart,klaviyoProduct=null)=>{if(!lineItem)return console.error("trackAddToCart, lineItem is required"),!1;const shippingState=getLineItemShippingState(lineItem),isStorefrontCart=!0;return gtag({ecommerce:null,klaviyo_cart:null,klaviyo_product:null}),gtag({event:"add_to_cart",eventID:getEventId(),ecommerce:{currency:"USD",cartType:"THEME",cart_total:cart.total_price/100,value:lineItem.line_price/100,items:[{item_id:isStorefrontCart?parseGid(lineItem.product_id):lineItem.product_id,variant_id:isStorefrontCart?parseGid(lineItem.variant_id):lineItem.variant_id,item_variant:isStorefrontCart?parseGid(lineItem.variant_id):lineItem.variant_id,item_name:lineItem.product_title,item_options:lineItem.variant_title,item_image:lineItem.image,item_url:`${window.location.hostname}${lineItem.url}`,sku:lineItem.sku,item_brand:lineItem.vendor,item_category:lineItem.product_type,item_category2:returnCat2(lineItem.product_type),price:lineItem.price/100,compare_at_price:lineItem.original_price/100,quantity:lineItem.quantity,shipping_state:shippingState}]},klaviyo_cart:{total_price:cart.total_price/100,$value:cart.total_price/100,total_discount:cart.total_discount,original_total_price:cart.original_total_price/100,items:cart.items,AddedItemCategories:Array.from(new Set(cart.items.map(item=>item.product_type))).join(", ")},klaviyo_product:klaviyoProduct}),null},trackAddToWaitlist=(product,variant,email)=>!product||!variant?(console.error("trackAddToWaitlist, product and variant are required"),!1):(gtag({ecommerce:null,klaviyo_cart:null,klaviyo_product:null}),gtag({event:"waitlist_signup",eventID:getEventId(),ecommerce:{currency:"USD",value:variant.price/100||"",pageType:"product",items:[{item_id:product.id,variant_id:variant.id,item_variant:variant.id,item_name:variant.title,item_options:variant.title,sku:variant.sku,item_brand:product.vendor,item_category:product.type,item_category2:returnCat2(product.type),price:variant.price/100||""}]},customer:{email}}),trackIdentify(email,{klaviyo_identify:{$email:email}}),null),trackProductView=(product,variant)=>{if(!product)return console.error("trackProductView, product is required"),!1;let productImageURL=product.images[0]?.src||product.images[0];productImageURL=processImageUrl(productImageURL);const currentVariantInventory=window.productInventory?.filter(productVariant=>productVariant.size===variant.option1),inventoryDetails=variant.option3?{MTO_inventory:currentVariantInventory.find(v=>v.shipping_details==="Standard Production")?.inventory||0,RTS_inventory:currentVariantInventory.find(v=>v.shipping_details==="Rush Production")?.inventory||0}:{RTS_inventory:currentVariantInventory[0]?.inventory||0},productionAvailability=getProductionAvailability(currentVariantInventory,getRushFeePrice());return gtag({ecommerce:null,klaviyo_product:null}),gtag({event:"view_content",eventID:getEventId(),pageType:"product",ecommerce:{currency:"USD",value:product.price/100,items:[{item_id:product.id,variant_id:variant?.id,item_variant:variant?.id,item_name:escapeSingleQuote(product.title),sku:variant?.sku,item_brand:product.vendor,item_category:product.type,item_category2:returnCat2(product.type),item_category3:returnCat3(product),item_category4:returnCat4(product),price:product.price/100,compare_at_price:product.compare_at_price?product.compare_at_price/100:null,actual_price:getActualPrice()?getActualPrice():product.price/100,inventory_details:inventoryDetails,production_availability:productionAvailability,style:getStyle(variant.name),color:variant.option2,fabric:getFabric(),rush_fee_amount:getRushFeePrice()}]},klaviyo_product:{Name:product.title,ProductID:product.id,ImageURL:productImageURL,URL:`https://www.birdygrey.com/products/${product.handle}`,Brand:product.vendor.replace("'",""),Price:product.price/100,CompareAtPrice:product.compare_at_price===null?0:product.compare_at_price/100,ProductImages:product.images}}),gtag({event:"view_content_enriched",eventID:getEventId(),pageType:"product",ecommerce:{currency:"USD",value:product.price/100,items:[{item_id:product.id,variant_id:variant?.id,item_variant:variant?.id,item_name:escapeSingleQuote(product.title),sku:variant?.sku,item_brand:product.vendor,item_category:product.type,item_category2:returnCat2(product.type),item_category3:returnCat3(product),item_category4:returnCat4(product),price:product.price/100,compoare_at_price:product.compare_at_price?product.compare_at_price/100:null,inventory_details:inventoryDetails,rush_fee_price:getRushFeePrice(),color_position:getColorPosition(),number_of_images:product.images?.length||0,number_of_videos:getVideosCount(),reviews_count:getProductReviews().reviewCount,reviews_rating:getProductReviews().reviewRating,yaml_items:getSsProductIds("recommend_similar_0"),clt_items:getSsProductIds("recommend_cross-sell_0"),recently_viewed_items:getSsProductIds("recommend_recently-viewed_0")}]},klaviyo_product:{Name:product.title,ProductID:product.id,ImageURL:productImageURL,URL:`https://www.birdygrey.com/products/${product.handle}`,Brand:product.vendor.replace("'",""),Price:product.price/100,CompareAtPrice:product.compare_at_price===null?0:product.compare_at_price/100,ProductImages:product.images}}),null},trackCollectionView=(products,totalProducts,selectedSort)=>{if(!products||!Array.isArray(products))return console.error("trackCollectionView, product is required"),!1;const shipsNowProducts=document.querySelectorAll(".selling-fast:not(.none)"),ssInlineBanners=document.querySelectorAll(".ss__result--inline-banner"),allproducts=document.querySelectorAll(".ss__result"),inlinePositions=[];allproducts.forEach((product,key)=>product.classList.value.includes("ss__result--inline-banner")&&inlinePositions.push(key));const items=products.map(product=>({item_id:product.id,variant_id:product.variant_id,item_variant:product.variant_id,item_name:product.title,item_category:product.type}));return gtag({ecommerce:null}),gtag({event:"view_item_list",eventID:getEventId(),pageType:"collection",ships_now_product_count:shipsNowProducts?.length/2||0,inline_ss_banners_count:ssInlineBanners?.length||0,inline_ss_banners_positions:inlinePositions,product_sort_order:selectedSort,product_count:totalProducts||products.length||0,color_bar_order:getBarColors()||[],ecommerce:{currency:"USD",items}}),null},trackCartView=(value,lineItems)=>{const items=lineItems.map((line,index)=>({item_id:parseGid(line.product_id),variant_id:parseGid(line.variant_id),item_variant:parseGid(line.variant_id),item_name:line.title,sku:line.sku,index,item_brand:line.vendor,item_category:line.product_type,price:line.price/100,quantity:line.quantity,shipping_state:getLineItemShippingState(line)}));return gtag({ecommerce:null}),gtag({event:"view_cart",eventID:getEventId(),pageType:"cart",ecommerce:{currency:"USD",value,cart_type:"storefront",items}}),null},trackIdentify=(email,data={})=>email?(gtag({event:"identify",customer:{email},...data}),setUserData({email}),null):(console.error("trackIdentify, email is required"),!1),trackLead=(email,data={})=>{const{hostname}=window.location;if(!email)return console.error("trackLead, email is required"),!1;const eventData={customer:{email},signup_location:data.signup_location,lead:{location:data.signup_location,brand:"Birdy Grey",source:hostname.replace("www.",""),listId:data.list_id},...getAttributionData()};return gtag({event:"lead",...eventData}),trackIdentify(email,{klaviyo_identify:{$email:email}}),null},trackColorBarScroll=direction=>{gtag({event:"colorbar_scroll",eventID:getEventId(),eventData:{direction}})},trackMiniCartClick=state=>{gtag({event:"mini_cart_click",eventData:{state}})},trackMiniCartView=(value,lineItems,pageType,upsells)=>{if(!lineItems){gtag({event:"view_mini_cart",eventID:getEventId(),pageType,ecommerce:{currency:"USD",value:0}});return}const isStorefrontCart=!0,items=lineItems.map((line,index)=>({item_id:isStorefrontCart?parseGid(line.product_id):line.product_id,variant_id:isStorefrontCart?parseGid(line.variant_id):line.variant_id,item_variant:isStorefrontCart?parseGid(line.variant_id):line.variant_id,item_name:line.title,sku:line.sku,index,item_brand:line.vendor,item_category:line.product_type,price:line.price/100,quantity:line.quantity,shipping_state:getLineItemShippingState(line)}));return gtag({ecommerce:null}),gtag({event:"view_mini_cart",eventID:getEventId(),pageType,ecommerce:{currency:"USD",value,cart_type:isStorefrontCart?"storefront":"ajax",items},eventData:{upsells}}),null},publishEventToShopify=(eventName,eventData)=>{if(!eventName||!eventData)return console.error("publishEventToShopify, eventData or eventName is missing"),!1;if(!window.Shopify||!window.Shopify.analytics)return console.error("publishEventToShopify, Shopify.analytics is not available"),!1;try{const userData=getUserData();window.Shopify.analytics.publish(eventName,{...eventData,customer:{...userData}})}catch(error){console.error(`publishEventToShopify, error for ${eventName}`,error)}return null},trackHomepageView=()=>{gtag({event:"homepage_view",eventID:getEventId(),eventData:{color_bar_order:getBarColors("homepage")||[],more_to_love_order:getMoreToLove()||[],featured_dresses:getFeaturedDresses()||[]}})},trackMoreToLoveClick=()=>{document.querySelector("[data-section-title='more-to-love']").querySelectorAll("[data-collection-id]").forEach(collection=>{collection.querySelector("a").addEventListener("click",()=>{const item_id=collection.getAttribute("data-collection-id"),item_title=collection.getAttribute("data-collection-title"),item_featured_image=collection.getAttribute("data-collection-image"),item_url=collection.getAttribute("data-collection-url"),item={item_id,item_title,item_featured_image,item_url};gtag({event:"more_to_love_click",eventID:getEventId(),ecommerce:{item}})})})},trackSearch=results=>{const items=results.map(product=>({product_id:product.id,product_name:product.mappings.core.name,product_price:product.mappings.core.price,product_sku:product.mappings.core.sku}));gtag({event:"view_search_suggestions",eventID:getEventId(),ecommerce:{items}})},trackSearchSuggestionsClick=product=>{const item={product_id:product.id,product_name:product.mappings.core.name,product_price:product.mappings.core.price,product_sku:product.mappings.core.sku};gtag({event:"search_suggestion_click",eventID:getEventId(),ecommerce:{item}})},trackPopularSearchesClick=term=>{gtag({event:"popular_searches_click",eventID:getEventId(),term})},trackSeeMoreClick=term=>{gtag({event:"search_see_more_click",eventID:getEventId(),term})},trackOrderView=(orderItems,expectedDelivery)=>{const items=orderItems.map(item=>{const mtoProperty=item.properties?.find(prop=>prop.name==="_MADE-TO-ORDER");return{item_id:item.product_id,variant_id:item.variant_id,item_name:item.title,sku:item.sku,price:item.price,...mtoProperty&&{promised_by_date:mtoProperty.value,expected_delivery:expectedDelivery||mtoProperty.value}}});gtag({event:"tracking_page_view",eventID:getEventId(),ecommerce:{items}})},trackBridePhoneNaClick=value=>{gtag({event:"bride_form_na_click",eventData:{state:value?"checked":"unchecked"}})}; //# sourceMappingURL=/cdn/shop/t/2918/assets/util--gtm.js.map