(()=>{"use strict";var t={d:(e,o)=>{for(var c in o)t.o(o,c)&&!t.o(e,c)&&Object.defineProperty(e,c,{enumerable:!0,get:o[c]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{add_to_cart:()=>w,begin_checkout:()=>f,purchase:()=>h,remove_from_cart:()=>g,search:()=>v,select_content:()=>y,view_item:()=>b,view_item_list:()=>m});const o=window.wp.i18n,c=window.wp.hooks,n=(t,e)=>{var o;const c={};t.variation&&(c.item_variant=t.variation);const n={item_id:d(t),item_name:t.name,...u(t),quantity:null!==(o=t.quantity)&&void 0!==o?o:e,price:i(t.prices.price,t.prices.currency_minor_unit),...c};return t?.price_after_coupon_discount({item_id:d(t),item_name:t.name,item_list_name:e,...u(t),price:i(t.prices.price,t.prices.currency_minor_unit)}),i=(t,e=2)=>parseInt(t,10)/10**e,a=(t,e,o)=>{(0,c.removeAction)(t,e),(0,c.addAction)(t,e,o)},d=t=>{const e=t.extensions?.woocommerce_google_analytics_integration?.identifier;return void 0!==e?e:"product_sku"===window.ga4w?.settings?.identifier?t.sku?t.sku:"#"+t.id:t.id},s=t=>t.coupons[0]?.code?{coupon:t.coupons[0]?.code}:{},u=t=>"categories"in t&&t.categories.length?_(t.categories):{},_=t=>Object.fromEntries(t.slice(0,5).map(((t,e)=>[p(e),t.name]))),p=t=>"item_category"+(t>0?t+1:""),l=(t,e,o)=>{var c;return null!==(c=e?.find((({id:e})=>e===t)))&&void 0!==c?c:o?.items?.find((({id:e})=>e===t))},m=({products:t,listName:e=(0,o.__)("Product List","woocommerce-google-analytics-integration")})=>0!==t.length&&{item_list_id:"engagement",item_list_name:(0,o.__)("Viewing products","woocommerce-google-analytics-integration"),items:t.map(((t,o)=>({...r(t,e),index:o+1})))},w=({product:t,quantity:e=1})=>({items:t?[n(t,e)]:[]}),g=({product:t,quantity:e=1})=>({items:t?[n(t,e)]:[]}),f=({storeCart:t})=>({currency:t.totals.currency_code,value:i(t.totals.total_price,t.totals.currency_minor_unit),...s(t),items:t.items.map(n)}),y=({product:t})=>!!t&&{content_type:"product",content_id:d(t)},v=({searchTerm:t})=>({search_term:t}),b=({product:t,listName:e=(0,o.__)("Product List","woocommerce-google-analytics-integration")})=>!!t&&{items:[r(t,e)]},h=({order:t})=>void 0!==t&&{transaction_id:t.id,affiliation:t.affiliation,currency:t.totals.currency_code,value:i(t.totals.total_price,t.totals.currency_minor_unit),tax:i(t.totals.tax_total,t.totals.currency_minor_unit),shipping:i(t.totals.shipping_total,t.totals.currency_minor_unit),items:t.items.map(n)},k="woocommerce-google-analytics",A="experimental__woocommerce_blocks";(0,c.removeAction)(`${A}-checkout-submit`,k),(0,c.removeAction)(`${A}-checkout-set-email-address`,k),(0,c.removeAction)(`${A}-checkout-set-phone-number`,k),(0,c.removeAction)(`${A}-checkout-set-billing-address`,k),(0,c.removeAction)(`${A}-cart-set-item-quantity`,k),(0,c.removeAction)(`${A}-product-search`,k),(0,c.removeAction)(`${A}-store-notice-create`,k);const E={statistics:["analytics_storage"],marketing:["ad_storage","ad_user_data","ad_personalization"]};function $(){(({tracker_function_name:t})=>{if("function"==typeof wp_has_consent){void 0===window.wp_consent_type&&(window.wp_consent_type="optin");const e={};for(const[t,o]of Object.entries(E))if(""!==consent_api_get_cookie(window.consent_api.cookie_prefix+"_"+t)){const c=wp_has_consent(t)?"granted":"denied";o.forEach((t=>{e[t]=c}))}Object.keys(e).length>0&&window[t]("consent","update",e)}})(window.ga4w.settings),(({tracker_function_name:t})=>{document.addEventListener("wp_listen_for_consent_change",(e=>{const o={},c=E[Object.keys(e.detail)[0]],n="allow"===Object.values(e.detail)[0]?"granted":"denied";void 0!==c&&(c.forEach((t=>{o[t]=n})),Object.keys(o).length>0&&window[t]("consent","update",o))}))})(window.ga4w.settings);const t=function({events:t,tracker_function_name:o}){return function(c){const n=e[c];if("function"!=typeof n)throw new Error(`Event ${c} is not supported.`);return function(e){const r=n(e);t.includes(c)&&r&&window[o]("event",c,r)}}}(window.ga4w.settings);!function(t,{events:e,cart:o,products:c,product:n,added_to_cart:r,order:i}){Object.values(null!=e?e:{}).forEach((e=>{"add_to_cart"===e?t(e)({product:r}):t(e)({storeCart:o,products:c,product:n,order:i})}));const a=document.body.onadded_to_cart;document.body.onadded_to_cart=function(e,r,i,d){"function"==typeof a&&a.apply(this,arguments);const s=parseInt(d[0].dataset.product_id||d[0].value),u=n?.id===s?n:l(parseInt(s),c,o);u&&t("add_to_cart")({product:u})};const d=()=>{document.querySelectorAll(".woocommerce-cart-form .woocommerce-cart-form__cart-item .remove[data-product_id]").forEach((t=>t.addEventListener("click",s)))};function s(e){t("remove_from_cart")({product:l(parseInt(e.target.dataset.product_id),c,o)})}d();const u=document.body.onupdated_wc_div;document.body.onupdated_wc_div=function(){"function"==typeof u&&u.apply(this,arguments),d()};const _=document.body.onremoved_from_cart;document.body.onremoved_from_cart=function(){"function"==typeof _&&_.apply(this,arguments),s({target:arguments[3][0]})},document.querySelectorAll(".products .product:not(.wp-block-post)")?.forEach((e=>{const n=e.querySelector("a[data-product_id]")?.getAttribute("data-product_id");n&&e.addEventListener("click",(e=>{const r=e.target.closest(".woocommerce-loop-product__link"),i=e.target.classList.contains("button")&&e.target.hasAttribute("data-product_id"),a=e.target.classList.contains("add_to_cart_button")&&!e.target.classList.contains("product_type_variable");(r||i&&!a)&&t("select_content")({product:l(parseInt(n),c,o)})}))})),document.querySelectorAll(".products-block-post-template .product, .wc-block-product-template .product")?.forEach((e=>{const n=e.querySelector("[data-product_id]")?.getAttribute("data-product_id");n&&e.addEventListener("click",(e=>{const r=e.target,i=r.closest(".wc-block-components-product-image a"),a=r.closest(".wp-block-post-title a"),d=r.closest(".wc-block-components-product-button [data-product_id]");d&&d.classList.contains("add_to_cart_button")&&!d.classList.contains("product_type_variable")?t("add_to_cart")({product:l(parseInt(n),c,o)}):(i||d||a)&&t("select_content")({product:l(parseInt(n),c,o)})}))}))}(t,window.ga4w.data),(t=>{a(`${A}-product-render`,k,t("view_item")),a(`${A}-cart-remove-item`,k,t("remove_from_cart")),a(`${A}-checkout-render-checkout-form`,k,t("begin_checkout")),a(`${A}-cart-add-item`,k,(({product:e})=>{t("add_to_cart")({product:e})})),a(`${A}-product-list-render`,k,t("view_item_list")),a(`${A}-product-view-link`,k,t("select_content"))})(t)}function L(){window.ga4w||console.warn("Google Analytics for WooCommerce: Configuration and tracking data not found after the page was fully loaded. Make sure the `woocommerce-google-analytics-integration-data` script gets eventually loaded.")}window.ga4w?$():(document.addEventListener("ga4w:ready",$),"complete"===document.readyState?L():window.addEventListener("load",L))})();