
var ws=document.currentScript;(function(window){let serviceDomain=getParameterValueByName('sd',ws.src)||new URL(ws.src).hostname||'cartsync-ui.revivalanimal.com';let autoInit=getParameterValueByName('auto-initialize',ws.src)==='true';let provider=getParameterValueByName('provider',ws.src);var cs_token='';if(!window.CartSync)
window.CartSync=window.CartSync||{};let Events=function(){var self=this;const options={"Provider":"BigCommerce","TargetPages":{"Product":"https://www.revivalanimal.com/product/","Category":"https://www.revivalanimal.com/category/","Cart":"https://www.revivalanimal.com/cart","Confirmation":"https://www.revivalanimal.com/checkout/success?i="},"Events":[{"Name":"ProductCards_AddToCart","EventType":"ProductAddedToCart","Action":"Click","Selectors":"button[class^='ProductCardCartSync_addToCartButton']","Values":[{"Name":"ProductSku","Selector":"div[class^='ProductCardCartSync_productId']","ValueSource":"text"},{"Name":"ProviderCartId","Selector":"cookie:bc_cartId","ValueSource":"text"}],"Delay":1000}],"CustomerData":{"Email":{"Selector":".login-status","ValueSource":"attribute:data-e"},"ProviderId":{"Selector":".login-status","ValueSource":"attribute:data-id"}},"ProductData":{"Container":"#product-global-info","SKU":{"Selector":"div[class*='ProductDataSection_selected'] h2.value.sku","ValueSource":"text"},"Name":{"Selector":"h1.item-name","ValueSource":"text"},"Price":{"Selector":"div[class*='ProductDataSection_selected'] .value-main-price","ValueSource":"text"},"SalePrice":{"Selector":".final-price","ValueSource":"text"},"Quantity":{"Selector":"input.item-quantity","ValueSource":"value"},"ProviderId":{"Selector":"","ValueSource":"text"},"Events":[{"Name":"AddToCart","EventType":"ProductAddedToCart","Action":"Click","Selectors":"[class^='ProductDataSection_addToCartButton']"},{"Name":"VariantSelected","EventType":"InitializeProduct","Action":"Click","Selectors":"[class^='ProductDataSection_variantChip']","Callback":""}],"Delay":1250},"CategoryData":{"Name":{"Selector":"h1.headline","ValueSource":"text"},"Path":{"Selector":"div.breadcrumb","ValueSource":"text"},"ProviderId":{"Selector":".category-info","ValueSource":"attribute:data-id"},"Delay":750},"CartData":{"ItemContainer":"div[class^='cart_cartProductContainer']","Item":{"Name":{"Selector":".item-name","ValueSource":"text"},"SKU":{"Selector":".item-sku","ValueSource":"text"},"Price":{"Selector":".standard-price","ValueSource":"text"},"SalePrice":{"Selector":".sale-price","ValueSource":"text"},"Quantity":{"Selector":".item-quantity","ValueSource":"value"}},"Subtotal":{"Selector":".cart-subtotal","ValueSource":"text"},"ProviderId":{"Selector":"cookie:bc_cartId","ValueSource":"text"},"Delay":1900},"OrderData":{"ProviderId":{"Selector":".order-id","ValueSource":"text"},"ItemContainer":"div[class^='OrderProduct_root']","Item":{"Name":{"Selector":".item-name","ValueSource":"text"},"SKU":{"Selector":".item-sku","ValueSource":"text"},"Price":{"Selector":".standard-price","ValueSource":"text"},"SalePrice":{"Selector":".sale-price","ValueSource":"text"},"Quantity":{"Selector":".item-quantity","ValueSource":"text"}},"CustomerEmail":{"Selector":".customer-email","ValueSource":"text"},"Subtotal":{"Selector":".order-subtotal","ValueSource":"text"},"Total":{"Selector":".order-total","ValueSource":"text"},"Delay":2500}};self.Provider=provider||options.Provider;function getProduct(options,alternativeContainerSelector,sender){let pContainer=null;if(sender){pContainer=sender.closest(alternativeContainerSelector?alternativeContainerSelector:options.ProductData.Container);}else{pContainer=(alternativeContainerSelector?document.querySelector(alternativeContainerSelector):document.querySelector(options.ProductData.Container));}
let result=null;if(pContainer){let sku=getValue(pContainer.querySelector(options.ProductData.SKU.Selector),options.ProductData.SKU.ValueSource);let price=parseFloat(getValue(pContainer.querySelector(options.ProductData.Price.Selector),options.ProductData.Price.ValueSource,'0.00').replace('$',''));let salePrice=parseFloat(getValue(pContainer.querySelector(options.ProductData.SalePrice.Selector),options.ProductData.SalePrice.ValueSource,'0.00').replace('$',''));let name=getValue(pContainer.querySelector(options.ProductData.Name.Selector),options.ProductData.Name.ValueSource);let quantity=parseInt(getValue(pContainer.querySelector(options.ProductData.Quantity.Selector),options.ProductData.Quantity.ValueSource,'1'));result=new window.CartSync.Product();result.Sku=sku;result.Price=price;result.SalePrice=salePrice;result.Quantity=quantity;result.Name=name;}
return result;}
function getCart(options){let result=null;let itemRows=document.querySelectorAll(options.CartData.ItemContainer);if(itemRows){let cartItems=[];for(var i=0;i<itemRows.length;i++){let sku=getValue(itemRows[i].querySelector(options.CartData.Item.SKU.Selector),options.CartData.Item.SKU.ValueSource).replace('#','');let price=parseFloat(getValue(itemRows[i].querySelector(options.CartData.Item.Price.Selector),options.CartData.Item.Price.ValueSource,'0.00').replace('$',''));let salePrice=price;let name=getValue(itemRows[i].querySelector(options.CartData.Item.Name.Selector),options.CartData.Item.Name.ValueSource);let quantity=parseInt(getValue(itemRows[i].querySelector(options.CartData.Item.Quantity.Selector),options.CartData.Item.Quantity.ValueSource,'1'));cartItems.push({Sku:sku,Price:price,SalePrice:salePrice,Quantity:quantity,Name:name});}
result={Subtotal:parseFloat(getValue(document.querySelector(options.CartData.Subtotal.Selector),options.CartData.Subtotal.ValueSource,'0.00').replace('$','')),Items:cartItems,ProviderId:getValue(options.CartData.ProviderId.Selector,options.CartData.ProviderId.ValueSource)}}else{let providerId=getValue(options.CartData.ProviderId.Selector,options.CartData.ProviderId.ValueSource);if(providerId){return{ProviderId:provider}}}
return result;}
function getOrder(options){let result=null;let itemRows=document.querySelectorAll(options.OrderData.ItemContainer);if(itemRows){let orderItems=[];for(var i=0;i<itemRows.length;i++){let sku=getValue(itemRows[i].querySelector(options.OrderData.Item.SKU.Selector),options.OrderData.Item.SKU.ValueSource).replace('#','');let price=parseFloat(getValue(itemRows[i].querySelector(options.OrderData.Item.Price.Selector),options.OrderData.Item.Price.ValueSource,'0.00').replace('$',''));let salePrice=price;let name=getValue(itemRows[i].querySelector(options.OrderData.Item.Name.Selector),options.OrderData.Item.Name.ValueSource);let quantity=parseInt(getValue(itemRows[i].querySelector(options.OrderData.Item.Quantity.Selector),options.OrderData.Item.Quantity.ValueSource,'1'));orderItems.push({Sku:sku,Price:price,SalePrice:salePrice,Quantity:quantity,Name:name});}
result={ProviderId:getValue(document.querySelector(options.OrderData.ProviderId.Selector),options.OrderData.ProviderId.ValueSource),CustomerEmail:getValue(document.querySelector(options.OrderData.CustomerEmail.Selector),options.OrderData.CustomerEmail.ValueSource),Subtotal:parseFloat(getValue(document.querySelector(options.OrderData.Subtotal.Selector),options.OrderData.Subtotal.ValueSource,'0.00').replace('$','')),Items:orderItems}}
return result;}
function getCategory(options){let result=null;let name=getValue(document.querySelector(options.CategoryData.Name.Selector),options.CategoryData.Name.ValueSource);let path=getValue(document.querySelector(options.CategoryData.Path.Selector),options.CategoryData.Path.ValueSource);let providerId=getValue(document.querySelector(options.CategoryData.ProviderId.Selector),options.CategoryData.ProviderId.ValueSource);result={Name:name,Path:path,ProviderId:providerId}
return result;}
function getValue(source,sourceValue,blankValue){if(source){if(isElement(source)){if(sourceValue==='value'){return source.value;}else if(sourceValue.startsWith('attribute:')){let attributeData=sourceValue.split(':');return source.getAttribute(attributeData[1]);}else{return source.innerText;}}else if(source.startsWith('cookie:')){let cookieData=source.split(':');return trackingGetCookieValueByName(cookieData[1]);}}
if(!blankValue){blankValue='';}
return blankValue;}
function isElement(element){return element instanceof Element||element instanceof HTMLDocument;}
function be(el,et){try{let source=el||document.querySelector('body');if(source!=undefined){var tr=new event();tr.EventType=et;var href=(source.href||'');if(tr.ElementId==undefined||tr.ElementId==null||tr.ElementId.length<1){tr.ElementId=source.getAttribute('id')||source.getAttribute('element-id')||'';}
tr.ElementXPath=Xpath.getElementXPath(el);tr.ElementContent=source.outerHTML;tr.WidgetId=(source.getAttribute('cartsync-content-widget')||source.getAttribute('cartsync-list-widget')||source.getAttribute('cartsync-dynamic-widget')||'');if(tr.WidgetId==undefined||tr.WidgetId==null||tr.WidgetId.length==0){var parentCartSyncWidget=source.closest('[cartsync-content-widget]')||source.closest('[cartsync-list-widget]')||source.closest('[cartsync-dynamic-widget]');if(parentCartSyncWidget)
tr.WidgetId=parentCartSyncWidget.getAttribute('cartsync-content-widget')||parentCartSyncWidget.getAttribute('cartsync-list-widget')||parentCartSyncWidget.getAttribute('cartsync-dynamic-widget')||'';}
tr.TotalValue=(source.getAttribute('cartsync-value')||null);tr.Group=(source.getAttribute('cartsync-ad-group')||getParameterValueByName('utm_source',href)||'');tr.Version=(source.getAttribute('cartsync-ad-version')||'');tr.Campaign=(source.getAttribute('cartsync-ad-campaign')||getParameterValueByName('utm_campaign',href)||'');tr.ValueSource=(getParameterValueByName('utm_source',href)||'');tr.Medium=(getParameterValueByName('utm_medium',href)||'');tr.Term=(getParameterValueByName('utm_term',href)||'');tr.Content=(getParameterValueByName('utm_content',href)||'');return tr;}}catch(er){console.log(er);}
return null;}
function le(event){var t=trackingGetCookieValueByName("cartsync-session-token");if(t!==null&&t!==undefined){event.SessionToken=t;event.Referrer=document.referrer;event.Url=window.location.href;if(event!==undefined&&event!==null&&event.SessionToken!==undefined){signEvent(event,options);var request=new remoteRequest('https://'+serviceDomain+'/api/Engagement/TrackEventAsync',"POST",event);request.onreadystatechange=()=>{if(request.readyState==4){if(request.status==200){if(request.response){var data=JSON.parse(request.responseText);if(data){console.log('event submitted');}}}}}}}}
function remoteRequest(url,method,data){var request=new XMLHttpRequest();request.open(method,url,true);request.withCredentials=true;request.setRequestHeader('Content-Type','application/json');request.setRequestHeader('Accept','*/*');let serializedData=JSON.stringify(data);request.send(serializedData);return request;}
function event(){this.EventType='';this.ElementId='';this.ElementXPath='';this.WidgetId='';this.SessionToken='';this.ElementContent='';this.Content='';this.Campaign='';this.ValueSource='';this.Term='';this.Medium='';this.Group='';this.Version='';this.AdditionalData=[];this.CustomerEmail='';this.ProviderCustomerId='';this.ProductSku='';this.ProviderOrderId='';this.ProviderCartId='';this.Url='';this.Platform='';}
function nameValue(){this.name='';this.value='';}
function initializeProduct(options){setTimeout(()=>{const product=getProduct(options);let productViewedEvent=be(document.querySelector(options.ProductData.Container),'ProductViewed');let productData=new nameValue();productData.name="Product";productData.value=JSON.stringify(product);productViewedEvent.ProductSku=productData.Sku;productViewedEvent.AdditionalData.push(productData);le(productViewedEvent);if(options.ProductData.Events){options.ProductData.Events.forEach((event)=>{let targetElements=document.querySelectorAll(event.Selectors);if(targetElements){targetElements.forEach((el)=>{if(event.Action.toLowerCase()==='click'){el.addEventListener("click",(el)=>{if(event.EventType){if(event.EventType==="InitializeProduct"){initializeProduct(options);}else if(event.EventType==="ProductAddedToCart"){let addToCartEvent=be(el.currentTarget,event.EventType);if(options.TargetPages.Product&&window.location.href.startsWith(options.TargetPages.Product)){const product=getProduct(options,null,el.currentTarget);addToCartEvent.TotalValue=product.SalePrice*parseFloat(product.Quantity);addToCartEvent.ProductSku=product.Sku;let productData=new nameValue();productData.name="Product";productData.value=JSON.stringify(product);let cart=getCart(options);if(cart){addToCartEvent.ProviderCartId=cart.ProviderId}
addToCartEvent.AdditionalData.push(productData);}else{addToCartEvent.ProductSku=getValue(el.currentTarget.closest(options.ProductData.Container).querySelector(options.ProductData.SKU.Selector),options.ProductData.SKU.ValueSource);}
le(addToCartEvent);}}
if(event.Callback){if(typeof window[event.Callback]==="function"){window[event.Callback](options);}}});}});}});}},options.ProductData.Delay);}
function signEvent(event,options){if(event&&options){event.Platform=options.Provider;if(!event.CustomerEmail){let customerEmailFromPage=getValue(document.querySelector(options.CustomerData.Email.Selector),options.CustomerData.Email.ValueSource);event.CustomerEmail=customerEmailFromPage;}
if(!event.ProviderCustomerId){let customerProviderIdFromPage=getValue(document.querySelector(options.CustomerData.ProviderId.Selector),options.CustomerData.ProviderId.ValueSource);event.ProviderCustomerId=customerProviderIdFromPage;}}}
var Xpath={};Xpath.getElementXPath=function(element){if(element&&element.id)
return'//*[@id="'+element.id+'"]';else
return Xpath.getElementTreeXPath(element);};Xpath.getElementTreeXPath=function(element){var paths=[];for(;element&&element.nodeType==Node.ELEMENT_NODE;element=element.parentNode){var index=0;var hasFollowingSiblings=false;for(var sibling=element.previousSibling;sibling;sibling=sibling.previousSibling){if(sibling.nodeType==Node.DOCUMENT_TYPE_NODE)
continue;if(sibling.nodeName==element.nodeName)
++index;}
for(var sibling=element.nextSibling;sibling&&!hasFollowingSiblings;sibling=sibling.nextSibling){if(sibling.nodeName==element.nodeName)
hasFollowingSiblings=true;}
var tagName=(element.prefix?element.prefix+":":"")+element.localName;var pathIndex=(index||hasFollowingSiblings?"["+(index+1)+"]":"");paths.splice(0,0,tagName+pathIndex);}
return paths.length?"/"+paths.join("/"):null;};self.initialize=function(){let eventTracker=this;console.log(`CartSync Events Script Called ${Date.now()}`);setTimeout(()=>{var page_view=new event();page_view.EventType='PageViewed';le(page_view);},1000);if(options){if(options.TargetPages.Product&&window.location.href.startsWith(options.TargetPages.Product)){initializeProduct(options);}
if(options.TargetPages.Category&&window.location.href.startsWith(options.TargetPages.Category)){setTimeout(()=>{let categoryViewedEvent=be(document.querySelector(options.CategoryData.Container),'CategoryViewed');let categoryData=new nameValue();categoryData.name="Category";categoryData.value=JSON.stringify(getCategory(options));categoryViewedEvent.AdditionalData.push(categoryData);le(categoryViewedEvent);},options.CategoryData.Delay);}
if(options.TargetPages.Cart&&window.location.href.startsWith(options.TargetPages.Cart)){setTimeout(()=>{let checkoutStartedEvent=be(document.querySelector(options.CartData.ItemContainer),'CheckoutStarted');let cart=getCart(options);let cartData=new nameValue();cartData.name="Cart";cartData.value=JSON.stringify(cart);checkoutStartedEvent.AdditionalData.push(cartData);checkoutStartedEvent.ProviderCartId=cart.ProviderId;le(checkoutStartedEvent);},options.CartData.Delay);}
if(options.TargetPages.Confirmation&&window.location.href.startsWith(options.TargetPages.Confirmation)){setTimeout(()=>{let orderPlacedEvent=be(document.querySelector(options.ProductData.Container),'OrderPlaced');let order=getOrder(options);let orderData=new nameValue();orderData.name="Order";orderData.value=JSON.stringify(order);orderPlacedEvent.AdditionalData.push(orderData);orderPlacedEvent.CustomerEmail=order.CustomerEmail;orderPlacedEvent.ProviderOrderId=order.ProviderId;le(orderPlacedEvent);},options.OrderData.Delay);}
if(options.Events){options.Events.forEach((targetEvent)=>{setTimeout(()=>{const targetElementsToBind=document.querySelectorAll(targetEvent.Selectors);if(targetElementsToBind){targetElementsToBind.forEach((targetElementToBind)=>{targetElementToBind.addEventListener(targetEvent.Action.toLowerCase()||"click",(btn)=>{let trackedEvent=be(btn.currentTarget,targetEvent.EventType);if(targetEvent.Values){targetEvent.Values.forEach((targetValueOption)=>{if(targetValueOption.Name&&targetValueOption.Selector){let targetValueElement=null;try{targetValueElement=document.querySelector(targetValueOption.Selector);}catch(err){console.log('The global events target is not a valid element. Please correct or ignore if this is expected.');}
const targetValue=getValue(targetValueElement||targetValueOption.Selector,targetValueOption.ValueSource);if(Object.hasOwn(trackedEvent,targetValueOption.Name)){trackedEvent[targetValueOption.Name]=targetValue;}else{let customData=new nameValue();customData.name=targetValueOption.Name;customData.value=JSON.stringify(targetValue);trackedEvent.AdditionalData.push(customData);}}});}
le(trackedEvent);});});}},targetEvent.Delay||100);});}}
function ti(selector){document.querySelectorAll(selector).forEach(function(element){var event=new Event('TrackedImpression');element.dispatchEvent(event);});}
window.onerror=function(message,source,lineno,colno,error){var errEvent=new event();errEvent.EventType='SiteError';var errDetails=new nameValue();errDetails.name="Details";var er=(error||[]);var message=['Message: '+message,'URL: '+(source||''),'Line: '+(lineno||''),'Column: '+(colno||''),'Error object: '+JSON.stringify(er)].join(' - ');errDetails.value=JSON.stringify(message);errEvent.AdditionalData.push(errDetails);le(errEvent);return false;};var links=document.getElementsByTagName('a');for(var i=0;i<links.length;i++){if(links[i].href!=undefined){links[i].addEventListener("click",function(){var event=be(this,'LinkClicked');le(event);});}}
const prevLocation=document.location.href;const elementToObserve=document.querySelector('body');const documentObserver=new MutationObserver((mutation)=>{if(prevLocation!=document.location.href){documentObserver.disconnect();window.CartSync.Events.initialize();}});documentObserver.observe(elementToObserve,{subtree:true,childList:true});}
self.push=(eventType,eventTitle,eventData,customerEmail,value,widget)=>{var ev=new event();ev.eventTitle=eventTitle;ev.EventType=eventType;ev.AdditionalData.push(eventData);ev.CustomerEmail=customerEmail;ev.TotalValue=value;if(widget){ev.WidgetId=widget.widgetKey;}
le(ev);};}
function trackingGetCookieValueByName(cname){var name=cname+"=";var decodedCookie=decodeURIComponent(document.cookie);var ca=decodedCookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1);if(c.indexOf(name)==0){return c.substring(name.length,c.length);}}
return"";}
function getParameterValueByName(name,url){if(!url){url=window.location.href;}
name=name.replace(/[\[\]]/g,"\\$&");var regex=new RegExp("[?&]"+name+"(=([^&#]*)|&|#|$)"),results=regex.exec(url);if(!results)return null;if(!results[2])return'';return decodeURIComponent(results[2].replace(/\+/g," "));}
window.CartSync.Events=new Events();window.CartSync.Product=function(){this.Sku='';this.Price=0.00;this.SalePrice=0.00;this.Quantity=0;this.Name='';}
if(document.readyState=="complete"||(document.readyState!=="loading"&&!document.documentElement.doScroll)){window.CartSync.Events.initialize();}else{document.addEventListener("DOMContentLoaded",window.CartSync.Events.initialize);}})(window);