{"version":3,"sources":["webpack:///./ClientApp/features/tracking/gtag.ts","webpack:///./ClientApp/shared/util/events/rocEventUtils.ts","webpack:///./ClientApp/features/commerce/checkout/types/checkout-steps.ts","webpack:///./ClientApp/features/tracking/trackers/commerce/google-analytics-enhanced-ecommerce/google-analytics-enhanced-ecommerce-tracker.ts"],"names":["isAlreadyLogged","window","console","warn","addRocEventHandler","eventType","eventHandler","handler","evt","detail","document","addEventListener","removeEventListener","CheckoutStep","convertOrderToGoogleAnalyticItems","order","recipients","reduce","items","recipient","map","item","id","product","name","quantity","price","unitPrice","salePrice","rawValue","basePrice","gtag","sku","adjustedQuantity","productId","productName","step","cart","Loading","LoginOrGuest","ShippingAddress","ShippingMethod","ShippingReview","Payment","Review","checkout_step","transaction_id","orderNo","value","total","tax","shipping","shippingTotal","option","checkout_option","content_type"],"mappings":"2FAAA,IACIA,GAAkB,EAMP,eAAoB,MACZ,oBAAXC,QAA4D,mBAA3BA,OAAM,MAOlD,EAAAA,QAAM,KAAN,mBANMD,IACJE,QAAQC,KAAK,2EACbH,GAAkB,K,gCCHN,SAASI,EACvBC,EACAC,GAEA,IAAMC,EAAU,SAACC,GAChBF,EAAaE,EAAIC,SAKlB,OAFAC,SAASC,iBAAiBN,EAAWE,GAE9B,kBAAMG,SAASE,oBAAoBP,EAAWE,IAhBtD,mC,gCCEO,IAAKM,EAJZ,kC,SAIYA,O,qBAAAA,I,+BAAAA,I,qCAAAA,I,mCAAAA,I,mCAAAA,I,qBAAAA,I,mBAAAA,I,gCAAAA,M,o4BCaZ,SAASC,EAAkCC,GAC1C,OAAOA,EAAMC,WAAWC,QACvB,SAACC,EAAOC,GAAR,kBACID,GADJ,EAEIC,EAAUD,MAAME,KAAI,SAACC,GAAS,MAChC,MAAO,CACNC,GAAID,EAAKE,QAAQD,GACjBE,KAAMH,EAAKG,KACXC,SAAUJ,EAAKI,SACfC,MACCL,EAAKM,WAAaN,EAAKM,UAAUC,UAC9BP,EAAKM,UAAUC,UAAUC,SAD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EAA7BA,UAAWC,EAAkB,EAAlBA,YACnDJ,YAAK,QAAS,iBAAkB,CAC/BwB,aAAc,UACdrC,MAAO,CACN,CACCI,GAAIY,EACJV,KAAMW,W","file":"google-analytics-enhanced-ecommerce-tracker.2306f6c9.js","sourcesContent":["const tagManagerName = 'gtag';\r\nlet isAlreadyLogged = false;\r\n/**\r\n * Wrapper function to send data to Google (page views, events, enhanced ecommerce data, etc.).\r\n *\r\n * @param {*} args\r\n */\r\nexport default (...args: any[]) => {\r\n\tif (typeof window === 'undefined' || typeof window[tagManagerName] !== 'function') {\r\n\t\tif (!isAlreadyLogged) {\r\n\t\t\tconsole.warn('Unable to add data to the data layer, the Global Site Tag is not setup.');\r\n\t\t\tisAlreadyLogged = true;\r\n\t\t}\r\n\t\treturn;\r\n\t}\r\n\twindow[tagManagerName](...args);\r\n};\r\n","import { RocEventType, RocEvent, ExtractEventParameters } from 'shared/events';\r\n\r\n/**\r\n * Helper function for handling ROC events from non React functions.\r\n * @param eventType The type of event to handle\r\n * @param eventHandler The event handler\r\n * @returns The callback function to remove this handler\r\n */\r\nexport default function addRocEventHandler(\r\n\teventType: T,\r\n\teventHandler: (data: ExtractEventParameters) => void,\r\n): () => void {\r\n\tconst handler = (evt: CustomEvent): void => {\r\n\t\teventHandler(evt.detail);\r\n\t};\r\n\r\n\tdocument.addEventListener(eventType, handler);\r\n\r\n\treturn () => document.removeEventListener(eventType, handler);\r\n}\r\n","/**\r\n * Defines Checkout Steps, including review steps. Doesn't have an explicit definition\r\n * for per-recipient steps, that should be handled separately.\r\n */\r\nexport enum CheckoutStep {\r\n\tLoading = 0,\r\n\tLoginOrGuest = 1,\r\n\tShippingAddress = 2,\r\n\tShippingMethod = 3,\r\n\tShippingReview = 4,\r\n\tPayment = 5,\r\n\tReview = 6,\r\n\tConfirmation = 7,\r\n}\r\n","/* eslint-disable camelcase */\r\nimport addRocEventHandler from 'shared/util/events/rocEventUtils';\r\nimport gtag from 'features/tracking/gtag';\r\nimport { CheckoutStep } from 'features/commerce/checkout/types/checkout-steps';\r\nimport { Order } from 'features/commerce/shopping-cart/types';\r\n\r\ninterface GoogleAnalyticsOrderItem {\r\n\tid: string;\r\n\tname: string;\r\n\tquantity: number;\r\n\tprice: number | undefined;\r\n}\r\n\r\n/**\r\n * Helper function for converting order model to the list of items in format expected by Google Analytics\r\n * @param order\r\n */\r\nfunction convertOrderToGoogleAnalyticItems(order: Order): Array {\r\n\treturn order.recipients.reduce(\r\n\t\t(items, recipient) => [\r\n\t\t\t...items,\r\n\t\t\t...recipient.items.map((item) => {\r\n\t\t\t\treturn {\r\n\t\t\t\t\tid: item.product.id,\r\n\t\t\t\t\tname: item.name,\r\n\t\t\t\t\tquantity: item.quantity,\r\n\t\t\t\t\tprice:\r\n\t\t\t\t\t\titem.unitPrice && item.unitPrice.salePrice\r\n\t\t\t\t\t\t\t? item.unitPrice.salePrice.rawValue\r\n\t\t\t\t\t\t\t: item.unitPrice?.basePrice.rawValue,\r\n\t\t\t\t};\r\n\t\t\t}),\r\n\t\t],\r\n\t\t[],\r\n\t);\r\n}\r\n\r\nexport default function setup() {\r\n\taddRocEventHandler('added-to-cart', ({ items }) => {\r\n\t\t// \"add_to_cart\" event should be triggered when a user adds items to cart\r\n\t\tgtag('event', 'add_to_cart', {\r\n\t\t\titems: items.map((item) => {\r\n\t\t\t\treturn {\r\n\t\t\t\t\tid: item.sku, // \"id: field can be set either to the product ID or SKU\r\n\t\t\t\t\tname: item.name,\r\n\t\t\t\t\tquantity: item.adjustedQuantity,\r\n\t\t\t\t\tprice: item.price,\r\n\t\t\t\t};\r\n\t\t\t}),\r\n\t\t});\r\n\t});\r\n\r\n\taddRocEventHandler('product-viewed', ({ productId, productName }) => {\r\n\t\t// \"view_item\" event should be triggered when a user views product or item details.\r\n\t\tgtag('event', 'view_item', {\r\n\t\t\titems: [\r\n\t\t\t\t{\r\n\t\t\t\t\tid: productId,\r\n\t\t\t\t\tname: productName,\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t});\r\n\t});\r\n\r\n\taddRocEventHandler('checkout-step-changed', ({ step, cart }) => {\r\n\t\tconst items = convertOrderToGoogleAnalyticItems(cart);\r\n\t\tswitch (step) {\r\n\t\t\tcase CheckoutStep.Loading:\r\n\t\t\t\t// \"begin_checkout\" event should be triggered when a user begins checkout.\r\n\t\t\t\t// in ROC Commerce this would be CheckoutStep.Loading as this is the entry point to the checkout.\r\n\t\t\t\tgtag('event', 'begin_checkout', {\r\n\t\t\t\t\titems: items,\r\n\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CheckoutStep.LoginOrGuest:\r\n\t\t\tcase CheckoutStep.ShippingAddress:\r\n\t\t\tcase CheckoutStep.ShippingMethod:\r\n\t\t\tcase CheckoutStep.ShippingReview:\r\n\t\t\tcase CheckoutStep.Payment:\r\n\t\t\tcase CheckoutStep.Review:\r\n\t\t\t\t// \"checkout_progress\" event should be triggered when a user completes a checkout step.\r\n\t\t\t\t// that's why we have to do some math because ROC dispatched \"checkout-step-changed\" event and provides\r\n\t\t\t\t// number of the current step, but we have to get the previous step that was completed.\r\n\t\t\t\tgtag('event', 'checkout_progress', {\r\n\t\t\t\t\tcheckout_step: step,\r\n\t\t\t\t\titems: items,\r\n\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t});\r\n\r\n\taddRocEventHandler('order-placed', ({ order }) => {\r\n\t\tgtag('event', 'purchase', {\r\n\t\t\ttransaction_id: order.orderNo,\r\n\t\t\tvalue: order.total.basePrice.rawValue,\r\n\t\t\ttax: order.tax?.basePrice.rawValue,\r\n\t\t\tshipping: order.shippingTotal.basePrice.rawValue,\r\n\t\t\titems: convertOrderToGoogleAnalyticItems(order),\r\n\t\t});\r\n\t});\r\n\r\n\taddRocEventHandler('checkout-option-changed', ({ step, option }) => {\r\n\t\tgtag('event', 'set_checkout_option', {\r\n\t\t\tcheckout_step: step,\r\n\t\t\tcheckout_option: option,\r\n\t\t});\r\n\t});\r\n\r\n\taddRocEventHandler('product-clicked', ({ productId, productName }) => {\r\n\t\tgtag('event', 'select_content', {\r\n\t\t\tcontent_type: 'product',\r\n\t\t\titems: [\r\n\t\t\t\t{\r\n\t\t\t\t\tid: productId,\r\n\t\t\t\t\tname: productName,\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t});\r\n\t});\r\n}\r\n"],"sourceRoot":""}