{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./sfra/cartridges/app_storefront_base/cartridge/client/default/js/util.js","webpack:///./vendor/buy-with-prime/cartridges/int_buywithprime/cartridge/client/default/js/clickstream/clickstreamCollector.js","webpack:///./vendor/buy-with-prime/cartridges/int_buywithprime/cartridge/client/default/js/clickstream/miniCart.js","webpack:///./vendor/buy-with-prime/cartridges/int_buywithprime/cartridge/client/default/js/clickstreamLoader.js"],"names":[],"mappings":";QAAA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yCAAyC,iCAAiC;QAC1E,gHAAgH,mBAAmB,EAAE;QACrI;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;QAEA;QACA,sDAAsD,+DAA+D;;QAErH;QACA;;;QAGA;QACA;;;;;;;;;;;;;AClFa;;AAEb;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;;;;;;;;;;;;ACZA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA,OAAO;AACP;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,8BAA8B,sHAAsH;AACpJ;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA,0BAA0B,gBAAgB;AAC1C;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA,0BAA0B,gBAAgB;AAC1C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;;AAEA;AACA,0BAA0B,uFAAuF;AACjH;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,0BAA0B,gBAAgB;AAC1C;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,2CAA2C;AAC3C;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,sDAAsD;AACtD;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B,mDAAmD;AAC/E,SAAS;;AAET;AACA;AACA;;AAEA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qBAAqB;AACrB;AACA;AACA,iBAAiB;AACjB;AACA;AACA;;AAEA;AACA;AACA,SAAS;AACT,KAAK;AACL;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;;AAET;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,SAAS;;AAET;AACA;;AAEA;AACA;AACA,KAAK;AACL;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,uBAAuB,0BAA0B;AACjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;;AAEA;AACA;AACA,WAAW,EAAE;AACb,WAAW,EAAE;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,uBAAuB,0BAA0B;AACjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,YAAY;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,YAAY;AACvB;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,gDAAgD;AAChD;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA,YAAY;AACZ;;AAEA;AACA;AACA;AACA,WAAW,YAAY;AACvB,aAAa,QAAQ;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;;AAEA;AACA;AACA,KAAK;AACL;;AAEA;AACA;AACA,WAAW,EAAE;AACb;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,C;;;;;;;;;;;;AC1nBa;;AAEb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,yBAAyB;AACzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb,SAAS;;AAET;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;;AAEA,C;;;;;;;;;;;;ACvDA;AACA;AACA,CAAc;;AAEd,wBAAwB,mBAAO,CAAC,4FAAW;;AAE3C,gBAAgB,mBAAO,CAAC,kKAAuC;AAC/D;AACA,mBAAmB,mBAAO,CAAC,uIAAwB;AACnD,CAAC,E","file":"default/js/clickstreamLoader.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./vendor/buy-with-prime/cartridges/int_buywithprime/cartridge/client/default/js/clickstreamLoader.js\");\n","'use strict';\n\nmodule.exports = function (include) {\n if (typeof include === 'function') {\n include();\n } else if (typeof include === 'object') {\n Object.keys(include).forEach(function (key) {\n if (typeof include[key] === 'function') {\n include[key]();\n }\n });\n }\n};\n","const UBID_COOKIE = \"sfccubid\";\n\n// Event types.\nconst BADGE_VIEW_EVENT = 'widget-viewed';\nconst PAGE_LOAD_EVENT = 'page-load';\nconst WIDGET_CLICK_EVENT = 'widget-clicked';\nconst BWP_WIDGET_PROMISE_LOADED = 'bwp-widget-promise-loaded'\n\n// Page actions.\nconst PRIME_BADGE_ACTION = 'prime-badge-loaded';\nconst WIDGET_PROMISE_LOADED = 'widget-loaded';\nconst ADD_TO_CART = 'add-to-cart';\nconst REMOVE_FROM_CART = 'remove-from-cart';\n\n// Specific page actions, used to decorate standard prime events to help eliminate ambiguity.\n// E.g; If two prime events take place in the product list and mini-cart on the same page,\n// these are added respectively, as a prefix to remove ambiguity.\nconst PRODUCT_ACTION = 'product';\nconst MINICART_ACTION = 'mini-cart';\n\n// Page types\nconst PRODUCT_PAGE = 'product-page-widget';\nconst CHECKOUT_PAGE = 'checkout';\nconst CONFIRMATION_PAGE = 'confirmation';\nconst ORDER_DETAILS_PAGE = 'order-details';\nconst MINICART_PAGE = 'mini-cart';\nconst CART_TYPE = 'cart';\nconst UNKNOWN = 'unknown';\n\n\n// Minor performance enhancement cache variable, prevents requerying cookies for the same information.\nlet cachedCookieValue;\n\n// Product Summary items displaying a BwP badge, aggregated inside a single event.\nlet currentProductSummaryItems;\n// Gathered clickstream events, ready for dispatch.\nlet currentEvents = [];\n\n/**\n * Declares a clickstream event array if none exists, then adds the given event to the array.\n * The array acts as a queue for requests to be collected by the transmitter.\n * @param {\n * current_url,\n * event_id,\n * current_timestamp,\n * store_domain,\n * user_agent,\n * ubid,\n * screen_width,\n * screen_height,\n * referrer,\n * page_action,\n * sku?,\n * value?,\n * discount?,\n * tax?,\n * order_id?,\n * cart_id?\n * } event Clickstream event containing browser information to send to clickstream queue..\n */\nfunction postClickstreamEvent(event) {\n if (!window.clickstreamURL && event && event.url) {\n window.clickstreamURL = event.url;\n }\n if (currentEvents) {\n currentEvents.push(event);\n }\n}\n\n/** Posts a standard prime badge viewed event. */\nfunction postPrimeBadgeViewedEvent(url, sku, specificPageAction) {\n if (url && url != \"null\") {\n postClickstreamEvent({ url, product_sku: sku, ...collectCommonBrowserData(BADGE_VIEW_EVENT, specificPageAction + '-' + PRIME_BADGE_ACTION) });\n }\n}\n\n/** Posts a mini-cart specific prime badge viewed event. */\nfunction postMiniCartBadgeViewedEvent(clickstreamURL, sku) {\n postPrimeBadgeViewedEvent(clickstreamURL, sku, MINICART_ACTION);\n}\n\nfunction postPrimeButtonClickedEvent(url, cartItems, pageType) {\n if (!window.clickstreamURL) {\n window.clickstreamURL = url;\n }\n\n let event = collectCommonBrowserData(WIDGET_CLICK_EVENT, null, pageType)\n event.cart_items = cartItems\n\n postClickstreamEvent({ url, ...event });\n}\n\nfunction postPrimePromiseViewedEvent(url, mSku, deliveryEstimate, pageType) {\n if (!window.clickstreamURL) {\n window.clickstreamURL = url;\n }\n\n let event = collectCommonBrowserData(BWP_WIDGET_PROMISE_LOADED, WIDGET_PROMISE_LOADED, pageType);\n event.product_sku = mSku;\n event.prime_promise_timestamp = deliveryEstimate;\n\n postClickstreamEvent({ url, ...event })\n}\n\n/** Posts a product summary event, assigns all current product summary items to a single event. */\nfunction postProductSummaryEvent() {\n // Only run if there are product summary items.\n if (currentProductSummaryItems && currentProductSummaryItems.length > 0) {\n // Getting the page action to determine if pre or post checkout.\n const pageActionElements = document.getElementsByClassName('page');\n let pageType;\n if (pageActionElements && pageActionElements.length > 0) {\n const pageDataAction = pageActionElements[0].getAttribute('data-action');\n pageType = pageDataAction === \"Order-Confirm\" ? CONFIRMATION_PAGE : CHECKOUT_PAGE\n }\n // Posting event.\n postClickstreamEvent({\n url: currentProductSummaryItems[0].url,\n cart_items: currentProductSummaryItems,\n order_id: getOrderNumber(),\n ...collectCommonBrowserData(PAGE_LOAD_EVENT, null, pageType),\n ...findProductSummaryFinancial()\n });\n }\n}\n\nfunction postOrderDetailsViewedEvent(id) {\n postClickstreamEvent({ order_id: id, ...collectCommonBrowserData(PAGE_LOAD_EVENT, null, ORDER_DETAILS_PAGE) })\n}\n\nfunction postCartClickEvent(pageAction, url, sku, deliveryDate, price, quantity, minicart) {\n if (!window.clickstreamURL) {\n window.clickstreamURL = url;\n }\n\n let event = collectCommonBrowserData(WIDGET_CLICK_EVENT, pageAction);\n event[\"page_type\"] = (minicart ? 'mini' : '') + CART_TYPE;\n event[\"product_sku\"] = sku;\n event[\"prime_promise_timestamp\"] = deliveryDate;\n event[\"quantity\"] = quantity;\n event[\"price\"] = price;\n event[\"currency\"] = \"USD\";\n\n postClickstreamEvent({ url, ...event });\n}\n\n/** Function used to get the order number from the default class assignment. */\nfunction getOrderNumber() {\n let orderNumber;\n\n const orderNumberElement = document.querySelector('.order-number');\n if (orderNumberElement) {\n orderNumber = orderNumberElement.innerHTML;\n }\n\n return orderNumber;\n}\n\n/**\n * Attempts to retrieve a UBID from cookies, used to signify a unique shopper.\n * If not found, generates and sets a new one.\n * @returns UUID string representing a unique shopper, existing or new.\n */\nfunction getUBID() {\n // Prevent needless search if we've already retrieved the cookie.\n if (cachedCookieValue) {\n return cachedCookieValue;\n }\n // Getting existing cookie if exists.\n const cookie = document.cookie.split('; ')\n .find(row => row.startsWith(UBID_COOKIE + '='));\n\n // If cookie and subsequent value is found, return that.\n if (cookie) {\n const cookieValue = cookie.split(\"=\")[1];\n\n if (cookieValue) {\n cachedCookieValue = cookieValue;\n return cookieValue;\n }\n }\n\n // Otherwise generate and return a new cookie.\n const newUBID = crypto.randomUUID();\n cachedCookieValue = newUBID;\n document.cookie = UBID_COOKIE + \"=\" + newUBID + \";path=/\";\n return newUBID;\n}\n\nfunction collectCartClickEvents() {\n const buttons = document.querySelectorAll('.cart #bwp-cart-button');\n\n buttons.forEach(button => {\n let cartItems = []\n let products = document.querySelectorAll('.product-line-item');\n products.forEach(function (product) {\n let sku = product.getAttribute('amzn-sku')\n let quantity = product.getAttribute('quantity')\n let priceElement = product.querySelector('.unit-price')\n let price;\n if (priceElement) {\n let priceValue = priceElement.querySelector('span.value[content]');\n price = priceValue ? parseFloat(priceValue.getAttribute('content')) : null;\n }\n cartItems.push({ 'SKU': sku, 'quantity': quantity, 'price': price });\n });\n\n button.addEventListener('click', function (event) {\n let clickedButton = event.target;\n let clickstreamURL = button.getAttribute('clickstream-url');\n\n let page_type;\n if (clickedButton.closest('.minicart-footer')) {\n page_type = MINICART_PAGE;\n } else {\n // Otherwise check the page data action.\n const pageActionElements = document.querySelectorAll('.page');\n if (pageActionElements && pageActionElements.length > 0) {\n // Obtaining page data action.\n const pageDataAction = pageActionElements[0].getAttribute('data-action');\n if (pageDataAction == 'Cart-Show') {\n page_type = CART_TYPE;\n } else {\n page_type = CHECKOUT_PAGE;\n }\n } else {\n page_type = UNKNOWN;\n }\n }\n\n postPrimeButtonClickedEvent(clickstreamURL, cartItems, page_type)\n dispatchCurrentEvents();\n });\n })\n}\n\nfunction collectManageOrderClickEvents() {\n const manageOrderElement = document.querySelector('[amzn-order-id]')\n if (manageOrderElement) {\n manageOrderElement.addEventListener('mousedown', () => {\n const id = manageOrderElement.getAttribute('amzn-order-id');\n if (id && id != \"null\") {\n postOrderDetailsViewedEvent(id);\n dispatchCurrentEvents();\n }\n });\n }\n}\n\nfunction collectAddToCartClickEvent(primePromiseData, primeContainer) {\n $(document).on('click', '.add-to-cart', function () {\n const clickstreamURLElement = document.querySelector(\"[clickstream-url]\");\n const clickstreamURL = getClickstreamURL(clickstreamURLElement);\n const bwpProduct = window.bwpProduct;\n let mSku, deliveryDate, price, quantity;\n\n // set promise data\n if (primePromiseData && primePromiseData.earliest) {\n deliveryDate = new Date(primePromiseData.earliest).getTime();\n }\n\n // set the price\n let productPrice = document.querySelectorAll('.prices-add-to-cart-actions');\n productPrice.forEach(function (product) {\n priceElement = product.querySelector('.sales')\n if (priceElement) {\n let priceValue = priceElement.querySelector('span.value[content]');\n price = priceValue ? parseFloat(priceValue.getAttribute('content')) : null;\n }\n })\n\n // find sku\n if (bwpProduct && bwpProduct.mSku) {\n mSku = bwpProduct.mSku;\n } else {\n if (primeContainer && primeContainer.length > 0) {\n mSku = findSku(primeContainer[0]);\n }\n }\n\n // find quantity\n let products = document.querySelectorAll('.product-line-item');\n products.forEach(function (product) {\n quantity = product.getAttribute('quantity')\n });\n\n const selectedOption = document.querySelector('.quantity-select option[selected]');\n quantity = selectedOption.value;\n\n postCartClickEvent(ADD_TO_CART, clickstreamURL, mSku, deliveryDate, price, quantity);\n dispatchCurrentEvents();\n });\n}\n\nfunction collectRemoveFromCartClickEvent() {\n $(document).on('click', '.cart-delete-confirmation-btn[data-dismiss=\"modal\"]', function () {\n const clickstreamURLElement = document.querySelector(\"[clickstream-url]\");\n const clickstreamURL = getClickstreamURL(clickstreamURLElement);\n let mSku, deliveryDate, price, quantity;\n let productToRemoveElem = document.querySelector('.product-to-remove');\n let productToRemove = productToRemoveElem.textContent;\n\n const lineItemNames = document.getElementsByClassName('line-item-name');\n for (let i = 0; i < lineItemNames.length; i++) {\n const lineItemElem = lineItemNames[i]\n let productName = lineItemElem.innerText.trim();\n if (productName == productToRemove) {\n const cardElement = lineItemElem.closest('.card');\n const productLineItemElement = lineItemElem.closest('.product-line-item');\n // It was removed on the full-cart\n if (productLineItemElement) {\n mSku = productLineItemElement.getAttribute('amzn-sku')\n // Only care about prime items.\n if (mSku != \"null\") {\n quantity = productLineItemElement.getAttribute('quantity')\n let priceElement = productLineItemElement.querySelector('.unit-price')\n if (priceElement) {\n let priceValue = priceElement.querySelector('span.value[content]');\n price = priceValue ? parseFloat(priceValue.getAttribute('content')) : null;\n }\n postCartClickEvent(REMOVE_FROM_CART, clickstreamURL, mSku, deliveryDate, price, quantity, true);\n }\n // Full cart removal.\n } else if (cardElement) {\n const primeContainer = cardElement.querySelector('.bwp-prime-container');\n // Only care about prime items.\n if (primeContainer && !primeContainer.classList.contains('hidden')) {\n const quantityElem = cardElement.querySelector('[selected]');\n if (quantityElem) {\n quantity = quantityElem.innerHTML;\n }\n const salesElem = cardElement.querySelector('.unit-price');\n if (salesElem) {\n const priceElem = salesElem.querySelector('.value');\n if (priceElem) {\n price = extractNumericValue(priceElem.innerText);\n }\n }\n mSku = findSku(primeContainer);\n deliveryDate = primeContainer.getAttribute('amzn-earliest');\n postCartClickEvent(REMOVE_FROM_CART, clickstreamURL, mSku, deliveryDate, price, quantity, false);\n\n }\n }\n dispatchCurrentEvents();\n break;\n }\n }\n });\n}\n\n/**\n * Collects common browser data for the event at the time the event happened.\n * @param {*} eventName Name of the event.\n * @param {*} pageAction Action page was taking when the event happened.\n * @returns object containing common browser data for clickstream eventing.\n */\nfunction collectCommonBrowserData(eventName, pageAction, pageType) {\n const event = {\n current_url: window.location.href,\n event_id: crypto.randomUUID(),\n current_timestamp: new Date().toISOString(),\n store_domain: window.location.origin,\n user_agent: window.navigator.userAgent,\n ubid: getUBID(),\n screen_width: window.screen.width,\n screen_height: window.screen.height,\n referrer: document.referrer,\n event_name: eventName\n };\n\n if (pageAction) {\n event.page_action = pageAction;\n }\n\n if (pageType) {\n event.page_type = pageType;\n }\n\n return event;\n}\n\n/**\n * Sends all events that are currently in the queue.\n */\nfunction dispatchCurrentEvents() {\n const url = window.clickstreamURL;\n // Maximum size per request.\n const batchSize = 10;\n\n if (currentEvents && currentEvents.length > 0) {\n for (let i = 0; i < currentEvents.length; i += batchSize) {\n // Gather batch to send.\n const eventsToSend = currentEvents.slice(i, i + batchSize);\n // Defining/sending the ajax request.\n $.ajax({\n url,\n type: 'POST',\n contentType: 'application/json',\n data: JSON.stringify(eventsToSend)\n });\n }\n currentEvents.length = 0;\n }\n}\n\n/**\n * Finds the amazon sku based on a specific attribute. Will search parents and then children for a matching attribute.\n * @param element - Element which may contain the amzn-sku.\n * @returns Amazon SKU for a given element if it exists.\n */\nfunction findSku(element) {\n let sku;\n if (element) {\n const parentSkuElement = element.closest('[amzn-sku]');\n const childSkuElement = element.querySelector('[amzn-sku]');\n if (parentSkuElement) {\n sku = parentSkuElement.getAttribute('amzn-sku');\n } else if (childSkuElement) {\n sku = childSkuElement.getAttribute('amzn-sku');\n }\n }\n return sku;\n}\n\n/**\n * Temporary function which attempts to find a clickstream URL in a given element.\n * @param element - Element which may contain the URL.\n * @returns URL value for a given element.\n */\nfunction getClickstreamURL(element) {\n if (element) {\n return element.getAttribute('clickstream-url');\n }\n}\n\n/**\n * Obtains the delivery promise shown to a shopper from a set attribute.\n * @param element - Element which may contain the promise.\n * @returns Delivery date in millis.\n */\nfunction getDeliveryDate(element) {\n let deliveryDate;\n if (element) {\n const deliveryDateElement = element.closest('[delivery-date-earliest]');\n if (deliveryDateElement) {\n deliveryDate = deliveryDateElement.getAttribute('delivery-date-earliest');\n if (deliveryDate) {\n deliveryDate = new Date(deliveryDate).getTime();\n }\n }\n }\n return deliveryDate;\n}\n\n/**\n * Searches a given element for prime badge related data.\n * @param {HTMLElement} element - Initial search element.\n * @returns Prime Badge clickstream object with found values.\n */\nfunction getPrimeBadgeData(element) {\n return {\n sku: findSku(element),\n url: getClickstreamURL(element)\n }\n}\n\n/**\n * Searches a given element for product summary related data.\n * @param {HTMLElement} element - Initial search element.\n * @returns ProductSummary Clickstream object with found values.\n */\nfunction getProductSummaryData(element) {\n const quantityElement = element.querySelector('.qty-card-quantity-count');\n\n let quantity;\n if (quantityElement) {\n quantity = quantityElement.innerHTML;\n }\n\n return {\n SKU: findSku(element),\n url: getClickstreamURL(element),\n prime_promise_timestamp: getDeliveryDate(element),\n quantity\n }\n}\n\n/**\n * Removes the currency symbol from a given currency string.\n * @param {String} currencyString \n * @returns Only the value of the currency. E.g; $5.12 becomes 5.12.\n */\nfunction extractNumericValue(currencyString) {\n const matches = currencyString.match(/-?\\d+(\\.\\d+)?/);\n return matches ? parseFloat(matches[0]) : null;\n}\n\n/**\n * Attempts to find all of the financial details for a basket shown to a shopper.\n * Used for product summary events.\n * @returns Object containing financial summary details.\n */\nfunction findProductSummaryFinancial() {\n const grandTotalElem = document.querySelector('.grand-total-sum');\n let grandTotal;\n if (grandTotalElem) {\n grandTotal = extractNumericValue(grandTotalElem.innerHTML);\n }\n\n const taxTotalElem = document.querySelector('.tax-total');\n let taxTotal;\n if (taxTotalElem) {\n taxTotal = extractNumericValue(taxTotalElem.innerHTML);\n }\n\n const discountTotalElem = document.querySelector('.order-discount-total');\n let discountTotal;\n if (discountTotalElem) {\n discountTotal = extractNumericValue(discountTotalElem.innerHTML);\n }\n\n return { value: grandTotal, tax: taxTotal, discount: discountTotal };\n}\n\n/**\n * Scans an element to see if a bwp container exists and is visible.\n * Used to ensure that only product summaries with a visible prime container are collected.\n * @param {HTMLElement} element - Initial search element. \n * @returns {boolean} True if a visible prime container exists.\n */\nfunction hasVisibleBwPContainer(element) {\n let found = false;\n checkoutContainerElement = element.querySelector('.bwp-container-checkout');\n if (checkoutContainerElement) {\n const primeContainer = element.querySelector('.bwp-prime-container');\n if (primeContainer && !primeContainer.classList.contains('hidden')) {\n found = true;\n }\n }\n\n return found;\n}\n\nfunction findClickstreamObjects(element) {\n if (element) {\n return element.querySelectorAll('[clickstream-object]');\n }\n}\n\n/**\n * Function use to collect all clickstream events events related to initial page loading.\n */\nfunction collectElementRenderEvents() {\n window.addEventListener('load', function () {\n currentProductSummaryItems = [];\n // Events are denoted by adding a clickstream object attribute.\n const dataTypes = findClickstreamObjects(document);\n dataTypes.forEach(element => {\n // Gathering data from the hierarchy.\n const clickstreamObjectType = element.getAttribute('clickstream-object');\n // Switch on object type to accurately record which event was processed.\n switch (clickstreamObjectType) {\n case 'primeBadge':\n const primeBadgeData = getPrimeBadgeData(element);\n postPrimeBadgeViewedEvent(primeBadgeData.url, primeBadgeData.sku, PRODUCT_ACTION)\n break;\n case 'productSummary':\n if (hasVisibleBwPContainer(element)) {\n const productSummaryData = getProductSummaryData(element);\n currentProductSummaryItems.push(productSummaryData);\n }\n break;\n }\n });\n // Convert product summary items to a single event if found.\n postProductSummaryEvent();\n\n // Dispatching after iterating.\n dispatchCurrentEvents();\n });\n}\n\n/**\n * Collects information related to a prime promise viewed event.\n * @param {*} primePromiseData Date related to the prime promise that was shown to the user.\n */\nfunction collectPrimePromiseEvent(primePromiseData, primeContainer) {\n if (primeContainer && primeContainer.length > 0) {\n // Ensuring we can obtain the required clickstream URL.\n const clickstreamURL = getClickstreamURL(primeContainer[0]);\n\n if (clickstreamURL && clickstreamURL != \"null\") {\n let mSku;\n let deliveryDate;\n\n const bwpProduct = window.bwpProduct;\n // If function was called from product page, mSku should be defined in the product.\n if (bwpProduct && bwpProduct.mSku) {\n mSku = bwpProduct.mSku;\n } else {\n // Otherwise, we need to find the sku from the prime container.\n mSku = findSku(primeContainer[0]);\n }\n\n // Attempt to convert prime promise to millis.\n if (primePromiseData && primePromiseData.earliest) {\n deliveryDate = new Date(primePromiseData.earliest).getTime();\n primeContainer[0].setAttribute(\"amzn-earliest\", deliveryDate);\n }\n\n // Post and dispatch.\n postPrimePromiseViewedEvent(clickstreamURL, mSku, deliveryDate, PRODUCT_PAGE);\n dispatchCurrentEvents();\n }\n }\n}\n\n// Initial collection call.\ncollectRemoveFromCartClickEvent();\ncollectElementRenderEvents();\ncollectManageOrderClickEvents();\ncollectCartClickEvents();\n\n// Attaching functions to the window for use in other clickstream workflows.\nmodule.exports = function () {\n window.postMiniCartBadgeViewedEvent = postMiniCartBadgeViewedEvent;\n window.collectPrimePromiseEvent = collectPrimePromiseEvent;\n window.collectAddToCartClickEvent = collectAddToCartClickEvent;\n window.collectCartClickEvents = collectCartClickEvents;\n window.dispatchCurrentEvents = dispatchCurrentEvents;\n window.findSku = findSku;\n window.getClickstreamURL = getClickstreamURL;\n window.findClickstreamObjects = findClickstreamObjects;\n}","'use strict';\n\n/**\n * Attempts to find the default mini-cart popover and attach a MutationObserver to it.\n * If the MutationObserver is successfully attached, it will watch for cart updates\n * and send clickstream events if it finds a BwP badge on an eligible item.\n */\nmodule.exports = function () {\n const miniCartContainer = $('.popover-bottom');\n if (miniCartContainer && miniCartContainer.length > 0) {\n // Defining te observer\n const observer = new MutationObserver(function (mutations) {\n // Iterate trough the mutations, specifically looking for child additions.\n mutations.forEach(function (mutation) {\n if (mutation.type === 'childList') {\n // Used to avoid unnecessary dispatch calls.\n let eventPosted = false;\n\n // Getting all the clickstream objects in the mini-cart, which should only be badge events.\n const miniCartBadgeObjects = window.findClickstreamObjects(miniCartContainer[0]);\n if (miniCartBadgeObjects) {\n miniCartBadgeObjects.forEach(badgeObject => {\n // Only processing each cart update once, using attributes to track.\n if (!badgeObject.getAttribute('bwp-cstream-processed')) {\n // Obtaining the clickstream information.\n const clickstreamUrl = window.getClickstreamURL(badgeObject);\n const amazonSku = window.findSku(badgeObject);\n\n // Posting event if URL was properly found.\n if (clickstreamUrl) {\n postMiniCartBadgeViewedEvent(clickstreamUrl, amazonSku);\n eventPosted = true;\n }\n // Marking the element as processed to ensure no duplicate events are sent.\n badgeObject.setAttribute('bwp-cstream-processed', 'true');\n }\n });\n // If event was posted then call a dispatch.\n if (eventPosted) {\n dispatchCurrentEvents();\n collectCartClickEvents();\n }\n }\n }\n });\n });\n\n // Attaching the observer.\n observer.observe(miniCartContainer[0], {\n attributes: true,\n subtree: true,\n childList: true\n });\n }\n\n}"," // copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n // SPDX-License-Identifier: Apache-2.0\n 'use strict';\n \n const processInclude = require('base/util');\n \n processInclude(require('./clickstream/clickstreamCollector.js'));\n $(document).ready(function () {\n processInclude(require('./clickstream/miniCart'));\n});"],"sourceRoot":""}