(()=>{"use strict";var e={857:e=>{var t=function(e){var t;return!!e&&"object"==typeof e&&"[object RegExp]"!==(t=Object.prototype.toString.call(e))&&"[object Date]"!==t&&e.$$typeof!==n},n="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function i(e,t){return!1!==t.clone&&t.isMergeableObject(e)?a(Array.isArray(e)?[]:{},e,t):e}function r(e,t,n){return e.concat(t).map(function(e){return i(e,n)})}function o(e){return Object.keys(e).concat(Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter(function(t){return Object.propertyIsEnumerable.call(e,t)}):[])}function s(e,t){try{return t in e}catch(e){return!1}}function a(e,n,c){(c=c||{}).arrayMerge=c.arrayMerge||r,c.isMergeableObject=c.isMergeableObject||t,c.cloneUnlessOtherwiseSpecified=i;var d,l,u=Array.isArray(n);return u!==Array.isArray(e)?i(n,c):u?c.arrayMerge(e,n,c):(l={},(d=c).isMergeableObject(e)&&o(e).forEach(function(t){l[t]=i(e[t],d)}),o(n).forEach(function(t){(!s(e,t)||Object.hasOwnProperty.call(e,t)&&Object.propertyIsEnumerable.call(e,t))&&(s(e,t)&&d.isMergeableObject(n[t])?l[t]=(function(e,t){if(!t.customMerge)return a;var n=t.customMerge(e);return"function"==typeof n?n:a})(t,d)(e[t],n[t],d):l[t]=i(n[t],d))}),l)}a.all=function(e,t){if(!Array.isArray(e))throw Error("first argument should be an array");return e.reduce(function(e,n){return a(e,n,t)},{})},e.exports=a}},t={};function n(i){var r=t[i];if(void 0!==r)return r.exports;var o=t[i]={exports:{}};return e[i](o,o.exports,n),o.exports}(()=>{n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t}})(),(()=>{n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})}})(),(()=>{n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})(),(()=>{var e=n(857);class t{static ucFirst(e){return e.charAt(0).toUpperCase()+e.slice(1)}static lcFirst(e){return e.charAt(0).toLowerCase()+e.slice(1)}static toDashCase(e){return e.replace(/([A-Z])/g,"-$1").replace(/^-/,"").toLowerCase()}static toLowerCamelCase(e,n){let i=t.toUpperCamelCase(e,n);return t.lcFirst(i)}static toUpperCamelCase(e,n){return n?e.split(n).map(e=>t.ucFirst(e.toLowerCase())).join(""):t.ucFirst(e.toLowerCase())}static parsePrimitive(e){try{return/^\d+(.|,)\d+$/.test(e)&&(e=e.replace(",",".")),JSON.parse(e)}catch(t){return e.toString()}}}class i{static isNode(e){return"object"==typeof e&&null!==e&&(e===document||e===window||e instanceof Node)}static hasAttribute(e,t){if(!i.isNode(e))throw Error("The element must be a valid HTML Node!");return"function"==typeof e.hasAttribute&&e.hasAttribute(t)}static getAttribute(e,t){let n=!(arguments.length>2)||void 0===arguments[2]||arguments[2];if(n&&!1===i.hasAttribute(e,t))throw Error('The required property "'.concat(t,'" does not exist!'));if("function"!=typeof e.getAttribute){if(n)throw Error("This node doesn't support the getAttribute function!");return}return e.getAttribute(t)}static getDataAttribute(e,n){let r=!(arguments.length>2)||void 0===arguments[2]||arguments[2],o=n.replace(/^data(|-)/,""),s=t.toLowerCamelCase(o,"-");if(!i.isNode(e)){if(r)throw Error("The passed node is not a valid HTML Node!");return}if(void 0===e.dataset){if(r)throw Error("This node doesn't support the dataset attribute!");return}let a=e.dataset[s];if(void 0===a){if(r)throw Error('The required data attribute "'.concat(n,'" does not exist on ').concat(e,"!"));return a}return t.parsePrimitive(a)}static querySelector(e,t){let n=!(arguments.length>2)||void 0===arguments[2]||arguments[2];if(n&&!i.isNode(e))throw Error("The parent node is not a valid HTML Node!");let r=e.querySelector(t)||!1;if(n&&!1===r)throw Error('The required element "'.concat(t,'" does not exist in parent node!'));return r}static querySelectorAll(e,t){let n=!(arguments.length>2)||void 0===arguments[2]||arguments[2];if(n&&!i.isNode(e))throw Error("The parent node is not a valid HTML Node!");let r=e.querySelectorAll(t);if(0===r.length&&(r=!1),n&&!1===r)throw Error('At least one item of "'.concat(t,'" must exist in parent node!'));return r}}class r{publish(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=new CustomEvent(e,{detail:t,cancelable:n});return this.el.dispatchEvent(i),i}subscribe(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=this,r=e.split("."),o=n.scope?t.bind(n.scope):t;if(n.once&&!0===n.once){let t=o;o=function(n){i.unsubscribe(e),t(n)}}return this.el.addEventListener(r[0],o),this.listeners.push({splitEventName:r,opts:n,cb:o}),!0}unsubscribe(e){let t=e.split(".");return this.listeners=this.listeners.reduce((e,n)=>([...n.splitEventName].sort().toString()===t.sort().toString()?this.el.removeEventListener(n.splitEventName[0],n.cb):e.push(n),e),[]),!0}reset(){return this.listeners.forEach(e=>{this.el.removeEventListener(e.splitEventName[0],e.cb)}),this.listeners=[],!0}get el(){return this._el}set el(e){this._el=e}get listeners(){return this._listeners}set listeners(e){this._listeners=e}constructor(e=document){this._el=e,e.$emitter=this,this._listeners=[]}}class o{static isSupported(){return"undefined"!==document.cookie}static setItem(e,t,n){if(null==e)throw Error("You must specify a key to set a cookie");let i=new Date;i.setTime(i.getTime()+864e5*n);let r="";"https:"===location.protocol&&(r="secure"),document.cookie="".concat(e,"=").concat(t,";expires=").concat(i.toUTCString(),";path=/;sameSite=lax;").concat(r)}static getItem(e){if(!e)return!1;let t=e+"=",n=document.cookie.split(";");for(let e=0;e<n.length;e++){let i=n[e];for(;" "===i.charAt(0);)i=i.substring(1);if(0===i.indexOf(t))return i.substring(t.length,i.length)}return!1}static removeItem(e){document.cookie="".concat(e,"= ; expires = Thu, 01 Jan 1970 00:00:00 GMT;path=/")}static key(){return""}static clear(){}}class s{static isTouchDevice(){return"ontouchstart"in document.documentElement}static isIOSDevice(){return s.isIPhoneDevice()||s.isIPadDevice()}static isNativeWindowsBrowser(){return s.isIEBrowser()||s.isEdgeBrowser()}static isIPhoneDevice(){return!!navigator.userAgent.match(/iPhone/i)}static isIPadDevice(){return!!navigator.userAgent.match(/iPad/i)}static isIEBrowser(){return -1!==navigator.userAgent.toLowerCase().indexOf("msie")||!!navigator.userAgent.match(/Trident.*rv:\d+\./)}static isEdgeBrowser(){return!!navigator.userAgent.match(/Edge\/\d+/i)}static getList(){return{"is-touch":s.isTouchDevice(),"is-ios":s.isIOSDevice(),"is-native-windows":s.isNativeWindowsBrowser(),"is-iphone":s.isIPhoneDevice(),"is-ipad":s.isIPadDevice(),"is-ie":s.isIEBrowser(),"is-edge":s.isEdgeBrowser()}}}class a{static iterate(e,t){if(e instanceof Map||Array.isArray(e))return e.forEach(t);if(e instanceof FormData){for(var n of e.entries())t(n[1],n[0]);return}if(e instanceof NodeList)return e.forEach(t);if(e instanceof HTMLCollection)return Array.from(e).forEach(t);if(e instanceof Object)return Object.keys(e).forEach(n=>{t(e[n],n)});throw Error("The element type ".concat(typeof e," is not iterable!"))}}let c="offcanvas";class d{open(e,t,n,i,r,o,s){this._removeExistingOffCanvas();let a=this._createOffCanvas(n,o,s,i);this.setContent(e,i,r),this._openOffcanvas(a,t)}setContent(e,t){let n=this.getOffCanvas();n[0]&&(n[0].innerHTML=e,this._registerEvents(t))}setAdditionalClassName(e){this.getOffCanvas()[0].classList.add(e)}getOffCanvas(){return document.querySelectorAll(".".concat(c))}close(e){let t=this.getOffCanvas();a.iterate(t,e=>{bootstrap.Offcanvas.getInstance(e).hide()}),setTimeout(()=>{this.$emitter.publish("onCloseOffcanvas",{offCanvasContent:t})},e)}goBackInHistory(){window.history.back()}exists(){return this.getOffCanvas().length>0}_openOffcanvas(e,t){d.bsOffcanvas.show(),window.history.pushState("offcanvas-open",""),"function"==typeof t&&t()}_registerEvents(e){let t=s.isTouchDevice()?"touchend":"click",n=this.getOffCanvas();a.iterate(n,t=>{let i=()=>{setTimeout(()=>{t.remove(),this.$emitter.publish("onCloseOffcanvas",{offCanvasContent:n})},e),t.removeEventListener("hide.bs.offcanvas",i)};t.addEventListener("hide.bs.offcanvas",i)}),window.addEventListener("popstate",this.close.bind(this,e),{once:!0});let i=document.querySelectorAll(".".concat("js-offcanvas-close"));a.iterate(i,n=>n.addEventListener(t,this.close.bind(this,e)))}_removeExistingOffCanvas(){d.bsOffcanvas=null;let e=this.getOffCanvas();return a.iterate(e,e=>e.remove())}_getPositionClass(e){return"left"===e?"offcanvas-start":"right"===e?"offcanvas-end":"offcanvas-".concat(e)}_createOffCanvas(e,t,n,i){let r=document.createElement("div");if(r.classList.add(c),r.classList.add(this._getPositionClass(e)),!0===t&&r.classList.add("is-fullwidth"),n){let e=typeof n;if("string"===e)r.classList.add(n);else if(Array.isArray(n))n.forEach(e=>{r.classList.add(e)});else throw Error('The type "'.concat(e,'" is not supported. Please pass an array or a string.'))}return document.body.appendChild(r),d.bsOffcanvas=new bootstrap.Offcanvas(r,{backdrop:!1!==i||"static"}),r}constructor(){this.$emitter=new r}}let l=Object.freeze(new d);class u{static open(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"left",i=!(arguments.length>3)||void 0===arguments[3]||arguments[3],r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:350,o=arguments.length>5&&void 0!==arguments[5]&&arguments[5],s=arguments.length>6&&void 0!==arguments[6]?arguments[6]:"";l.open(e,t,n,i,r,o,s)}static setContent(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:350;l.setContent(e,t,n)}static setAdditionalClassName(e){l.setAdditionalClassName(e)}static close(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:350;l.close(e)}static exists(){return l.exists()}static getOffCanvas(){return l.getOffCanvas()}static REMOVE_OFF_CANVAS_DELAY(){return 350}}class h{get(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"application/json",i=this._createPreparedRequest("GET",e,n);return this._sendRequest(i,null,t)}post(e,t,n){let i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"application/json";i=this._getContentType(t,i);let r=this._createPreparedRequest("POST",e,i);return this._sendRequest(r,t,n)}delete(e,t,n){let i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"application/json";i=this._getContentType(t,i);let r=this._createPreparedRequest("DELETE",e,i);return this._sendRequest(r,t,n)}patch(e,t,n){let i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"application/json";i=this._getContentType(t,i);let r=this._createPreparedRequest("PATCH",e,i);return this._sendRequest(r,t,n)}abort(){if(this._request)return this._request.abort()}_registerOnLoaded(e,t){t&&e.addEventListener("loadend",()=>{t(e.responseText,e)})}_sendRequest(e,t,n){return this._registerOnLoaded(e,n),e.send(t),e}_getContentType(e,t){return e instanceof FormData&&(t=!1),t}_createPreparedRequest(e,t,n){return this._request=new XMLHttpRequest,this._request.open(e,t),this._request.setRequestHeader("X-Requested-With","XMLHttpRequest"),n&&this._request.setRequestHeader("Content-type",n),this._request}constructor(){this._request=null}}let g="loader",v={BEFORE:"before",INNER:"inner"};class m{create(){if(!this.exists()){if(this.position===v.INNER){this.parent.innerHTML=m.getTemplate();return}this.parent.insertAdjacentHTML(this._getPosition(),m.getTemplate())}}remove(){let e=this.parent.querySelectorAll(".".concat(g));a.iterate(e,e=>e.remove())}exists(){return this.parent.querySelectorAll(".".concat(g)).length>0}_getPosition(){return this.position===v.BEFORE?"afterbegin":"beforeend"}static getTemplate(){return'<div class="'.concat(g,'" role="status">\n                    <span class="').concat("visually-hidden",'">Loading...</span>\n                </div>')}static SELECTOR_CLASS(){return g}constructor(e,t=v.BEFORE){this.parent=e instanceof Element?e:document.body.querySelector(e),this.position=t}}let p=null;class f extends u{static open(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"left",r=!(arguments.length>4)||void 0===arguments[4]||arguments[4],o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:u.REMOVE_OFF_CANVAS_DELAY(),s=arguments.length>6&&void 0!==arguments[6]&&arguments[6],a=arguments.length>7&&void 0!==arguments[7]?arguments[7]:"";if(!e)throw Error("A url must be given!");l._removeExistingOffCanvas();let c=l._createOffCanvas(i,s,a,r);this.setContent(e,t,n,r,o),l._openOffcanvas(c)}static setContent(e,t,n,i,r){let o=new h;super.setContent('<div class="offcanvas-body">'.concat(m.getTemplate(),"</div>"),i,r),p&&p.abort();let s=e=>{super.setContent(e,i,r),"function"==typeof n&&n(e)};p=t?o.post(e,t,f.executeCallback.bind(this,s)):o.get(e,f.executeCallback.bind(this,s))}static executeCallback(e,t){"function"==typeof e&&e(t),window.PluginManager.initializePlugins()}}let b="element-loader-backdrop";class E extends m{static create(e){e.classList.add("has-element-loader"),E.exists(e)||(E.appendLoader(e),setTimeout(()=>{let t=e.querySelector(".".concat(b));t&&t.classList.add("element-loader-backdrop-open")},1))}static remove(e){e.classList.remove("has-element-loader");let t=e.querySelector(".".concat(b));t&&t.remove()}static exists(e){return e.querySelectorAll(".".concat(b)).length>0}static getTemplate(){return'\n        <div class="'.concat(b,'">\n            <div class="loader" role="status">\n                <span class="').concat("visually-hidden",'">Loading...</span>\n            </div>\n        </div>\n        ')}static appendLoader(e){e.insertAdjacentHTML("beforeend",E.getTemplate())}}window.router["frontend.cookie.offcanvas"];class y{static log(e){for(var t=arguments.length,n=Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];console.log("[".concat(this.pluginName,"] ").concat(e),...n)}static warn(e){for(var t=arguments.length,n=Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];console.warn("[".concat(this.pluginName,"] ").concat(e),...n)}static error(e){for(var t=arguments.length,n=Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];console.error("[".concat(this.pluginName,"] ").concat(e),...n)}}y.pluginName="Google Ads (Cloud)";class _{init(){}supports(e,t){return y.warn("Method 'supports' was not overridden by `"+this.constructor.name+"`. Default return set to false."),!1}execute(){y.warn("Method 'execute' was not overridden by `"+this.constructor.name+"`.")}disable(){this.active=!1}constructor({conversionId:e,conversionEnabled:t,conversionLabel:n,conversionDynamicRemarketingEnabled:i,conversionDynamicRemarketingProductIdentifier:r,enhancedConversionsEnabled:o,context:s,debugEnabled:a=!1}){this.active=!0,this.conversionId=e,this.conversionEnabled=t,this.conversionLabel=n,this.conversionDynamicRemarketingEnabled=i,this.conversionDynamicRemarketingProductIdentifier=r,this.enhancedConversionsEnabled=o,this.context=s,this.debugEnabled=a}}class w extends _{execute(){let e=this.getEvents();window.PluginManager.getPluginInstances(this.getPluginName()).forEach(t=>{Object.keys(e).forEach(n=>{t.$emitter.subscribe(n,e[n])})})}getEvents(){return console.warn("[Google AdsCloud Plugin] Method 'getEvents' was not overridden by `"+this.constructor.name+"`."),{}}getPluginName(){console.warn("[Google AdsCloud Plugin] Method 'getPluginName' was not overridden by `"+this.constructor.name+"`.")}}class C{static event(e,t,n){let{debugEnabled:i=!1}=n;if(!window.gtag){y.error("No gtag found. Maybe the Google Ads conversion ID is missing?");return}document.$emitter&&document.$emitter.publish("shopStudioGoogleAdsCloudGtagEvent",{event:e,data:t}),i&&y.log('Pushed event "'.concat(e,'" to gtag:'),t),window.gtag("event",e,t)}static set(e,t,n){let{debugEnabled:i=!1}=n;if(!window.gtag){y.error("No gtag found. Maybe the Google Ads conversion ID is missing?");return}document.$emitter&&document.$emitter.publish("shopStudioGoogleAdsCloudGtagSet",{key:e,data:t}),i&&y.log('Set data "'.concat(e,'" to gtag:'),t),window.gtag("set",e,t)}}class I{static find(e){let t=i.querySelector(document,'script[data-shop-studio-google-ads-cloud-data="'.concat(e,'"]'),!1);if(!t)return null;let n=t.innerText.trim();return n&&0!==n.length&&JSON.parse(n)||null}}class L extends w{supports(e,t){return this.conversionEnabled.addToCart||this.conversionDynamicRemarketingEnabled.addToCart}getPluginName(){return"AddToCart"}getEvents(){return{beforeFormSubmit:this._beforeFormSubmit.bind(this)}}async _beforeFormSubmit(e){if(!this.active)return;let t=this._findProductId(e.detail);if(!t){y.warn("Product ID not found. Skipping.");return}await this._buildDataAndPushToGtag(t,e.detail)}_findProductId(e){let t=null;return e.forEach((e,n)=>{n.endsWith("[id]")&&(t=e)}),t}async _buildDataAndPushToGtag(e,t){let n=this._findProduct(e);if(!n){y.warn('Failed to find product by ID "'.concat(e,'"'));return}if(this.conversionEnabled.addToCart&&this.conversionLabel.addToCart&&this.conversionLabel.addToCart.trim().length>0&&C.event("conversion",{send_to:"".concat(this.conversionId,"/").concat(this.conversionLabel.addToCart),value:n.price,currency:n.currency},{debugEnabled:this.debugEnabled}),this.conversionDynamicRemarketingEnabled.addToCart){let i=t.get("'lineItems[".concat(e,"][quantity]'"));null!==i&&(i=parseInt(i.toString())),C.event("add_to_cart",{send_to:this.conversionId,value:n.price,currency:n.currency,items:[{google_business_vertical:"retail",id:"id"===this.conversionDynamicRemarketingProductIdentifier.addToCart?n.id:n.number,name:n.name,price:n.price,currency:n.currency,quantity:i}]},{debugEnabled:this.debugEnabled})}}_findProduct(e){let t=["product-page-loaded","navigation-page-loaded","search-page-loaded"];for(let n of t){let t=I.find(n);if(t&&t.product)return t.product;if(t&&t.productListing&&t.productListing.products){for(let n of t.productListing.products)if(n.id===e)return n}}return y.warn('Failed to find data for events "'.concat(t.join(", "),'"')),null}}class P{setItem(e,t){return this._storage[e]=t}getItem(e){return Object.prototype.hasOwnProperty.call(this._storage,e)?this._storage[e]:null}removeItem(e){return delete this._storage[e]}key(e){return Object.values(this._storage)[e]||null}clear(){return this._storage={}}constructor(){this._storage={}}}class k{_chooseStorage(){return k._isSupported(window.localStorage)?this._storage=window.localStorage:k._isSupported(window.sessionStorage)?this._storage=window.sessionStorage:o.isSupported()?this._storage=o:this._storage=new P}static _isSupported(e){try{let t="__storage_test";return e.setItem(t,"1"),e.removeItem(t),!0}catch(e){return!1}}_validateStorage(){if("function"!=typeof this._storage.setItem)throw Error('The storage must have a "setItem" function');if("function"!=typeof this._storage.getItem)throw Error('The storage must have a "getItem" function');if("function"!=typeof this._storage.removeItem)throw Error('The storage must have a "removeItem" function');if("function"!=typeof this._storage.key)throw Error('The storage must have a "key" function');if("function"!=typeof this._storage.clear)throw Error('The storage must have a "clear" function')}getStorage(){return this._storage}constructor(){this._storage=null,this._chooseStorage(),this._validateStorage()}}let T=Object.freeze(new k).getStorage();class A extends _{init(){this.storageKey="shop-studio-google-ads-cloud-add-to-cart-by-number"}supports(e,t){return(this.conversionEnabled.addToCart||this.conversionDynamicRemarketingEnabled.addToCart)&&"checkout"===e&&"cartpage"===t}execute(){let e=T.getItem(this.storageKey);e&&e.trim().length>0&&(T.removeItem(this.storageKey),this._buildDataAndPushToGtag(e.trim()));let t=i.querySelector(document,".cart-add-product",!1);t&&t.addEventListener("submit",this._formSubmit.bind(this))}async _formSubmit(e){if(!this.active)return;let t=this._findProductNumber(e.currentTarget);if(!t){y.warn("Product number not found. Skipping.");return}T.setItem(this.storageKey,t)}_findProductNumber(e){return i.querySelector(e,'input[name="number"]').value||null}async _buildDataAndPushToGtag(e){let t=this._findProduct(e);if(!t){y.warn('Failed to find product by product number "'.concat(e,'"'));return}this.conversionEnabled.addToCart&&this.conversionLabel.addToCart&&this.conversionLabel.addToCart.trim().length>0&&C.event("conversion",{send_to:"".concat(this.conversionId,"/").concat(this.conversionLabel.addToCart),value:t.price,currency:t.currency},{debugEnabled:this.debugEnabled}),this.conversionDynamicRemarketingEnabled.addToCart&&C.event("add_to_cart",{send_to:this.conversionId,value:t.price,currency:t.currency,items:[{google_business_vertical:"retail",id:"id"===this.conversionDynamicRemarketingProductIdentifier.addToCart?t.id:t.number,name:t.name,price:t.price,currency:t.currency,quantity:1}]},{debugEnabled:this.debugEnabled})}_findProduct(e){let t=["checkout-cart-page-loaded","checkout-confirm-page-loaded","checkout-info-widget-loaded","checkout-offcanvas-widget-loaded"];for(let n of t){let t=I.find(n);if(t&&t.cart&&t.cart.products){for(let n of t.cart.products)if(n.number===e)return n}}return y.warn('Failed to find data for events "'.concat(t.join(", "),'"')),null}}class S extends w{supports(e,t){return"checkout"===e&&"confirmpage"===t}async execute(){this.active&&await this._buildDataAndPushToGtag()}async _buildDataAndPushToGtag(){let e=I.find("checkout-confirm-page-loaded");if(!e){y.warn('Failed to find data for event "checkout-confirm-page-loaded"');return}let t=e.cart,n=e.context;C.event("conversion",{send_to:"".concat(this.conversionId,"/").concat(this.conversionLabel.beginCheckout),value:t.totalPrice,currency:n.currency},{debugEnabled:this.debugEnabled})}}class D extends w{supports(e,t){return this.conversionEnabled.login&&this.conversionLabel.login&&this.conversionLabel.login.trim().length>0&&("auth"===e&&"loginpage"===t||"register"===e&&"checkoutregisterpage"===t)}getPluginName(){return"FormValidation"}getEvents(){return{onFormSubmit:this._onFormSubmit.bind(this)}}_onFormSubmit(e){this.active&&e.target.classList.contains("login-form")&&e.detail.validity&&this._buildDataAndPushToGtag(e)}_buildDataAndPushToGtag(){C.event("conversion",{send_to:"".concat(this.conversionId,"/").concat(this.conversionLabel.login)},{debugEnabled:this.debugEnabled})}}class O extends _{supports(e,t){return(this.conversionEnabled.purchase||this.conversionDynamicRemarketingEnabled.purchase)&&"checkout"===e&&"finishpage"===t}async execute(){let e=new URLSearchParams(window.location.search).get("orderId");if(!e){y.warn("Order ID not found. Skipping");return}await this._buildDataAndPushToGtag(e)}async _buildDataAndPushToGtag(e){let t=I.find("checkout-finish-page-loaded");if(!t){y.warn('Failed to find data for event "checkout-finish-page-loaded"');return}let n=t.order,i=n.customer;this.enhancedConversionsEnabled.purchase&&i&&i.email&&i.email.trim().length>0&&C.set("user_data",{email:i.email},{debugEnabled:this.debugEnabled}),this.conversionEnabled.purchase&&this.conversionLabel.purchase&&this.conversionLabel.purchase.trim().length>0&&C.event("conversion",{send_to:"".concat(this.conversionId,"/").concat(this.conversionLabel.purchase),transaction_id:n.orderNumber,value:n.totalPrice,currency:n.currency},{debugEnabled:this.debugEnabled}),this.conversionDynamicRemarketingEnabled.purchase&&C.event("purchase",{send_to:this.conversionId,transaction_id:n.orderNumber,value:n.totalPrice,currency:n.currency,tax:n.tax,shipping:n.shipping,affiliation:n.affiliation,coupon:n.coupon,items:n.products.map(e=>({google_business_vertical:"retail",id:"id"===this.conversionDynamicRemarketingProductIdentifier.purchase?e.id:e.number,name:e.name,price:e.price,currency:e.currency,quantity:e.quantity}))},{debugEnabled:this.debugEnabled})}}class x extends _{supports(e,t){return this.conversionEnabled.removeFromCart&&this.conversionLabel.removeFromCart&&this.conversionLabel.removeFromCart.trim().length>0}execute(){document.addEventListener("click",this._onRemoveFromCart.bind(this))}async _onRemoveFromCart(e){if(!this.active)return;let t=e.target.closest(".cart-item-remove-button");if(!t)return null;let n=this._findProductId(t);if(!n){y.warn("Product ID not found. Skipping.");return}await this._buildDataAndPushToGtag(n)}_findProductId(e){return i.getDataAttribute(e,"product-id")}async _buildDataAndPushToGtag(e){let t=this._findProduct(e);if(!t){y.warn('Failed to find product by ID "'.concat(e,'"'));return}C.event("conversion",{send_to:"".concat(this.conversionId,"/").concat(this.conversionLabel.removeFromCart),value:t.price,currency:t.currency},{debugEnabled:this.debugEnabled})}_findProduct(e){let t=["checkout-cart-page-loaded","checkout-confirm-page-loaded","checkout-info-widget-loaded","checkout-offcanvas-widget-loaded"];for(let n of t){let t=I.find(n);if(t&&t.cart&&t.cart.products){for(let n of t.cart.products)if(n.id===e)return n}}return y.warn('Failed to find data for events "'.concat(t.join(", "),'"')),null}}class R extends w{supports(e,t){return this.conversionEnabled.search&&this.conversionLabel.search&&this.conversionLabel.search.trim().length>0}getPluginName(){return"SearchWidget"}getEvents(){return{afterSuggest:this._onSearch.bind(this)}}_onSearch(e){this.active&&this._buildDataAndPushToGtag()}_buildDataAndPushToGtag(){C.event("conversion",{send_to:"".concat(this.conversionId,"/").concat(this.conversionLabel.search)},{debugEnabled:this.debugEnabled})}}class q extends w{supports(e,t){return this.conversionEnabled.signUp&&this.conversionLabel.signUp&&this.conversionLabel.signUp.trim().length>0&&("auth"===e&&"loginpage"===t||"register"===e&&"checkoutregisterpage"===t)}getPluginName(){return"FormValidation"}getEvents(){return{onFormSubmit:this._onFormSubmit.bind(this)}}_onFormSubmit(e){this.active&&e.target.classList.contains("register-form")&&e.detail.validity&&this._buildDataAndPushToGtag(e)}_buildDataAndPushToGtag(){C.event("conversion",{send_to:"".concat(this.conversionId,"/").concat(this.conversionLabel.signUp)},{debugEnabled:this.debugEnabled})}}class N extends _{supports(e,t){return(this.conversionEnabled.viewItem||this.conversionDynamicRemarketingEnabled.viewItem)&&"product"===e&&"index"===t}execute(){if(!this.active)return;let e=this._findProductId();if(!e){y.warn("Product ID not found. Skipping.");return}this._buildDataAndPushToGtag(e)}_findProductId(){let e=i.querySelector(document,"#productDetailPageBuyProductForm"),t=i.querySelectorAll(e,"input"),n=null;return t.forEach(e=>{i.getAttribute(e,"name").endsWith("[id]")&&(n=e.value)}),n}async _buildDataAndPushToGtag(e){let t=I.find("product-page-loaded");if(!t){y.warn('Failed to find data for event "product-page-loaded"');return}let n=t.product;this.conversionEnabled.viewItem&&this.conversionLabel.viewItem&&this.conversionLabel.viewItem.trim().length>0&&C.event("conversion",{send_to:"".concat(this.conversionId,"/").concat(this.conversionLabel.viewItem),value:n.price,currency:n.currency},{debugEnabled:this.debugEnabled}),this.conversionDynamicRemarketingEnabled.viewItem&&C.event("view_item",{send_to:this.conversionId,value:n.price,currency:n.currency,items:[{google_business_vertical:"retail",id:"id"===this.conversionDynamicRemarketingProductIdentifier.viewItem?n.id:n.number,name:n.name,price:n.price,currency:n.currency,quantity:1}]},{debugEnabled:this.debugEnabled})}}class F extends _{supports(e,t){let n=i.querySelector(document,".cms-element-product-listing-wrapper",!1);return(this.conversionEnabled.viewItemList||this.conversionDynamicRemarketingEnabled.viewItemList)&&!!n}execute(){this.active&&this._buildDataAndPushToGtag()}_buildDataAndPushToGtag(){let e=I.find("navigation-page-loaded");if(!e){y.warn('Failed to find data for event "navigation-page-loaded"');return}let t=e.productListing;this.conversionEnabled.viewItemList&&this.conversionLabel.viewItemList&&this.conversionLabel.viewItemList.trim().length>0&&C.event("conversion",{send_to:"".concat(this.conversionId,"/").concat(this.conversionLabel.viewItemList),value:t.totalPrice,currency:t.currency},{debugEnabled:this.debugEnabled}),this.conversionDynamicRemarketingEnabled.viewItemList&&C.event("view_item_list",{send_to:this.conversionId,value:t.totalPrice,currency:t.currency,items:t.products.map(e=>({google_business_vertical:"retail",id:"id"===this.conversionDynamicRemarketingProductIdentifier.viewItemList?e.id:e.number,name:e.name,price:e.price,currency:e.currency,quantity:e.quantity}))},{debugEnabled:this.debugEnabled})}}class G extends _{supports(e,t){return(this.conversionEnabled.viewSearchResults||this.conversionDynamicRemarketingEnabled.viewSearchResults)&&"search"===e&&"search"===t}execute(){this.active&&this._buildDataAndPushToGtag()}_buildDataAndPushToGtag(){let e=I.find("search-page-loaded");if(!e){y.warn('Failed to find data for event "search-page-loaded"');return}let t=e.productListing;this.conversionEnabled.viewSearchResults&&this.conversionLabel.viewSearchResults&&this.conversionLabel.viewSearchResults.trim().length>0&&C.event("conversion",{send_to:"".concat(this.conversionId,"/").concat(this.conversionLabel.viewSearchResults),value:t.totalPrice,currency:t.currency},{debugEnabled:this.debugEnabled}),this.conversionDynamicRemarketingEnabled.viewSearchResults&&C.event("view_search_results",{send_to:this.conversionId,value:t.totalPrice,currency:t.currency,items:t.products.map(e=>({google_business_vertical:"retail",id:"id"===this.conversionDynamicRemarketingProductIdentifier.viewSearchResults?e.id:e.number,name:e.name,price:e.price,currency:e.currency,quantity:e.quantity}))},{debugEnabled:this.debugEnabled})}}class j extends window.PluginBaseClass{init(){this.cookieEnabledName="shopstudio-google-ads-cloud-cookie-consent",this.defaultGoogleAnalyticsCookieEnabledName="google-analytics-enabled",this._handleCookieChangeEvent(),(!window.useDefaultCookieConsent||this._cookieEqualsValue(this.cookieEnabledName,"allowed"))&&this._startGoogleAds()}registerEvent(e){let t=new e({conversionId:this.options.conversionId,conversionEnabled:this.options.conversionEnabled,conversionLabel:this.options.conversionLabel,conversionDynamicRemarketingEnabled:this.options.conversionDynamicRemarketingEnabled,conversionDynamicRemarketingProductIdentifier:this.options.conversionDynamicRemarketingProductIdentifier,enhancedConversionsEnabled:this.options.enhancedConversionsEnabled,context:this.options.context,debugEnabled:this.options.debugEnabled});t.init(),this.events.push(t)}_startGoogleAds(){let e=this.options.conversionId;if(!e){y.error("Conversion ID for GTag is missing.");return}if(!this._cookieEqualsValue(this.defaultGoogleAnalyticsCookieEnabledName,"1")){let t=document.createElement("script");t.src="https://www.googletagmanager.com/gtag/js?id=".concat(e),document.head.append(t),window.gtag("js",new Date)}window.gtag("config",e,this.options.gtag.config),gtag("consent","default",{ad_user_data:this._cookieEqualsValue(this.cookieEnabledName,"allowed")?"granted":"denied",ad_storage:this._cookieEqualsValue(this.cookieEnabledName,"allowed")?"granted":"denied",ad_personalization:this._cookieEqualsValue(this.cookieEnabledName,"allowed")?"granted":"denied",analytics_storage:this._cookieEqualsValue(this.defaultGoogleAnalyticsCookieEnabledName,"1")?"granted":"denied"}),this.events=[],this._registerDefaultEvents(),this._handleEvents()}_handleEvents(){this.events.forEach(e=>{e.supports(this.options.context.controllerName,this.options.context.controllerAction)&&e.execute()})}_registerDefaultEvents(){this.registerEvent(L),this.registerEvent(A),this.registerEvent(S),this.registerEvent(D),this.registerEvent(O),this.registerEvent(x),this.registerEvent(R),this.registerEvent(q),this.registerEvent(N),this.registerEvent(F),this.registerEvent(G)}_handleCookieChangeEvent(){document.$emitter.subscribe("CookieConfiguration_Update",this._handleCookies.bind(this))}_handleCookies(e){let t=e.detail;if(Object.prototype.hasOwnProperty.call(t,this.cookieEnabledName)){if(t[this.cookieEnabledName]){this._startGoogleAds();return}this._removeCookies(),this._disableEvents()}}_removeCookies(){let e=document.cookie.split(";"),t=/^(_swag_ga|_gat_gtag)/;e.forEach(e=>{let n=e.split("=")[0].trim();n.match(t)&&o.removeItem(n)})}_disableEvents(){this.events.forEach(e=>{e.disable()})}_cookieEqualsValue(e,t){return o.getItem(e)===t}}j.options={conversionId:null,debugEnabled:!1,gtag:{config:{anonymize_ip:"true",cookie_domain:"none",cookie_prefix:"_shop_studio_google_ads_cloud"}},conversionEnabled:{addToCart:!1,beginCheckout:!1,login:!1,purchase:!1,removeFromCart:!1,search:!1,signUp:!1,viewItem:!1,viewItemList:!1,viewSearchResults:!1},conversionLabel:{addToCart:null,beginCheckout:null,login:null,purchase:null,removeFromCart:null,search:null,signUp:null,viewItem:null,viewItemList:null,viewSearchResults:null},conversionDynamicRemarketingEnabled:{addToCart:!1,purchase:!1,viewItem:!1,viewItemList:!1,viewSearchResults:!1},conversionDynamicRemarketingProductIdentifier:{addToCart:"productNumber",purchase:"productNumber",viewItem:"productNumber",viewItemList:"productNumber",viewSearchResults:"productNumber"},enhancedConversionsEnabled:{purchase:!1},context:{controllerName:null,controllerAction:null,currency:{isoCode:null}}};let{PluginManager:M}=window;M.register("ShopStudioGoogleAdsCloud",j,"[data-shop-studio-google-ads-cloud]")})()})();