!function(){"use strict";window.flowmonk=new class{constructor(){this.disabledKey="flowmonk-disabled",this.baseCollectionListAttributeKey="data-fm-collection-list",this.collectionPageAttributeKey="data-fm-collection-page-event",this.collectionListAttributeKey="fmCollectionList",this.targetElementIdAttributeKey="fmTargetElementId",this.targetElementListenerId="fmTargetElementListenerId",this.itemSlugAttributeKey="fmItemSlug",this.elementIdCounter=0,this.eventListeners={},this.init=()=>{this.trackingEnabled()&&this.trackPageView(),window.addEventListener("load",(()=>{document.querySelectorAll(`[${this.baseCollectionListAttributeKey}]`).forEach((t=>{const e=this.getCollectionListConfigurations(t);t.childNodes.forEach((t=>{e.forEach((e=>{this.setListItemEventClickListener(t,e)}))})),e.forEach((e=>{this.setListChangeListener(t,e)}))}));document.querySelectorAll(`[${this.collectionPageAttributeKey}]`).forEach((t=>{this.setPageEventClickListener(t)}))}))},this.trackPageView=()=>{const t=window.location,e=t.protocol+"//"+t.hostname,i=window.location.pathname||"/";this.post({h:e,p:i})},this.trackListItemEvent=(t,e)=>{const i=window.location,n=i.protocol+"//"+i.hostname,o=window.location.pathname||"/";this.beacon({h:n,p:o,e:t,s:e})},this.trackPageEvent=t=>{const e=window.location,i=e.protocol+"//"+e.hostname,n=window.location.pathname||"/";this.beacon({h:i,p:n,e:t})},this.disableForComputer=()=>{if(window.localStorage)return window.localStorage.setItem(this.disabledKey,"true"),void alert("Flowmonk has been disabled for this website.");alert("Your browser doesn't support localStorage.")},this.enableForComputer=()=>{window.localStorage&&(window.localStorage.removeItem(this.disabledKey),alert("Flowmonk has been enabled for this website."))},this.encode=t=>encodeURIComponent(btoa(JSON.stringify({sid:this.siteId,...t}))),this.beacon=t=>{this.siteId&&this.url&&this.trackingEnabled()&&navigator.sendBeacon(`${this.url}/collect?o=${this.encode(t)}`)},this.post=t=>{if(this.siteId&&this.url&&this.trackingEnabled()){const e=document.createElement("img");e.setAttribute("alt",""),e.setAttribute("aria-hidden","true"),e.style.position="absolute",e.src=`${this.url}/collect?o=${this.encode(t)}`,e&&(e.addEventListener("load",(function(){var t;null===(t=null==e?void 0:e.parentNode)||void 0===t||t.removeChild(e)})),e.addEventListener("error",(function(){var t;null===(t=null==e?void 0:e.parentNode)||void 0===t||t.removeChild(e)})),document.body.appendChild(e))}},this.getCollectionListConfigurations=t=>{const e=[],i=Object.keys(t.dataset).filter((t=>t.includes(this.collectionListAttributeKey)||t.includes(this.targetElementIdAttributeKey))).reduce(((t,e)=>{const i=e.split("-");let n=i[i.length-1];return 1===i.length&&(n="-0"),t[n]||(t[n]=[]),t[n].push(e),t}),{});return Object.values(i).forEach((i=>{const n={eventId:"",targetElementId:""};i.forEach((e=>{e.includes(this.collectionListAttributeKey)?n.eventId=t.dataset[e]||"":e.includes(this.targetElementIdAttributeKey)&&(n.targetElementId=t.dataset[e]||"")})),e.push(n)})),e},this.setListChangeListener=(t,e)=>{new MutationObserver((t=>{t.forEach((t=>{"childList"===t.type&&t.addedNodes.forEach((t=>{this.setListItemEventClickListener(t,e)}))}))})).observe(t,{childList:!0})},this.setListItemEventClickListener=(t,e)=>{var i;const n=null==t?void 0:t.querySelector(`#${e.targetElementId}`);let o=null===(i=null==n?void 0:n.dataset)||void 0===i?void 0:i[this.targetElementListenerId];o?null==n||n.removeEventListener("click",this.eventListeners[o]):(null==n?void 0:n.dataset)&&(this.elementIdCounter++,o=`listener_${this.elementIdCounter}`,n.dataset[this.targetElementListenerId]=o),this.eventListeners[o]=t=>{var i,n;const o=null===(n=null===(i=t.currentTarget)||void 0===i?void 0:i.dataset)||void 0===n?void 0:n[this.itemSlugAttributeKey];o&&this.trackListItemEvent(e.eventId,o)},null==n||n.addEventListener("click",this.eventListeners[o])},this.setPageEventClickListener=t=>{var e;const i=null===(e=null==t?void 0:t.dataset)||void 0===e?void 0:e.fmCollectionPageEvent;i&&t.addEventListener("click",(()=>{this.trackPageEvent(i)}))},this.trackingEnabled=()=>{let t=!1;try{t=window.localStorage&&"true"===window.localStorage.getItem(this.disabledKey)}catch(t){}return!t};const t=document.currentScript||document.querySelector('script[src*="flowmonk.js"][data-site-id]')||document.querySelector("script[data-site-id]"),e=null==t?void 0:t.getAttribute("data-site-id");null!==e&&(this.siteId=e),this.url="https://api.flowmonk.com"}},setTimeout(window.flowmonk.init)}();
