(function(){ const zoovuId = 'wNWhCtTlrKSTXiK/+VgEGwiieUOmXUpH'; const domainId = '05ab0b94-c821-4253-a7ad-e1aafaccb7ae'; const variables = [{"id":"6353c517-0b13-4612-8dfd-7a28a75d772b","name":"[Bosch PT] Are products missing in autosuggestions?","type":"FUNCTION","valueType":"BOOLEAN","function":function(event){// Different DOM for cart page if (window.location.href.includes("eshop")) { const products = document.querySelectorAll(`[data-test-id="complex-suggest-item"]`); if (products.length === 0) { return true; } else { return false; } } else { const productsContainer = Boolean(document.querySelector(".m-searchNavigationResults__product-suggestion")); return !productsContainer; } /* */},"scope":"LOCAL"},{"id":"7a089517-a9dd-4fb4-a822-f2086593e99b","name":"[Bosch PT] ATC was clicked","type":"FUNCTION","valueType":"BOOLEAN","function":function(event){if (event.target.closest("button.addToCart")) { return true; } else { return false; } /* */},"scope":"LOCAL"},{"id":"c648b7b3-561b-4aa3-a35e-cad90bd6aa87","name":"[Bosch PT] Cart quantity component was used","type":"FUNCTION","valueType":"BOOLEAN","function":function(event){const isQuantityButtonClick = Boolean( event.target.closest('[data-test-id="decrease-quantity-button"]') || event.target.closest('[data-test-id="increase-quantity-button"]') ); return isQuantityButtonClick; /* */},"scope":"LOCAL"},{"id":"5400d372-a64d-4866-9ea8-8311ca5616f1","name":"[Bosch PT] Currency","type":"FUNCTION","valueType":"TEXT","function":function(event){const COUNTRY_CURRENCY = { AD: "EUR", AE: "AED", AF: "AFN", AG: "XCD", AI: "XCD", AL: "ALL", AM: "AMD", AO: "AOA", AR: "ARS", AS: "USD", AT: "EUR", AU: "AUD", AW: "AWG", AX: "EUR", AZ: "AZN", BA: "BAM", BB: "BBD", BD: "BDT", BE: "EUR", BF: "XOF", BG: "BGN", BH: "BHD", BI: "BIF", BJ: "XOF", BL: "EUR", BM: "BMD", BN: "BND", BO: "BOB", BQ: "USD", BR: "BRL", BS: "BSD", BT: "BTN", BV: "NOK", BW: "BWP", BY: "BYN", BZ: "BZD", CA: "CAD", CC: "AUD", CD: "CDF", CF: "XAF", CG: "XAF", CH: "CHF", CI: "XOF", CK: "NZD", CL: "CLP", CM: "XAF", CN: "CNY", CO: "COP", CR: "CRC", CU: "CUP", CV: "CVE", CW: "ANG", CX: "AUD", CY: "EUR", CZ: "CZK", DE: "EUR", DJ: "DJF", DK: "DKK", DM: "XCD", DO: "DOP", DZ: "DZD", EC: "USD", EE: "EUR", EG: "EGP", EH: "MAD", ER: "ERN", ES: "EUR", ET: "ETB", FI: "EUR", FJ: "FJD", FK: "FKP", FM: "USD", FO: "DKK", FR: "EUR", GA: "XAF", GB: "GBP", GD: "XCD", GE: "GEL", GF: "EUR", GG: "GBP", GH: "GHS", GI: "GIP", GL: "DKK", GM: "GMD", GN: "GNF", GP: "EUR", GQ: "XAF", GR: "EUR", GT: "GTQ", GU: "USD", GW: "XOF", GY: "GYD", HK: "HKD", HM: "AUD", HN: "HNL", HR: "EUR", HT: "HTG", HU: "HUF", ID: "IDR", IE: "EUR", IL: "ILS", IM: "GBP", IN: "INR", IO: "USD", IQ: "IQD", IR: "IRR", IS: "ISK", IT: "EUR", JE: "GBP", JM: "JMD", JO: "JOD", JP: "JPY", KE: "KES", KG: "KGS", KH: "KHR", KI: "AUD", KM: "KMF", KN: "XCD", KP: "KPW", KR: "KRW", KW: "KWD", KY: "KYD", KZ: "KZT", LA: "LAK", LB: "LBP", LC: "XCD", LI: "CHF", LK: "LKR", LR: "LRD", LS: "LSL", LT: "EUR", LU: "EUR", LV: "EUR", LY: "LYD", MA: "MAD", MC: "EUR", MD: "MDL", ME: "EUR", MF: "EUR", MG: "MGA", MH: "USD", MK: "MKD", ML: "XOF", MM: "MMK", MN: "MNT", MO: "MOP", MP: "USD", MQ: "EUR", MR: "MRU", MS: "XCD", MT: "EUR", MU: "MUR", MV: "MVR", MW: "MWK", MX: "MXN", MY: "MYR", MZ: "MZN", NA: "NAD", NC: "XPF", NE: "XOF", NF: "AUD", NG: "NGN", NI: "NIO", NL: "EUR", NO: "NOK", NP: "NPR", NR: "AUD", NU: "NZD", NZ: "NZD", OM: "OMR", PA: "PAB", PE: "PEN", PF: "XPF", PG: "PGK", PH: "PHP", PK: "PKR", PL: "PLN", PM: "EUR", PN: "NZD", PR: "USD", PS: "ILS", PT: "EUR", PW: "USD", PY: "PYG", QA: "QAR", RE: "EUR", RO: "RON", RS: "RSD", RU: "RUB", RW: "RWF", SA: "SAR", SB: "SBD", SC: "SCR", SD: "SDG", SE: "SEK", SG: "SGD", SH: "SHP", SI: "EUR", SJ: "NOK", SK: "EUR", SL: "SLL", SM: "EUR", SN: "XOF", SO: "SOS", SR: "SRD", SS: "SSP", ST: "STN", SV: "USD", SX: "ANG", SY: "SYP", SZ: "SZL", TC: "USD", TD: "XAF", TF: "EUR", TG: "XOF", TH: "THB", TJ: "TJS", TK: "NZD", TL: "USD", TM: "TMT", TN: "TND", TO: "TOP", TR: "TRY", TT: "TTD", TV: "AUD", TW: "TWD", TZ: "TZS", UA: "UAH", UG: "UGX", UM: "USD", US: "USD", UY: "UYU", UZ: "UZS", VA: "EUR", VC: "XCD", VE: "VES", VG: "USD", VI: "USD", VN: "VND", VU: "VUV", WF: "XPF", WS: "WST", YE: "YER", YT: "EUR", ZA: "ZAR", ZM: "ZMW", ZW: "ZWL" }; const locales = window.location.pathname.split("/").filter(Boolean); const country = locales[0].toUpperCase(); return COUNTRY_CURRENCY[country]; /* */},"scope":"LOCAL"},{"id":"dafa3f7c-a241-4d3a-ac9c-389eb07d93bd","name":"[Bosch PT] Currency for purchase event","type":"FUNCTION","valueType":"TEXT","function":function(event){const purchaseEvent = dataLayer.find((ev) => ev["1"] === "purchase")["2"]; const currency = purchaseEvent.currency; return currency; /* */},"scope":"LOCAL"},{"id":"d11d4343-6f33-4ffd-9207-aa43f2677671","name":"[Bosch PT] Delete button was clicked","type":"FUNCTION","valueType":"BOOLEAN","function":function(event){ const deleteButton = event.target.closest('[data-test-id="line-item-delete-button"]'); if (deleteButton) { return true; } return false; /* */},"scope":"LOCAL"},{"id":"cc08371f-f1bd-4513-9179-7ddb9dda4fd1","name":"[Bosch PT] Get all SKUs from search result","type":"FUNCTION","valueType":"LIST","function":function(event){const productSkus = []; const categoryTileLinks = document.querySelectorAll(".category-grid-tile__link-wrapper"); // Product on search result can have many variants and no "main sku", so I'm only passing SKU that is included in hyperlink. // To be checked later with product team if this makes sense. categoryTileLinks.forEach((tileLink) => { const href = tileLink.getAttribute("href"); const skus = tileLink.getAttribute("data-track_dyn_productid").split(","); skus.forEach((sku) => { if (href.includes(sku)) { productSkus.push(sku); } }) }) return productSkus; /* */},"scope":"LOCAL"},{"id":"9acdf70b-14f9-472a-976a-92016cdb6945","name":"[Bosch PT] Get list of SKUs in search autosuggestions","type":"FUNCTION","valueType":"LIST","function":function(event){let hyperlinks; // Different DOM for cart page if (window.location.href.includes("eshop")) { hyperlinks = document.querySelectorAll(`[data-test-id="complex-suggest-item"]`); } else { hyperlinks = document.querySelectorAll(".m-searchNavigationResults__product-suggestion .m-searchNavigationResults__link"); } const skuList = []; Array.from(hyperlinks).forEach(hyperlink => { const href = hyperlink.getAttribute("href"); const match = href.match(/([A-Za-z0-9]+)(?=[\/#?]*$)/); skuList.push(match[1]); }); return skuList; /* */},"scope":"LOCAL"},{"id":"a4097d75-887f-4947-a618-415b4f4ef370","name":"[Bosch PT] Get price from ATC button","type":"FUNCTION","valueType":"DECIMAL","function":function(event){const atcButton = event.target.closest("button.addToCart"); const sku = atcButton.getAttribute("data-sku"); const product = productCartMap[sku]; return Number(product.price); /* */},"scope":"LOCAL"},{"id":"bf72883a-4663-41ed-baf6-584175490328","name":"[Bosch PT] Get quantity for REMOVE_FROM_CART","type":"FUNCTION","valueType":"INTEGER","function":function(event){const productCard = event.target.closest("[class*=lineItemContainer]"); const quantity = productCard.querySelector(`[data-test-id="product-quantity"]`).value; return Number(quantity); /* */},"scope":"LOCAL"},{"id":"0f6a3dfb-49ad-486c-baa4-bb55bb2b1a30","name":"[Bosch PT] isPDP","type":"FUNCTION","valueType":"BOOLEAN","function":function(event){const isPdp = document.body.classList.contains("t-productdetailpage--eshop") || document.body.classList.contains("t-pdp"); return isPdp; /* */},"scope":"LOCAL"},{"id":"c381b7a3-3dd3-4100-9c41-e85911343723","name":"[BoschPT] isSearchInput","type":"FUNCTION","valueType":"BOOLEAN","function":function(event){if (event.target.id === "search") { return true; } // cart page if (event.target.closest(`[name="searchQuery"]`)) { return true; } return false; /* */},"scope":"LOCAL"},{"id":"90055979-6dde-4e58-919a-7e7db009aae3","name":"[Bosch PT] It's pdp but product is not necessarily selected","type":"FUNCTION","valueType":"BOOLEAN","function":function(event){const firstPdp = document.querySelector("#product-detail-stage"); const secondPdp = document.querySelector(".o-gt-stage"); if (firstPdp || secondPdp) { return true; } return false; /* */},"scope":"LOCAL"},{"id":"97966e49-2e80-42f2-ab9b-65a4d909d336","name":"[Bosch PT] Locale formatted","type":"FUNCTION","valueType":"TEXT","function":function(event){const locales = window.location.pathname.split("/").filter(Boolean); const country = locales[0].toUpperCase(); const language = locales[1].toLowerCase(); const localeFormatted = `${language}-${country}`; return localeFormatted; /* */},"scope":"LOCAL"},{"id":"ce635408-b5eb-48e4-9b48-949d83c92b29","name":"[Bosch PT] Page is PDP","type":"FUNCTION","valueType":"BOOLEAN","function":function(event){const mainSectionInFirstPDP = document.querySelector("#product-detail-stage"); const mainSectionInSecondPDP = document.querySelector(".o-gt-stage"); if (mainSectionInFirstPDP || mainSectionInSecondPDP) { return true; } return false; /* */},"scope":"LOCAL"},{"id":"4d44ede1-271d-47d1-a400-2c20e70deaf6","name":"[Bosch PT] Price for PDP_VISITED","type":"FUNCTION","valueType":"DECIMAL","function":function(event){// there are multiple price elements, but we only care about first one here at both PDPs const priceText = document.querySelector(".a-gt-price__price")?.textContent; if (!priceText) { return 0; } function parsePrice(str) { // Extract only digits, commas, dots const numberPart = str.match(/[\d.,]+/g)?.join('') || ""; // If the number uses comma as decimal separator (European format) // Detect by checking last comma position const hasCommaAsDecimal = numberPart.includes(',') && numberPart.lastIndexOf(',') > numberPart.lastIndexOf('.'); let normalized = numberPart; if (hasCommaAsDecimal) { // Remove thousand separators and convert final comma to dot normalized = normalized.replace(/\./g, ""); // remove thousand dots normalized = normalized.replace(/,/g, "."); // convert decimal comma } else { // Normal format: remove thousand separators (commas) normalized = normalized.replace(/,/g, ""); } return parseFloat(normalized); } const price = parsePrice(priceText); return price; /* */},"scope":"LOCAL"},{"id":"b3d67dce-a9a9-468f-9360-d80eae8d665b","name":"[Bosch PT] PricePerUnit for UPDATE_CART","type":"FUNCTION","valueType":"DECIMAL","function":function(event){const products = JSON.parse(sessionStorage.getItem("zoovu-cart-product-prices") || "[]"); const cartItem = event.target.closest('[class*=lineItemContainer]'); const skuFormatted = cartItem.querySelector('[data-test-id="product-sku"]').textContent; const sku = skuFormatted.split(":")[1].trim(); const product = products.find(product => product.sku === sku); return product.pricePerUnit; // old version in case new one needs a fallback for some reason // function getCurrentPrice() // { // const productCard = event.target.closest("[class*=lineItemContainer]"); // const priceText = productCard.querySelector(`[data-test-id="product-price-block"] div p`).textContent; // function parsePrice(str) { // // Extract only digits, commas, dots // const numberPart = str.match(/[\d.,]+/g)?.join('') || ""; // // If the number uses comma as decimal separator (European format) // // Detect by checking last comma position // const hasCommaAsDecimal = numberPart.includes(',') && // numberPart.lastIndexOf(',') > numberPart.lastIndexOf('.'); // let normalized = numberPart; // if (hasCommaAsDecimal) { // // Remove thousand separators and convert final comma to dot // normalized = normalized.replace(/\./g, ""); // remove thousand dots // normalized = normalized.replace(/,/g, "."); // convert decimal comma // } else { // // Normal format: remove thousand separators (commas) // normalized = normalized.replace(/,/g, ""); // } // return parseFloat(normalized); // } // return parsePrice(priceText); // } // function getCurrentQuantity() // { // const productCard = event.target.closest("[class*=lineItemContainer]"); // const currentQuantity = Number(productCard.querySelector(`[data-test-id="product-quantity"]`).value); // return currentQuantity; // } // const currentPrice = getCurrentPrice(); // const currentQuantity = getCurrentQuantity(); // const pricePerUnit = currentPrice / currentQuantity; /* */},"scope":"LOCAL"},{"id":"3194c5d8-d8f5-42c7-b90a-d38b1446b4b1","name":"[Bosch PT] Products for purchase event","type":"FUNCTION","valueType":"LIST","function":function(event){const purchaseEvent = dataLayer.find((ev) => ev["1"] === "purchase")["2"]; const products = []; purchaseEvent.items.forEach((product) => { products.push({ name: product.item_name, sku: product.item_id, quantity: product.quantity, pricePerUnit: product.price, }); }); /* */},"scope":"LOCAL"},{"id":"d3e5945a-8e55-4b96-b963-ccbc71ad4352","name":"[Bosch PT] Product was clicked on autosuggestions","type":"FUNCTION","valueType":"BOOLEAN","function":function(event){// Different DOM for cart page if (window.location.href.includes("eshop")) { return Boolean(event.target.closest(`[data-test-id="complex-suggest-item"]`)); } else { return (Boolean(event.target.closest(`.m-searchNavigationResults__product-suggestion a:not([href*=search]`))); } /* */},"scope":"LOCAL"},{"id":"1330574d-7910-45d3-b50c-e0e82bfc11f8","name":"[Bosch PT] Quantity for ATC button","type":"FUNCTION","valueType":"INTEGER","function":function(event){const atcButton = event.target.closest("button.addToCart"); const sku = atcButton.getAttribute("data-sku"); const product = productCartMap[sku]; // In case ATC is connected to quantity input const quantityContainer = event.target.parentElement.querySelector(".quantity"); if (quantityContainer) { const input = quantityContainer.querySelector("input"); return Number(input.value); } return Number(product.quantity); /* */},"scope":"LOCAL"},{"id":"f2c8b929-18d6-4fa1-9c48-53dcdfe223d5","name":"[Bosch PT] Search result is empty","type":"FUNCTION","valueType":"BOOLEAN","function":function(event){return !!(document.querySelector("[class*=no-search-results]")); /* */},"scope":"LOCAL"},{"id":"9219e29f-45ce-4e95-884b-c97151c7ee88","name":"[Bosch PT] Search result was clicked","type":"FUNCTION","valueType":"BOOLEAN","function":function(event){const categoryTile = event.target.closest(".category-grid-tile"); return Boolean(categoryTile); /* */},"scope":"LOCAL"},{"id":"af1f6746-9b0a-467c-9eb8-fab74479a700","name":"[Bosch PT] SKU from any cart item action (delete/modify)","type":"FUNCTION","valueType":"TEXT","function":function(event){const cartItem = event.target.closest('[class*=lineItemContainer]'); const skuFormatted = cartItem.querySelector('[data-test-id="product-sku"]').textContent; const sku = skuFormatted.split(":")[1].trim(); return sku; /* */},"scope":"LOCAL"},{"id":"5a950c76-96c5-41f3-8f9b-d83de69cd69b","name":"[Bosch PT] SKU from ATC","type":"FUNCTION","valueType":"TEXT","function":function(event){const sku = event.target.closest("button.addToCart").getAttribute('data-sku'); return sku; /* */},"scope":"LOCAL"},{"id":"f3dd91b8-0939-4ecf-bb28-32c8759d2f4d","name":"[Bosch PT] SKU from PDP","type":"FUNCTION","valueType":"TEXT","function":function(event){const mainSectionInFirstPDP = document.querySelector("#product-detail-stage"); const mainSectionInSecondPDP = document.querySelector(".o-gt-stage"); if (mainSectionInFirstPDP) { const selectedVariantSku = mainSectionInFirstPDP.getAttribute("data-sku"); const groupIdentifier = utag_data.product_category_id[0]; if (selectedVariantSku) { return selectedVariantSku; } else { return groupIdentifier; } } if (mainSectionInSecondPDP) { const mainProductSku = utag_data.product_id[0]; return mainProductSku; } /* */},"scope":"LOCAL"},{"id":"59c718f9-cd2c-4f44-9755-2609e78a2812","name":"[Bosch PT] SKU on PDP has changed","type":"FUNCTION","valueType":"BOOLEAN","function":function(event){function currentSkuValue() { const mainSectionInFirstPDP = document.querySelector("#product-detail-stage"); const mainSectionInSecondPDP = document.querySelector(".o-gt-stage"); if (mainSectionInFirstPDP) { const selectedVariantSku = mainSectionInFirstPDP.getAttribute("data-sku"); const groupIdentifier = utag_data.product_category_id[0]; if (selectedVariantSku) { return selectedVariantSku; } else { return groupIdentifier; } } if (mainSectionInSecondPDP) { const mainProductSku = utag_data.product_id[0]; return mainProductSku; } } function previousSkuValue() { return sessionStorage.getItem("zoovu-last-selected-sku"); } if (currentSkuValue() !== previousSkuValue()) { console.log("SKU has new value"); return true; } else { console.log("SKU value has not changed"); return false; } /* */},"scope":"LOCAL"},{"id":"e22afd9c-c6f7-4e8f-8413-31ded27641a3","name":"[Bosch PT] Target is category link in autosuggestions","type":"FUNCTION","valueType":"BOOLEAN","function":function(event){// Different DOM for cart page if (window.location.href.includes("eshop")) { if (event.target.closest(`a[data-test-id="more-suggestions-link"]`)) { return true; } // const isInsideLinksContainer = Boolean(event.target.closest(`ul[class*=headerSearchResultsMoreSuggestionsBlock]`)); // const isLink = Boolean(event.target.closest(`[data-test-id="more-suggestions-link"]`)); // if (isInsideLinksContainer && isLink) // { // const link = event.target.closest(`[data-test-id="more-suggestions-link"]`); // const href = link.getAttribute("href"); // if (href.includes("www")) // { // return true; // } // } } else { if (event.target.closest(".m-searchNavigationResults__linksItems__link ")) { return true; } // const isInsideLinksContainer = Boolean(event.target.closest(`.m-searchNavigationResults__linksItems`)); // const isLink = Boolean(event.target.closest(`.m-searchNavigationResults__linksItems__link`)); // if (isInsideLinksContainer && isLink) // { // const link = event.target.closest(`.m-searchNavigationResults__linksItems__link`); // const href = link.getAttribute("href"); // if (href.includes("www")) // { // return true; // } // } } return false; /* */},"scope":"LOCAL"},{"id":"98de71ca-516e-4a2b-a7af-32fd8de785e5","name":"[Bosch PT] TargetURL for clickout in autosuggestions","type":"FUNCTION","valueType":"TEXT","function":function(event){return event.target.closest("a").getAttribute("href"); /* */},"scope":"LOCAL"},{"id":"baa79840-995a-45a3-8f9d-1d2a1983b109","name":"[Bosch PT] TargetURL for search clickout","type":"FUNCTION","valueType":"TEXT","function":function(event){const categoryTile = event.target.closest(".category-grid-tile"); const hyperlink = categoryTile.querySelector("a"); const hyperlinkValue = hyperlink.getAttribute("href"); return hyperlinkValue; /* */},"scope":"LOCAL"},{"id":"b6d9960e-8afc-4d54-b00f-80bfb9409f8b","name":"[Bosch PT] TransactionID for purchase event","type":"FUNCTION","valueType":"TEXT","function":function(event){const purchaseEvent = dataLayer.find((ev) => ev["1"] === "purchase")["2"]; const transactionID = purchaseEvent.transaction_id; return transactionID; /* */},"scope":"LOCAL"},{"id":"f684a5b4-3a9b-469d-a4d8-dfc15bb2c33e","name":"[Bosch PT] Updated quantity for UPDATE_CART","type":"FUNCTION","valueType":"INTEGER","function":function(event){const productCard = event.target.closest("[class*=lineItemContainer]"); const currentQuantity = Number(productCard.querySelector(`[data-test-id="product-quantity"]`).value); const shouldSubtract = Boolean(event.target.closest(`[data-test-id="decrease-quantity-button"]`)); const shouldAdd = Boolean(event.target.closest(`[data-test-id="increase-quantity-button"]`)); if (shouldAdd) { return currentQuantity + 1; } else if (shouldSubtract) { return currentQuantity - 1; } /* */},"scope":"LOCAL"},{"id":"3b881070-bf08-4869-be93-2b5d94a99c5b","name":"Clickout, category","type":"CONSTANT","valueType":"TEXT","value":"Clickout, category","scope":"GLOBAL"},{"id":"2e141436-b43c-40d6-bbed-64cfdca7f222","name":"Go to PDP - search clickout","type":"CONSTANT","valueType":"TEXT","value":"Go to PDP - search clickout","scope":"GLOBAL"},{"id":"6c77635c-e95a-4eca-8086-f6be1b1193e8","name":"Named referral: Search","type":"CONSTANT","valueType":"TEXT","value":"Search","scope":"GLOBAL"},{"id":"75cf8fd1-fafe-44be-9806-23ff3017c9c1","name":"Page URL","type":"FUNCTION","valueType":"TEXT","function":function(event){return window.location.href; /* */},"scope":"GLOBAL"},{"id":"c0fe42da-f640-40d9-8e2e-9e39ea0c8dfe","name":"Search results","type":"CONSTANT","valueType":"TEXT","value":"Search results","scope":"GLOBAL"}]; const script = {"id":"fe90ed05-cecf-479b-81fa-2b96f5dd904d","rows":[{"id":"7bf05bc7-447f-48ef-97e0-c4213f6571e2","rowType":"CUSTOM_ACTION","trigger":{"id":"1379104d-1c5f-49eb-b892-57e2b0bce5dc","name":"[Bosch PT] Product on PDP has changed","type":"CLICK","groups":[{"id":"ded30c69-a26e-4822-a482-1187058579af","rows":[{"valueType":"BOOLEAN","id":"130714f2-dbac-4897-9aba-223c67eec540","variableId":"ce635408-b5eb-48e4-9b48-949d83c92b29","value":"true","operator":"EQUALS"},{"valueType":"BOOLEAN","id":"3eb131f4-735b-414c-ae3d-5f8a09211341","variableId":"59c718f9-cd2c-4f44-9755-2609e78a2812","value":"true","operator":"EQUALS"}]}]},"action":{"id":"1921ef2a-35e4-4215-b511-0f1dfe6e1e3b","type":"CUSTOM","code":function(event){// The reason setTimeout is necessary is because otherwise this SKU will be checked after a new one is saved // This way ensures we first check the SKU in PDP_VISITED and only afterwards we save new SKU setTimeout(() => { const mainSectionInFirstPDP = document.querySelector("#product-detail-stage"); const secondPdp = document.querySelector(".o-gt-stage"); let sku; if (mainSectionInFirstPDP) { const selectedVariantSku = mainSectionInFirstPDP.getAttribute("data-sku"); const groupIdentifier = utag_data.product_category_id[0]; if (selectedVariantSku) { sku = selectedVariantSku; } else if (groupIdentifier) { sku = groupIdentifier; } sessionStorage.setItem("zoovu-last-selected-sku", sku); } if (secondPdp) { sku = utag_data.product_id[0]; sessionStorage.setItem("zoovu-last-selected-sku", sku); } }, 500) /* */}},"fields":[]},{"id":"ba2fc78d-0cdc-44ed-abd1-375bd133ee60","rowType":"EVENT","trigger":{"id":"1379104d-1c5f-49eb-b892-57e2b0bce5dc","name":"[Bosch PT] Product on PDP has changed","type":"CLICK","groups":[{"id":"ded30c69-a26e-4822-a482-1187058579af","rows":[{"valueType":"BOOLEAN","id":"130714f2-dbac-4897-9aba-223c67eec540","variableId":"ce635408-b5eb-48e4-9b48-949d83c92b29","value":"true","operator":"EQUALS"},{"valueType":"BOOLEAN","id":"3eb131f4-735b-414c-ae3d-5f8a09211341","variableId":"59c718f9-cd2c-4f44-9755-2609e78a2812","value":"true","operator":"EQUALS"}]}]},"action":{"type":"PDP_VISITED"},"fields":[{"id":"29ad4b11-962c-451b-80af-41e4e835a2f9","variableId":"97966e49-2e80-42f2-ab9b-65a4d909d336","fieldName":"locale"},{"id":"46f2a6cf-824d-471b-b034-68297d3c118a","variableId":"f3dd91b8-0939-4ecf-bb28-32c8759d2f4d","fieldName":"sku"},{"id":"dc1751d1-b8ed-493c-8709-89af26b44f04","variableId":"4d44ede1-271d-47d1-a400-2c20e70deaf6","fieldName":"price"},{"id":"794dd387-87fa-4f17-93fa-b3746c344b80","variableId":"5400d372-a64d-4866-9ea8-8311ca5616f1","fieldName":"currencyCode"}]},{"id":"80476de0-dff9-485a-96c8-b87505c88b01","rowType":"CUSTOM_ACTION","trigger":{"id":"d85bd256-0569-4817-bfc1-83dff99a410a","name":"[Bosch PT] Visiting cart page","type":"PAGE_LOAD","groups":[{"id":"b8115873-32e3-4a73-a7d4-35949980c8fc","rows":[{"valueType":"TEXT","id":"ff80f2b3-5b42-441f-a823-1a20be469c33","variableId":"75cf8fd1-fafe-44be-9806-23ff3017c9c1","value":"cart","operator":"CONTAINS"}]}]},"action":{"id":"a050c1bb-ca8e-43ff-9e50-6b029f054d76","type":"CUSTOM","code":function(event){// Workaround for https://zoovu.atlassian.net/browse/COE-7137 function waitForLoaderToDisappear(selector = "[class*=pageLoader]") { return new Promise(resolve => { const check = () => { const loader = document.querySelector(selector); if (!loader) { resolve(); } else { setTimeout(check, 1000); } }; check(); }); } waitForLoaderToDisappear().then(() => { main(); }); function main() { const products = []; const productContainers = document.querySelectorAll("[class*=lineItemContainer]"); function getSKU(productContainer) { const skuFormatted = productContainer.querySelector('[data-test-id="product-sku"]').textContent; const sku = skuFormatted.split(":")[1].trim(); return sku; } function getPricePerUnit(productContainer) { function getCurrentPrice() { const productCard = productContainer; const priceText = productCard.querySelector(`[data-test-id="product-price-block"] div p`).textContent; function parsePrice(str) { // Extract only digits, commas, dots const numberPart = str.match(/[\d.,]+/g)?.join('') || ""; // If the number uses comma as decimal separator (European format) // Detect by checking last comma position const hasCommaAsDecimal = numberPart.includes(',') && numberPart.lastIndexOf(',') > numberPart.lastIndexOf('.'); let normalized = numberPart; if (hasCommaAsDecimal) { // Remove thousand separators and convert final comma to dot normalized = normalized.replace(/\./g, ""); // remove thousand dots normalized = normalized.replace(/,/g, "."); // convert decimal comma } else { // Normal format: remove thousand separators (commas) normalized = normalized.replace(/,/g, ""); } return parseFloat(normalized); } return parsePrice(priceText); } function getCurrentQuantity() { const productCard = productContainer; const currentQuantity = Number(productCard.querySelector(`[data-test-id="product-quantity"]`).value); return currentQuantity; } const currentPrice = getCurrentPrice(); const currentQuantity = getCurrentQuantity(); const pricePerUnit = currentPrice / currentQuantity; return Number(pricePerUnit.toFixed(2)); } Array.from(productContainers).forEach(productContainer => { // https://zoovu.atlassian.net/browse/COE-7225 const productIsAGift = Boolean(productContainer.querySelector("[class*=gift]")); if (!productIsAGift) { products.push({ sku: getSKU(productContainer), pricePerUnit: getPricePerUnit(productContainer) }) } }) sessionStorage.setItem("zoovu-cart-product-prices", JSON.stringify(products)); } /* */}},"fields":[]},{"id":"2559a218-109f-49a4-bd73-4e6a7686df50","rowType":"EVENT","trigger":{"id":"8a545127-e6ee-4e47-96b4-4c990422f08b","name":"[Bosch PT] Category link was clicked on search autosuggestions","type":"CLICK","groups":[{"id":"4e525821-47a3-4bbf-9af9-27a16918d7f2","rows":[{"valueType":"BOOLEAN","id":"116c3f5a-225c-4d29-b2fd-ef8a8f4e478a","variableId":"e22afd9c-c6f7-4e8f-8413-31ded27641a3","value":"true","operator":"EQUALS"}]}]},"action":{"type":"CLICKOUT"},"fields":[{"id":"99ff5f02-7d8d-4765-92b3-5f69038ba653","variableId":"97966e49-2e80-42f2-ab9b-65a4d909d336","fieldName":"locale"},{"id":"621bf5ff-3d16-43df-a53a-c54f27066486","variableId":"98de71ca-516e-4a2b-a7af-32fd8de785e5","fieldName":"targetUrl"},{"id":"2e7cd443-52a3-4ca0-98ff-469fc5e721a4","variableId":"6c77635c-e95a-4eca-8086-f6be1b1193e8","fieldName":"namedReferral"},{"id":"f80e13d9-b809-4165-a449-cbf9c7ff10c1","variableId":"3b881070-bf08-4869-be93-2b5d94a99c5b","fieldName":"eventLabel"}]},{"id":"676e0c4c-6168-4ea9-a5bf-03e307ee659b","rowType":"EVENT","trigger":{"id":"e108d62c-bbec-4725-8dab-ca6542e25c4e","name":"[Bosch PT] On a thank-you page","type":"PAGE_LOAD","groups":[{"id":"527cb3bb-c529-4bc7-ac64-39e29f2282c3","rows":[{"valueType":"TEXT","id":"b51ed31d-a090-4e3d-bbb5-cb46b2162111","variableId":"75cf8fd1-fafe-44be-9806-23ff3017c9c1","value":"confirmation","operator":"CONTAINS"}]}]},"action":{"type":"PURCHASED"},"fields":[{"id":"b3d8b801-f94f-42a4-a0c9-80fc73168b4d","variableId":"dafa3f7c-a241-4d3a-ac9c-389eb07d93bd","fieldName":"currencyCode"},{"id":"31ff6a5a-8f07-4914-8ba0-eae59355807e","variableId":"3194c5d8-d8f5-42c7-b90a-d38b1446b4b1","fieldName":"products"},{"id":"19975fcf-2089-4915-83f5-55d385e6a6b2","variableId":"b6d9960e-8afc-4d54-b00f-80bfb9409f8b","fieldName":"transactionId"}]},{"id":"8196e46e-4515-443a-a627-6b482fa474aa","rowType":"EVENT","trigger":{"id":"f73f4b15-91b3-4f67-ba02-db598f03e5c8","name":"[Bosch PT] Product was clicked on autosuggestions","type":"CLICK","groups":[{"id":"d1b6fdcf-227d-44b2-ada3-ae3716822519","rows":[{"valueType":"BOOLEAN","id":"a9fd50de-7834-4c9b-b920-611acf521591","variableId":"d3e5945a-8e55-4b96-b963-ccbc71ad4352","value":"true","operator":"EQUALS"}]}]},"action":{"type":"CLICKOUT"},"fields":[{"id":"9ee3d9c9-8b3b-4d2b-b111-b3294b7654bf","variableId":"97966e49-2e80-42f2-ab9b-65a4d909d336","fieldName":"locale"},{"id":"2603f3f7-cb19-4657-81b6-99767657123e","variableId":"98de71ca-516e-4a2b-a7af-32fd8de785e5","fieldName":"targetUrl"},{"id":"4cfb1c70-5df4-44cc-b816-f60c97a9b13e","variableId":"6c77635c-e95a-4eca-8086-f6be1b1193e8","fieldName":"namedReferral"},{"id":"d8be23de-8484-469f-a1f5-1db85ce46241","variableId":"2e141436-b43c-40d6-bbed-64cfdca7f222","fieldName":"eventLabel"}]},{"id":"287fd264-4a6b-4202-9903-02e3ef580f2d","rowType":"EVENT","trigger":{"id":"dbb640fb-b6ae-4376-8766-1d852b69fa2f","name":"[Bosch PT] Search input was used","type":"INPUT","groups":[{"id":"8aea98a7-9f6a-4a3a-9251-09079fdb5bc6","rows":[{"valueType":"BOOLEAN","id":"21507487-504e-477b-8c02-e299691aab40","variableId":"c381b7a3-3dd3-4100-9c41-e85911343723","value":"true","operator":"EQUALS"}]}]},"action":{"type":"SEARCH_RESULT"},"fields":[{"id":"d5c87925-a28f-49b5-bf4e-875ba4673248","variableId":"97966e49-2e80-42f2-ab9b-65a4d909d336","fieldName":"locale"},{"id":"f28a6cb2-df16-49d9-a2d0-b92d7b7aa71b","variableId":"6353c517-0b13-4612-8dfd-7a28a75d772b","fieldName":"isEmpty"},{"id":"1f761891-879c-44a4-86c5-ad47804cb85e","variableId":"9acdf70b-14f9-472a-976a-92016cdb6945","fieldName":"skus"},{"id":"14409330-def3-4c1f-b170-385b5d0d729d","variableId":"c0fe42da-f640-40d9-8e2e-9e39ea0c8dfe","fieldName":"eventLabel"}]},{"id":"b96fdaea-d62b-4c6e-a20b-fa39b1c2d70b","rowType":"CUSTOM_ACTION","trigger":{"id":"bf1c2b81-9d97-4c51-89c0-3fb9d0e7cd49","name":"[Bosch PT] Visiting any page","type":"PAGE_LOAD","groups":[{"id":"143ecc59-02c2-42bc-ac96-24ac3de37239","rows":[{"valueType":"BOOLEAN","id":"a6bd8539-c2d2-4eda-bc01-2e62a52cd7b1","variableId":"ce635408-b5eb-48e4-9b48-949d83c92b29","value":"true","operator":"EQUALS"}]},{"id":"13260e13-b9ff-4683-a0eb-ef1ef1882b39","rows":[{"valueType":"BOOLEAN","id":"4165791a-1e33-41d5-a099-c948e81ef760","variableId":"ce635408-b5eb-48e4-9b48-949d83c92b29","value":"false","operator":"EQUALS"}]}]},"action":{"id":"235043b1-d7dc-40da-88b4-62cd4d0bae75","type":"CUSTOM","code":function(event){function getAnalysisConsentFromCookie() { const name = "privacy-consents-v4"; const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length !== 2) return false; const cookieValue = parts.pop().split(';').shift(); const decoded = decodeURIComponent(cookieValue); const parsed = JSON.parse(decoded); return parsed?.consent?.analysis === true; } function onConsentChange() { const consent = getAnalysisConsentFromCookie(); if (consent) { enableTracking(); } else { disableTracking(); } } window.addEventListener("consent_updated", () => { onConsentChange(); }); window.addEventListener("consent_loaded", () => { onConsentChange(); }); onConsentChange(); /* */}},"fields":[]},{"id":"885cd4b6-4407-49fb-b420-8177c44eeed2","rowType":"EVENT","trigger":{"id":"dbb640fb-b6ae-4376-8766-1d852b69fa2f","name":"[Bosch PT] Search input was used","type":"INPUT","groups":[{"id":"8aea98a7-9f6a-4a3a-9251-09079fdb5bc6","rows":[{"valueType":"BOOLEAN","id":"21507487-504e-477b-8c02-e299691aab40","variableId":"c381b7a3-3dd3-4100-9c41-e85911343723","value":"true","operator":"EQUALS"}]}]},"action":{"type":"SEARCH"},"fields":[{"id":"ed1cd622-1d95-4f83-af0e-f3143de2d657","variableId":"97966e49-2e80-42f2-ab9b-65a4d909d336","fieldName":"locale"}]},{"id":"5537e434-8a12-4e91-8b56-359c503afea1","rowType":"EVENT","trigger":{"id":"93db58bf-0211-444e-b5c4-c28d2136bb1b","name":"[Bosch PT] Visiting search result page","type":"PAGE_LOAD","groups":[{"id":"8930a1b1-0932-436b-8436-3855c56cfcd8","rows":[{"valueType":"TEXT","id":"87122eb8-999a-40df-a4ce-1fc399e399cb","variableId":"75cf8fd1-fafe-44be-9806-23ff3017c9c1","value":"?q=","operator":"CONTAINS"}]}]},"action":{"type":"SEARCH_RESULT"},"fields":[{"id":"bb5f904d-70a9-43bc-9908-ae3f9f1e2069","variableId":"97966e49-2e80-42f2-ab9b-65a4d909d336","fieldName":"locale"},{"id":"3a6ec5d5-460b-45ba-8faa-aa5a2554d3bf","variableId":"f2c8b929-18d6-4fa1-9c48-53dcdfe223d5","fieldName":"isEmpty"},{"id":"f34154bb-c561-433e-8518-8f0c2d3bc59a","variableId":"cc08371f-f1bd-4513-9179-7ddb9dda4fd1","fieldName":"skus"},{"id":"415a2c35-195d-4c77-988c-7101c77bcf3e","variableId":"c0fe42da-f640-40d9-8e2e-9e39ea0c8dfe","fieldName":"eventLabel"}]},{"id":"d699f15c-c54f-4e9c-a85e-7b544cac803c","rowType":"EVENT","trigger":{"id":"2abd9f72-cd80-4a47-b2c8-20687a7efc44","name":"[Bosch PT] Search clickout","type":"CLICK","groups":[{"id":"4ac8687f-c405-41a5-bca8-fcc8e8cac6a7","rows":[{"valueType":"BOOLEAN","id":"c5d7b546-fcd8-4006-8566-535af169066b","variableId":"9219e29f-45ce-4e95-884b-c97151c7ee88","value":"true","operator":"EQUALS"}]}]},"action":{"type":"CLICKOUT"},"fields":[{"id":"9141dc0c-8c85-406e-a9a2-356969f130a9","variableId":"97966e49-2e80-42f2-ab9b-65a4d909d336","fieldName":"locale"},{"id":"3ccbf01f-1cf8-41b7-aa97-b61274aa40f7","variableId":"baa79840-995a-45a3-8f9d-1d2a1983b109","fieldName":"targetUrl"},{"id":"dcdc8898-0e5e-4d79-b1b7-7efc27ac2f6d","variableId":"6c77635c-e95a-4eca-8086-f6be1b1193e8","fieldName":"namedReferral"},{"id":"f317617f-2afb-4cf4-a3b8-481663ac470c","variableId":"2e141436-b43c-40d6-bbed-64cfdca7f222","fieldName":"eventLabel"}]},{"id":"08c8d865-4947-4c62-ab69-37328fd1d8c5","rowType":"CUSTOM_ACTION","trigger":{"id":"91fac70f-18cc-497f-b3f6-4632951f77e6","name":"[Bosch PT] Visiting PDP (whether it has product selected or not)","type":"PAGE_LOAD","groups":[{"id":"b95b1078-b8e6-4dbd-b3a2-1bffce166e60","rows":[{"valueType":"BOOLEAN","id":"50b60b3c-f79d-4359-a748-51617a5d39f0","variableId":"90055979-6dde-4e58-919a-7e7db009aae3","value":"true","operator":"EQUALS"}]}]},"action":{"id":"1921ef2a-35e4-4215-b511-0f1dfe6e1e3b","type":"CUSTOM","code":function(event){// The reason setTimeout is necessary is because otherwise this SKU will be checked after a new one is saved // This way ensures we first check the SKU in PDP_VISITED and only afterwards we save new SKU setTimeout(() => { const mainSectionInFirstPDP = document.querySelector("#product-detail-stage"); const secondPdp = document.querySelector(".o-gt-stage"); let sku; if (mainSectionInFirstPDP) { const selectedVariantSku = mainSectionInFirstPDP.getAttribute("data-sku"); const groupIdentifier = utag_data.product_category_id[0]; if (selectedVariantSku) { sku = selectedVariantSku; } else if (groupIdentifier) { sku = groupIdentifier; } sessionStorage.setItem("zoovu-last-selected-sku", sku); } if (secondPdp) { sku = utag_data.product_id[0]; sessionStorage.setItem("zoovu-last-selected-sku", sku); } }, 500) /* */}},"fields":[]},{"id":"478ff873-ad10-403e-8fe4-64308848b0f3","rowType":"EVENT","trigger":{"id":"510ea37f-195f-4c9f-ad94-9f4aa528c519","name":"[Bosch PT] Visiting PDP","type":"PAGE_LOAD","groups":[{"id":"9da0cc36-5ff8-44da-9f9c-1febbb673e56","rows":[{"valueType":"BOOLEAN","id":"e3c43f55-edc6-4fc5-8875-54f9a048619d","variableId":"ce635408-b5eb-48e4-9b48-949d83c92b29","value":"true","operator":"EQUALS"}]}]},"action":{"type":"PDP_VISITED"},"fields":[{"id":"40e00284-2dec-419f-b92a-589621e29e9d","variableId":"97966e49-2e80-42f2-ab9b-65a4d909d336","fieldName":"locale"},{"id":"fa6aae2d-d42b-43b1-9022-bf552b82c5f7","variableId":"f3dd91b8-0939-4ecf-bb28-32c8759d2f4d","fieldName":"sku"},{"id":"1f3c0e19-7ec1-40d7-8453-060c8a2da61d","variableId":"4d44ede1-271d-47d1-a400-2c20e70deaf6","fieldName":"price"},{"id":"3b4743b4-d0f4-40fa-b9dd-0d322cb0df98","variableId":"5400d372-a64d-4866-9ea8-8311ca5616f1","fieldName":"currencyCode"}]},{"id":"af8a0c26-9352-4627-b4d3-4b481b6c8841","rowType":"EVENT","trigger":{"id":"bb7e66ca-d6f4-44e5-b738-6c458a7406b3","name":"[Bosch PT] Cart quantity was changed","type":"CLICK","groups":[{"id":"c6833a3a-f2b7-4caf-83ab-dd6db1004525","rows":[{"valueType":"BOOLEAN","id":"8fe7a961-df94-49a9-ba91-5fa0b70b693d","variableId":"c648b7b3-561b-4aa3-a35e-cad90bd6aa87","value":"true","operator":"EQUALS"}]}]},"action":{"type":"UPDATE_CART"},"fields":[{"id":"c98eecc7-15cb-4c54-b396-77c5bcc916be","variableId":"97966e49-2e80-42f2-ab9b-65a4d909d336","fieldName":"locale"},{"id":"2bb8281b-1304-42b7-8496-eed677202704","variableId":"af1f6746-9b0a-467c-9eb8-fab74479a700","fieldName":"sku"},{"id":"90af029a-3074-49d8-852f-21a458aad193","variableId":"b3d67dce-a9a9-468f-9360-d80eae8d665b","fieldName":"price"},{"id":"535f1fe5-e5ef-436b-ac96-045be6de66bc","variableId":"5400d372-a64d-4866-9ea8-8311ca5616f1","fieldName":"currencyCode"},{"id":"7bb91454-23e4-4eab-8b77-65a2a71d0c74","variableId":"f684a5b4-3a9b-469d-a4d8-dfc15bb2c33e","fieldName":"quantity"}]},{"id":"91b5e8db-c3db-4269-afe1-9f24aef1b6e3","rowType":"EVENT","trigger":{"id":"0bb302ba-438f-47a0-8260-4575e8fb6127","name":"[Bosch PT] Product was removed from cart","type":"CLICK","groups":[{"id":"ad9a3be4-1ae8-4ee2-8ff2-83936a349eb8","rows":[{"valueType":"BOOLEAN","id":"38927020-e7f3-4e58-8b31-75655f76dfe1","variableId":"d11d4343-6f33-4ffd-9207-aa43f2677671","value":"true","operator":"EQUALS"}]}]},"action":{"type":"REMOVE_FROM_CART"},"fields":[{"id":"ac66656d-f851-4934-a0b4-616f5cc07d91","variableId":"97966e49-2e80-42f2-ab9b-65a4d909d336","fieldName":"locale"},{"id":"e205baf6-12db-4bfe-adbb-971a79a096f6","variableId":"af1f6746-9b0a-467c-9eb8-fab74479a700","fieldName":"sku"},{"id":"946cbe62-802b-4b68-bcd3-b343704cb2b4","variableId":"b3d67dce-a9a9-468f-9360-d80eae8d665b","fieldName":"price"},{"id":"a7e3d61c-6270-4817-9d06-4cb63d0d3a87","variableId":"5400d372-a64d-4866-9ea8-8311ca5616f1","fieldName":"currencyCode"},{"id":"2a97f1d0-b620-4978-988f-8c8a03092fd5","variableId":"bf72883a-4663-41ed-baf6-584175490328","fieldName":"quantity"}]},{"id":"6267aa6b-f473-4e40-bdc3-c7404863eeac","rowType":"EVENT","trigger":{"id":"4ee86f61-bdc2-4358-a320-002b0cc0286d","name":"[Bosch PT] ATC button on PDP clicked","type":"CLICK","groups":[{"id":"f8b1df8b-94d3-4150-87e8-4d5112fa55cd","rows":[{"valueType":"BOOLEAN","id":"5ac7d40a-6750-4e3c-a076-82965644cc60","variableId":"7a089517-a9dd-4fb4-a822-f2086593e99b","value":"true","operator":"EQUALS"}]}]},"action":{"type":"ADD_TO_CART"},"fields":[{"id":"8dfce2ce-252c-464d-9935-4a9cf8938d2d","variableId":"97966e49-2e80-42f2-ab9b-65a4d909d336","fieldName":"locale"},{"id":"74ea1ee2-a198-4dcf-af0c-0c8e28c48d6b","variableId":"5a950c76-96c5-41f3-8f9b-d83de69cd69b","fieldName":"sku"},{"id":"349c18af-8302-4b54-90a2-a3e4f2b5cf46","variableId":"a4097d75-887f-4947-a618-415b4f4ef370","fieldName":"price"},{"id":"100ffc40-601a-495d-9fd2-3e4605236609","variableId":"5400d372-a64d-4866-9ea8-8311ca5616f1","fieldName":"currencyCode"},{"id":"2b86aea3-0ae8-4c56-8f23-f5d261707bd3","variableId":"1330574d-7910-45d3-b50c-e0e82bfc11f8","fieldName":"quantity"}]},{"id":"f6f1dcf9-26cb-4285-9518-b57b6463d81c","rowType":"EVENT","trigger":{"id":"60d5d091-48ed-4b41-b029-fc5b70e81a32","name":"[Bosch PT] Visiting a page that isn't PDP","type":"PAGE_LOAD","groups":[{"id":"649644e3-2f06-480e-880e-685f270cf839","rows":[{"valueType":"BOOLEAN","id":"b5151fb5-6b77-4b36-aa1e-014551a10cdb","variableId":"0f6a3dfb-49ad-486c-baa4-bb55bb2b1a30","value":"false","operator":"EQUALS"}]}]},"action":{"type":"PAGE_VISITED"},"fields":[{"id":"6b556e11-1081-4153-b5f4-d9cf6ea6b302","variableId":"97966e49-2e80-42f2-ab9b-65a4d909d336","fieldName":"locale"}]}]}; const advancedCode = function(){}; const url = 'https://queue-propagator.zoovu.com'; const currentEnvironment = 'orca'; const currentAccountId = 2729; const currencies = ['FJD', 'MXN', 'STD', 'LVL', 'SCR', 'CDF', 'BBD', 'UGX', 'HNL', 'MXV', 'ZAR', 'STN', 'CUC', 'BSD', 'SDD', 'SDG', 'IQD', 'GMD', 'CUP', 'TWD', 'RSD', 'UYI', 'MYR', 'FKP', 'XOF', 'UYU', 'CVE', 'OMR', 'SEK', 'KES', 'BTN', 'GNF', 'MZN', 'SVC', 'MZM', 'ARS', 'QAR', 'NLG', 'IRR', 'XPD', 'UZS', 'THB', 'XPF', 'BDT', 'LYD', 'KWD', 'XPT', 'RUB', 'ISK', 'BEF', 'MKD', 'RUR', 'DZD', 'PAB', 'SGD', 'KGS', 'XAD', 'XAF', 'XAG', 'ITL', 'ATS', 'CHF', 'HRK', 'CHE', 'DJF', 'TZS', 'XAU', 'VND', 'ADP', 'AUD', 'CHW', 'KHR', 'IDR', 'XBA', 'KYD', 'XBC', 'XBB', 'SHP', 'BWP', 'CYP', 'XBD', 'TJS', 'RWF', 'AED', 'DKK', 'BGL', 'ZWD', 'BGN', 'MMK', 'SYP', 'ZWG', 'NOK', 'ZWL', 'YUM', 'ZWN', 'LKR', 'ZWR', 'IEP', 'CZK', 'XCD', 'GRD', 'HTG', 'XSU', 'AFA', 'XCG', 'SIT', 'BHD', 'PTE', 'SZL', 'KZT', 'YER', 'AFN', 'BYB', 'AWG', 'NPR', 'MNT', 'GBP', 'BYN', 'XTS', 'HUF', 'BYR', 'BIF', 'XUA', 'XDR', 'BZD', 'MOP', 'NAD', 'SKK', 'TMM', 'PEN', 'WST', 'TMT', 'FRF', 'CLF', 'GTQ', 'CLP', 'TND', 'SLE', 'SLL', 'AYM', 'XFO', 'DOP', 'KMF', 'XFU', 'GEL', 'MAD', 'TOP', 'AZM', 'PGK', 'AZN', 'UAH', 'ERN', 'TPE', 'MRO', 'CNY', 'MRU', 'BMD', 'PHP', 'XXX', 'PYG', 'JMD', 'GWP', 'ESP', 'COP', 'USD', 'COU', 'USN', 'VEB', 'ETB', 'USS', 'VED', 'SOS', 'VEF', 'VUV', 'LAK', 'BND', 'ZMK', 'LRD', 'ALL', 'GHC', 'MTL', 'VES', 'ZMW', 'TRL', 'ILS', 'GHS', 'KPW', 'GYD', 'MDL', 'BOB', 'AMD', 'TRY', 'LBP', 'JOD', 'HKD', 'EUR', 'LSL', 'CAD', 'BOV', 'EEK', 'MUR', 'ROL', 'GIP', 'RON', 'NGN', 'CRC', 'PKR', 'ANG', 'SRD', 'TTD', 'LTL', 'SAR', 'MVR', 'SRG', 'INR', 'KRW', 'JPY', 'PLN', 'AOA', 'SBD', 'CSD', 'LUF', 'MWK', 'MGA', 'FIM', 'MGF', 'DEM', 'BAM', 'EGP', 'SSP', 'NIO', 'NZD', 'BRL'] // ------------------------- API ------------------------- let trackingEnabled = true; function disableTracking() { trackingEnabled = false; } function enableTracking() { trackingEnabled = true; } function getNumericPriceFromString(stringPrice) { const parsedPrice = stringPrice .replace(/\.$/, '') .replace(/([^.',\s\d])*/g, '') .replace(/([.',\s](?=\d{3}))/g, '') .replace(/([.',](?=\d{2}))/g, '.'); return Number(parsedPrice); } class TrackingExecutionError extends Error { constructor(message, trackingEntityType, variableId, triggerId, scriptId, trackingErrorType) { super(message); this.trackingEntityType = trackingEntityType; this.variableId = variableId; this.triggerId = triggerId; this.scriptId = scriptId; this.trackingErrorType = trackingErrorType; } } // ------------------------- helpers ------------------------- const eventTypes = Object.freeze({ PAGE_VISITED: "PAGE_VISITED", ADD_TO_CART: "ADD_TO_CART", REMOVE_FROM_CART: "REMOVE_FROM_CART", PDP_VISITED: "PDP_VISITED", PURCHASED: "PURCHASED", UPDATE_CART: "UPDATE_CART", DECLINE_TRACKING: "DECLINE_TRACKING", SEARCH: "SEARCH", SEARCH_RESULT: "SEARCH_RESULT", CLICKOUT: "CLICKOUT", LEAD_GEN: "LEAD_GEN" }); const trackingEventTypes = Object.freeze({ TRACKING_SUCCESSFUL_EXECUTION: 'TRACKING_SUCCESSFUL_EXECUTION', TRACKING_EXECUTION_FAILURE: 'TRACKING_EXECUTION_FAILURE' }) const actionTypes = Object.freeze({ ...eventTypes, CUSTOM: 'CUSTOM' }) const triggerTypes = Object.freeze({ CLICK: 'CLICK', INPUT: 'INPUT', PAGE_LOAD: 'PAGE_LOAD' }); const variableTypes = Object.freeze({ FUNCTION: 'FUNCTION', CONSTANT: 'CONSTANT' }); const trackingEntityTypes = Object.freeze({ VARIABLE: 'VARIABLE', TRIGGER: 'TRIGGER', CUSTOM_ACTION: 'CUSTOM_ACTION' }); const trackingErrorTypes = Object.freeze({ MISSING_VALUE: 'MISSING_VALUE', TYPE_MISMATCH: 'TYPE_MISMATCH', UNSUPPORTED_VARIABLE: 'UNSUPPORTED_VARIABLE', MISSING_VARIABLE: 'MISSING_VARIABLE', OTHER: 'OTHER' }); const trackingVariableScopes = Object.freeze({ GLOBAL: 'GLOBAL', LOCAL: 'LOCAL' }); const namedReferrals = Object.freeze({ SEARCH: 'SEARCH' }) const getElementAttribute = (target, attributeName) => { const attribute = target[attributeName]; if (typeof attribute === 'string') { return attribute; } if (attribute && attribute.baseVal !== undefined) { return attribute.baseVal; } return target.getAttribute(attributeName === 'className' ? 'class' : attributeName) || ''; }; const getElementId = (target) => { return getElementAttribute(target, 'id'); }; const getElementClassName = (target) => { return getElementAttribute(target, 'className'); }; const matchers = Object.freeze({ EQUALS: (a, b) => a === b, DOES_NOT_EQUAL: (a, b) => a !== b, CONTAINS: (a, b) => a.indexOf(b) >= 0, DOES_NOT_CONTAIN: (a, b) => a.indexOf(b) === -1, GREATER_THAN: (a, b) => a > b, LESS_THAN: (a, b) => a < b, GREATER_THAN_OR_EQUAL: (a, b) => a >= b, LESS_THAN_OR_EQUAL: (a, b) => a <= b, MATCHES_CSS_SELECTOR: (target, test) => target.matches(test), MATCHES_ID: (target, test) => getElementId(target) === test, CONTAINS_ID: (target, test) => getElementId(target).includes(test), DOES_NOT_CONTAIN_ID: (target, test) => !getElementId(target).includes(test), MATCHES_CLASS: (target, test) => getElementClassName(target) === test, CONTAINS_CLASS: (target, test) => getElementClassName(target).includes(test), DOES_NOT_CONTAIN_CLASS: (target, test) => !getElementClassName(target).includes(test), MATCHES_REGEX: (a, b) => parseRegexString(b).test(a), }); const trackingFieldName = `${domainId}_${zoovuId}_trackingExecutions` const MAX_RECORDS = 100 const DEBOUNCE_TIME = 1500 // helper to retrieve variableId later let eventFields = [] if (!JSON.parse(localStorage.getItem(trackingFieldName))) { localStorage.setItem(trackingFieldName, JSON.stringify([])) } function parseRegexString(input) { const trimmed = input.trim(); // check if it starts and ends with slashes (e.g., /^abc$/gi) const match = trimmed.match(/^\/(.+)\/([a-z]*)$/i); if (match) { const pattern = match[1]; const flags = match[2]; return new RegExp(pattern, flags); } // no flags return new RegExp(trimmed); } function checkValue(type, value) { switch (type) { case 'BOOLEAN': return value === true || value === 'true'; case 'TEXT': return value; case 'DECIMAL': return typeof value === 'string' ? parseFloat(value) : value; case 'INTEGER': return typeof value === 'string' ? parseInt(value) : value; default: return value; } } function cast(type, value) { switch (type) { case 'BOOLEAN': return value === true || value === 'true'; case 'TEXT': return value; case 'DECIMAL': return typeof value === 'string' ? parseFloat(value) : value; case 'INTEGER': return typeof value === 'string' ? parseInt(value) : value; default: return value; } } function debounce(fn, delay) { let lastCallTime = 0; let animationFrameId = null; let isScheduled = false; function execute(context, args, currentTime) { if (currentTime - lastCallTime >= delay) { fn.apply(context, args); isScheduled = false; } else { animationFrameId = requestAnimationFrame((newTime) => { execute(context, args, newTime); }); } } return function () { const context = this, args = arguments; lastCallTime = performance.now(); if (!isScheduled) { isScheduled = true; animationFrameId = requestAnimationFrame((currentTime) => { execute(context, args, currentTime); }); } }; } function getOrganization() { return zoovuId; } function getDomainId() { return domainId; } function getTimezone() { return Intl.DateTimeFormat().resolvedOptions().timeZone; } function getReferrer() { const referrer = document.referrer; if (/^(https?|android-app):\/\//i.test(referrer)) { return referrer; } else { return undefined; } } function getPath() { return window.location.href.replace(window.location.origin, ''); } function getCookieValue(cookieName) { const cookies = document.cookie.split('; '); for (let i = 0; i < cookies.length; i++) { const cookie = cookies[i].split('='); if (cookie[0] === cookieName) { return cookie[1]; } } return null; } function generateUuid() { return self.crypto.randomUUID(); } function addZoovuCidToCookies() { const uuid = generateUuid(); const zoovuCid = `zoovu-cid=${uuid}; path=/`; document.cookie = zoovuCid; return uuid; } function getCID() { return getCookieValue(`zoovu-cid`) !== null ? getCookieValue(`zoovu-cid`) : addZoovuCidToCookies(); } function getEnvironment() { return currentEnvironment; } function getAccountId() { return currentAccountId; } function getPropertyTypeError(propertyName, expectedType, currentType) { return `TYPE MISMATCH: ${propertyName}: should be ${expectedType} but is ${currentType}` } function typeCheckValue(value, variableType, propertyName, variableId, triggerId) { let errorMessage = ''; if (value === undefined || value === null) { throw new TrackingExecutionError(`${propertyName}: value is not defined.`, trackingEntityTypes.VARIABLE, variableId, triggerId, script.id, trackingErrorTypes.MISSING_VALUE) } switch (variableType) { case "TEXT": if (typeof value !== 'string') errorMessage = getPropertyTypeError(propertyName, 'string', typeof value); break; case "INTEGER": case "DECIMAL": if (typeof value !== 'number') errorMessage = getPropertyTypeError(propertyName, 'number', typeof value); break; case "BOOLEAN": if (typeof value !== 'boolean') errorMessage = getPropertyTypeError(propertyName, 'boolean', typeof value); break; case 'LIST': if (!Array.isArray(value)) errorMessage = getPropertyTypeError(propertyName, 'list', typeof value); break; case 'EVENT': break; default: throw new TrackingExecutionError(`Not supported variable type: ${variableType}`, trackingEntityTypes.VARIABLE, variableId, triggerId, script.id, trackingErrorTypes.UNSUPPORTED_VARIABLE) } if (errorMessage) { throw new TrackingExecutionError(errorMessage, trackingEntityTypes.VARIABLE, variableId, triggerId, script.id, trackingErrorTypes.TYPE_MISMATCH) } } function ensureRequiredFieldsPresent(fields, eventType) { return Object.entries(fields).every(([key, value]) => { if (!value) { const variableId = eventFields.find(field => field.fieldName === key).variableId; // empty eventFields eventFields = []; throw new TrackingExecutionError( `Required property ${key} missing value for ${eventType}.`, trackingEntityTypes.VARIABLE, variableId, null, script.id, trackingErrorTypes.MISSING_VALUE ) } return true; }); } function getBaseEventBody(eventType) { return { origin: 'CLIENT', queryParams: {}, organization: getOrganization(), domainId: getDomainId(), path: getPath(), referrer: getReferrer(), cid: getCID(), timezone: getTimezone(), // dynamic eventType: eventType ?? '', eventLabel: '', }; } function getEventExecutable(actionType) { switch (actionType) { case actionTypes.PAGE_VISITED: return sendPageVisitedEvent; case actionTypes.ADD_TO_CART: return sendAddToCartEvent; case actionTypes.CLICKOUT: return sendClickoutEvent; case actionTypes.REMOVE_FROM_CART: return sendRemoveFromCartEvent; case actionTypes.PDP_VISITED: return sendPdpVisitedEvent; case actionTypes.PURCHASED: return sendPurchaseEvent; case actionTypes.DECLINE_TRACKING: return sendDeclineTrackingEvent; case actionTypes.UPDATE_CART: return sendUpdateCartEvent; case actionTypes.SEARCH: return sendSearchEvent; case actionTypes.SEARCH_RESULT: return sendSearchResultEvent; case actionTypes.LEAD_GEN: return sendLeadGenEvent; } } function checkSpecificFieldValues(fieldName, value, variableId) { if (fieldName === 'currencyCode' && !currencies.includes(value)) { throw new TrackingExecutionError( `Value ${value} is not compatible with currencyCode.`, trackingEntityTypes.VARIABLE, variableId, null, script.id, trackingErrorTypes.OTHER ) } if (fieldName === 'namedReferral' && !namedReferrals[value.toUpperCase()]) { throw new TrackingExecutionError( `Value ${value} is not compatible with namedReferral.`, trackingEntityTypes.VARIABLE, variableId, null, script.id, trackingErrorTypes.OTHER ) } } function getVariableValueById(variableId, event, fieldName, triggerId) { const foundVariable = variables.find(v => v.id === variableId); let variableValue = null; if (foundVariable) { if (foundVariable.type === variableTypes.CONSTANT) { variableValue = cast(foundVariable.valueType, foundVariable.value); } else if (foundVariable.type === variableTypes.FUNCTION && typeof foundVariable.function === 'function') { try { variableValue = foundVariable.function(event); } catch (e) { throw new TrackingExecutionError( e.message, trackingEntityTypes.VARIABLE, variableId, triggerId, script.id, trackingErrorTypes.OTHER ) } } else { throw new TrackingExecutionError( `${foundVariable.type} is not supported.`, trackingEntityTypes.VARIABLE, variableId, triggerId, script.id, trackingErrorTypes.UNSUPPORTED_VARIABLE ) } typeCheckValue(variableValue, foundVariable.valueType, fieldName ? fieldName : foundVariable.name, variableId, triggerId); if (fieldName === 'currencyCode' || fieldName === 'namedReferral') { checkSpecificFieldValues(fieldName, variableValue, variableId) } return variableValue; } else { throw new TrackingExecutionError( `No variable with ID ${variableId}`, trackingEntityTypes.VARIABLE, variableId, triggerId, script.id, trackingErrorTypes.MISSING_VARIABLE ) } } function evaluateSingleTriggerRow(row, event, triggerId) { const target = getVariableValueById(row.variableId, event, undefined, triggerId); const matcher = matchers[row.operator]; checkValue(row.valueType, row.value); const value = cast(row.valueType, row.value); if (matcher && typeof matcher === 'function') { return matcher(target, value); } return false; } function preparePayloadFromFields(fields, event) { const payload = {}; fields.forEach(f => { payload[f.fieldName] = getVariableValueById(f.variableId, event, f.fieldName) }) return payload; } function evaluateTriggerConditions(trigger, event) { // OR between groups return trigger.groups.some(group => // AND between rows group.rows.every(row => evaluateSingleTriggerRow(row, event, trigger.id))) } function runAction(action, fields, event, trigger) { const trackingExecutions = jsonParser(trackingFieldName) if (action.type === actionTypes.CUSTOM && typeof action.code === 'function') { // add script custom action trackingExecutions.push(createTrackingSuccessfulExecutionRecord(trackingEntityTypes.CUSTOM_ACTION, action.id)) try { action.code(event); } catch (e) { throw new TrackingExecutionError( e.message, trackingEntityTypes.CUSTOM_ACTION, action.id, null, script.id, trackingErrorTypes.OTHER ) } localStorage.setItem(trackingFieldName, JSON.stringify(trackingExecutions)); } else { const sendEventFunction = getEventExecutable(action.type); eventFields = [...fields]; if (sendEventFunction && typeof sendEventFunction === 'function') { const payload = preparePayloadFromFields(fields, event) sendEventFunction(payload); addSuccessfulExecutions(trigger, fields) } } } function evaluateSingleRule(rule, event) { if (evaluateTriggerConditions(rule.trigger, event)) { runAction(rule.action, rule.fields, event, rule.trigger); } } function evaluateRules(rules, event) { try { rules.forEach(rule => { evaluateSingleRule(rule, event) }); } catch (error) { const trackingExecutions = jsonParser(trackingFieldName); const {message, trackingEntityType, variableId, triggerId, scriptId, trackingErrorType} = error; const failedExecution = createTrackingFailedExecutionRecord( trackingEntityType, variableId, triggerId, scriptId, trackingErrorType, message ) trackingExecutions.push(failedExecution) localStorage.setItem(trackingFieldName, JSON.stringify(trackingExecutions)); console.debug(error) } } function observeAndReactOnPageChange(callback) { let oldHref; if (oldHref === undefined) { callback(); oldHref = document.location.href; } const body = document.querySelector('body'); const observer = new MutationObserver(() => { if (oldHref !== document.location.href) { oldHref = document.location.href; callback(); } }); observer.observe(body, {childList: true, subtree: true}); } function executeAdvancedCode() { if (typeof advancedCode === 'function') { advancedCode(); } } function jsonParser(key) { const foundValue = JSON.parse(localStorage.getItem(key)) if (!Array.isArray(foundValue)) { throw Error('Invalid value in localStorage for key ' + key) } return foundValue } function createTrackingSuccessfulExecutionRecord(entityType, entityId) { const executionTime = Date.now(); return { organization: getOrganization(), domainId: getDomainId(), eventType: trackingEventTypes.TRACKING_SUCCESSFUL_EXECUTION, trackingEntityType: entityType, trackingEntityId: entityId, executionTime } } function createTrackingFailedExecutionRecord(entityType, entityId, triggerId, scriptId, errorType, message) { const executionTime = Date.now(); return { organization: getOrganization(), domainId: getDomainId(), eventType: trackingEventTypes.TRACKING_EXECUTION_FAILURE, trackingEntityType: entityType, trackingEntityId: entityId, executionTime, triggerId: triggerId || null, scriptId: scriptId || null, error: { type: errorType, message } } } function addSuccessfulExecutions(trigger, fields) { const successfulExecutions = jsonParser(trackingFieldName) // add script trigger successfulExecutions.push(createTrackingSuccessfulExecutionRecord(trackingEntityTypes.TRIGGER, trigger.id)) // add script function variables fields.forEach(field => { const foundVariableInField = variables.find(variable => variable.id === field.variableId) if (foundVariableInField.type === variableTypes.FUNCTION && foundVariableInField.scope === trackingVariableScopes.LOCAL) { successfulExecutions.push(createTrackingSuccessfulExecutionRecord(trackingEntityTypes.VARIABLE, foundVariableInField.id)) } }) // add trigger function variables trigger.groups.forEach(groups => { groups.rows.forEach(row => { const foundVariable = variables.find(variable => variable.id === row.variableId) if (foundVariable.type === variableTypes.FUNCTION && foundVariable.scope === trackingVariableScopes.LOCAL) { successfulExecutions.push(createTrackingSuccessfulExecutionRecord(trackingEntityTypes.VARIABLE, foundVariable.id)) } }) }) localStorage.setItem(trackingFieldName, JSON.stringify(successfulExecutions)); } // ------------------------- events ------------------------- async function sendEvent(body) { if (trackingEnabled) { await fetch(`${url}/fact`, { method: 'POST', mode: 'cors', cache: 'no-cache', credentials: 'same-origin', headers: { 'Content-Type': 'application/json', }, redirect: 'follow', referrerPolicy: 'no-referrer', body: JSON.stringify(body), }); } else { console.debug("Tracking disabled - no permission to track"); } } async function sendSSTRPurchaseEvent(body) { if (trackingEnabled) { const purchaseUrl = 'https://ev-co.zoovu.com/v1/CollectSalesEvent'; await fetch(purchaseUrl, { method: 'POST', mode: 'cors', cache: 'no-cache', headers: { 'Content-Type': 'application/json', }, redirect: 'follow', referrerPolicy: 'no-referrer', body: JSON.stringify(body), }); } else { console.debug("Tracking disabled - no permission to track"); } } async function sendTrackingSuccessfulExecution(body) { if (trackingEnabled) { await fetch(`${url}/tracking/executions`, { method: 'POST', mode: 'cors', cache: 'no-cache', headers: { 'Content-Type': 'application/json', }, redirect: 'follow', referrerPolicy: 'no-referrer', body: JSON.stringify(body), }); } else { console.debug("Tracking disabled - no permission to track"); } } function sendFactEventBase(eventType, eventSpecificBody) { const body = { ...getBaseEventBody(eventType), // event label + custom per-event fields ...eventSpecificBody, }; sendEvent(body); }; function sendPageVisitedEvent({locale, category, eventLabel = 'Page visit'}) { const body = { locale, eventLabel, // optional category, }; if (ensureRequiredFieldsPresent({locale}, eventTypes.PAGE_VISITED)) { sendFactEventBase(eventTypes.PAGE_VISITED, body); } }; function sendPdpVisitedEvent({ locale, sku, quantity = 1, currencyCode, eventLabel = "Product details page visit", price, category }) { const body = { locale, sku, eventLabel, // optional category, price, currencyCode, quantity, }; if (ensureRequiredFieldsPresent({locale, sku}, eventTypes.PDP_VISITED)) { sendFactEventBase(eventTypes.PDP_VISITED, body); } }; function sendAddToCartEvent({ locale, sku, quantity = 1, currencyCode, eventLabel = "Add to cart", price, category }) { const body = { locale, sku, eventLabel, // optional category, price, currencyCode, quantity, }; if (ensureRequiredFieldsPresent({locale, sku}, eventTypes.ADD_TO_CART)) { sendFactEventBase(eventTypes.ADD_TO_CART, body); } }; function sendRemoveFromCartEvent({ locale, sku, quantity = 1, currencyCode, eventLabel = "Remove from cart", price, category }) { const body = { locale, sku, eventLabel, // optional category, price, currencyCode, quantity, }; if (ensureRequiredFieldsPresent({locale, sku}, eventTypes.REMOVE_FROM_CART)) { sendFactEventBase(eventTypes.REMOVE_FROM_CART, body); } }; function sendUpdateCartEvent({ locale, sku, quantity = 1, currencyCode, eventLabel = "Update cart", price, category }) { const body = { locale, sku, eventLabel, // optional category, price, currencyCode, quantity, }; if (ensureRequiredFieldsPresent({locale, sku}, eventTypes.UPDATE_CART)) { sendFactEventBase(eventTypes.UPDATE_CART, body); } }; function sendDeclineTrackingEvent({ locale, eventLabel = "No permission to track", category }) { const body = { locale, eventLabel, // optional category }; if (ensureRequiredFieldsPresent({locale}, eventTypes.DECLINE_TRACKING)) { sendFactEventBase(eventTypes.DECLINE_TRACKING, body); disableTracking(); } }; function sendSearchEvent({ locale, eventLabel = "Search phrase typed", category }) { const body = { locale, eventLabel, // optional category, }; if (ensureRequiredFieldsPresent({locale}, eventTypes.SEARCH)) { sendFactEventBase(eventTypes.SEARCH, body); } }; function sendSearchResultEvent({ locale, isEmpty = false, eventLabel = "Search results", skus, category }) { const body = { locale, isEmpty, skus, eventLabel, // optional category }; if (ensureRequiredFieldsPresent({locale, skus}, eventTypes.SEARCH_RESULT)) { sendFactEventBase(eventTypes.SEARCH_RESULT, body); } }; function sendClickoutEvent({ locale, targetUrl, namedReferral, eventLabel = "Clickout", category }) { const body = { locale, targetUrl, namedReferral, eventLabel, // optional category }; if (ensureRequiredFieldsPresent({locale, targetUrl, namedReferral}, eventTypes.CLICKOUT)) { sendFactEventBase(eventTypes.CLICKOUT, body); } }; function sendPurchaseEvent({ currencyCode, transactionId, products }) { const sstrBody = { transactionId, products, currency: currencyCode, browserTimestamp: Date.now(), env: getEnvironment(), accountId: getAccountId(), clientId: getCID(), }; if (ensureRequiredFieldsPresent({products, currencyCode,}, eventTypes.PURCHASED)) { sendSSTRPurchaseEvent(sstrBody); } }; function sendLeadGenEvent({ locale, currencyCode, products, leadId, leadType, category, eventLabel = "Lead gen sent" }) { const body = { locale, eventLabel, // optional currencyCode, products, leadId, leadType, category }; if (ensureRequiredFieldsPresent({locale}, eventTypes.LEAD_GEN)) { sendFactEventBase(eventTypes.LEAD_GEN, body); } }; function sendSuccessfulExecutionEvent(forceSend) { const successfulExecutions = jsonParser(trackingFieldName) if (successfulExecutions.length === MAX_RECORDS || (forceSend && successfulExecutions.length > 0)) { sendTrackingSuccessfulExecution(successfulExecutions) localStorage.setItem(trackingFieldName, JSON.stringify([])) } } // ------------------------- core ------------------------- function reactOnLoad() { const pageLoadRules = script.rows.filter(row => row.trigger.type === triggerTypes.PAGE_LOAD); window.addEventListener("load", (event) => { observeAndReactOnPageChange(() => evaluateRules(pageLoadRules, event) && sendSuccessfulExecutionEvent()) }, {capture: true}); } function reactOnClick() { const clickRules = script.rows.filter(row => row.trigger.type === triggerTypes.CLICK); // click via mouse document.querySelector('body').addEventListener('mousedown', (event) => { evaluateRules(clickRules, event); sendSuccessfulExecutionEvent() }, {capture: true}); // click via enter button document.querySelector('body').addEventListener('keydown', (event) => { if (event.code === "Enter" || event.code === "NumpadEnter") { evaluateRules(clickRules, event); sendSuccessfulExecutionEvent() } }, {capture: true}); } function reactOnInput() { const inputRules = script.rows.filter(row => row.trigger.type === triggerTypes.INPUT); document.querySelector('body').addEventListener('input', debounce(function (event) { evaluateRules(inputRules, event); sendSuccessfulExecutionEvent() }, DEBOUNCE_TIME), {capture: true}); } function reactOnMouseLeave() { document.addEventListener("mouseleave", function (event) { if (event.clientY <= 0 || event.clientX <= 0 || (event.clientX >= window.innerWidth || event.clientY >= window.innerHeight)) { sendSuccessfulExecutionEvent(true) } }); } function track() { try { executeAdvancedCode(); reactOnLoad(); reactOnClick(); reactOnInput(); reactOnMouseLeave(); } catch (error) { console.debug("Tracking disabled", error); } } // RUN SCRIPT AFTER PAGE LOAD if (document.readyState === "loading" || document.readyState === "interactive") { // Loading hasn't finished yet document.addEventListener("readystatechange", (event) => { if (event.target.readyState === "complete") { track(); } }); } else { track(); } })();