(()=>{"use strict";var t={d:(e,o)=>{for(var n in o)t.o(o,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:o[n]})},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:()=>b,remove_from_cart:()=>g,search:()=>v,select_content:()=>y,view_item:()=>h,view_item_list:()=>p});const o=window.wp.i18n,n=window.wp.hooks,c=(t,e)=>{var o;const n={};t.variation&&(n.item_variant=t.variation);const c={item_id:d(t),item_name:t.name,...u(t),quantity:null!==(o=t.quantity)&&void 0!==o?o:e,price:i(t.totals?.line_total||t.prices.price,t.prices.currency_minor_unit),...n};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,n.removeAction)(t,e),(0,n.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)=>[m(e),t.name]))),m=t=>"item_category"+(t>0?t+1:""),l=(t,e,o)=>{var n;return null!==(n=e?.find((({id:e})=>e===t)))&&void 0!==n?n:o?.items?.find((({id:e})=>e===t))},p=({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?[c(t,e)]:[]}),g=({product:t,quantity:e=1})=>({items:t?[c(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(c)}),y=({product:t})=>!!t&&{content_type:"product",content_id:d(t)},v=({searchTerm:t})=>({search_term:t}),h=({product:t,listName:e=(0,o.__)("Product List","woocommerce-google-analytics-integration")})=>!!t&&{items:[r(t,e)]},b=({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(c)},k="woocommerce-google-analytics",A="experimental__woocommerce_blocks";(0,n.removeAction)(`${A}-checkout-submit`,k),(0,n.removeAction)(`${A}-checkout-set-email-address`,k),(0,n.removeAction)(`${A}-checkout-set-phone-number`,k),(0,n.removeAction)(`${A}-checkout-set-billing-address`,k),(0,n.removeAction)(`${A}-cart-set-item-quantity`,k),(0,n.removeAction)(`${A}-product-search`,k),(0,n.removeAction)(`${A}-store-notice-create`,k);const E={statistics:["analytics_storage"],marketing:["ad_storage","ad_user_data","ad_personalization"]};function C(){(({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 n=wp_has_consent(t)?"granted":"denied";o.forEach((t=>{e[t]=n}))}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={},n=E[Object.keys(e.detail)[0]],c="allow"===Object.values(e.detail)[0]?"granted":"denied";void 0!==n&&(n.forEach((t=>{o[t]=c})),Object.keys(o).length>0&&window[t]("consent","update",o))}))})(window.ga4w.settings);const t=function({events:t,tracker_function_name:o}){return function(n){const c=e[n];if("function"!=typeof c)throw new Error(`Event ${n} is not supported.`);return function(e){const r=c(e);t.includes(n)&&r&&window[o]("event",n,r)}}}(window.ga4w.settings);!function(t,{events:e,cart:o,products:n,product:c,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:n,product:c,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);if(Number.isNaN(s))throw new Error("Google Analytics for WooCommerce: Could not read product ID from the button given in `added_to_cart` event. Check whether WooCommerce Core events or elements are malformed by other extensions.");const u=c?.id===s?c:l(s,n,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){const c=parseInt(e.target?.dataset.product_id);if(Number.isNaN(c))throw new Error("Google Analytics for WooCommerce: Could not read product ID from the target element given to remove from cart event. Check whether WooCommerce Core events or elements are malformed by other extensions.");t("remove_from_cart")({product:l(c,n,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(t,e,o,n){"function"==typeof _&&_.apply(this,arguments),s({target:n?.[0]})},document.querySelectorAll(".products .product:not(.wp-block-post)")?.forEach((e=>{const c=e.querySelector("a[data-product_id]")?.getAttribute("data-product_id");c&&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(c),n,o)})}))})),document.querySelectorAll(".products-block-post-template .product, .wc-block-product-template .product")?.forEach((e=>{const c=e.querySelector("[data-product_id]")?.getAttribute("data-product_id");c&&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(c),n,o)}):(i||d||a)&&t("select_content")({product:l(parseInt(c),n,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 $(){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?C():(document.addEventListener("ga4w:ready",C),"complete"===document.readyState?$():window.addEventListener("load",$))})();