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AAK9D,SAASK,UAajC,OATAyD,KAAK9D,SAASwE,SAAQ,SAACvE,G,IAKTA,EAJZkE,EAAiBC,WAAWE,WAAW5D,KAAKT,EAAQwE,IACpDN,EAAiBC,WAAWC,SAAS3D,KAAK,CACxC+D,GAAIxE,EAAQwE,GACZC,UAAWzE,EAAQM,MACnBC,SAA0B,QAAhBP,EAAAA,EAAQO,gBAARP,IAAAA,EAAAA,EAAoB,KAElC,IAEOkE,CACT,EAEA,EAAUQ,6BAAV,WAEE,OAAO,KADkB,IAjDRlC,EAAAA,WAiDckC,+BAAN,MAAK,WACGb,KAAKI,8BACxC,EAnDmBzB,C,CAJlB,CAIoDmC,EAAAA,Q,olCCClClC,C,IAAN,iB,SAAMA,EASPmC,G,yGATOnC,G,KACnBe,UAAY,Y,KAEJL,SAAW,M,KAEnBR,QAAU,G,IAKoBiC,EAAAA,GAA3Bf,KAAKgB,mBAAkB,I,QAVPpC,EAAAA,UAanBC,UAAAA,W,IAIa,EACS,EAEH,EANK,mBAAXoC,QACTA,OAAO,QAASjB,KAAKL,UAAW,CAC9BuB,SAAUlB,KAAKlB,QACftB,MAA8B,QAAvB,EAAAwC,KAAKgB,0BAAL,eAAyBvE,MAChC0E,eAAuC,QAAvB,EAAAnB,KAAKgB,0BAAL,eAAyBtE,SACzC4C,SAAUU,KAAKV,SACf8B,WAAY,CAAwB,QAAvB,EAAApB,KAAKgB,0BAAL,eAAyBL,KAG5C,EAvBmB/B,C,CAAN,E","sources":["webpack://webstaurantstore/./analytics/AddToCart/addToCartAnalytics.ts","webpack://webstaurantstore/./analytics/AddToCart/addToCartApiHelpers.ts","webpack://webstaurantstore/./analytics/MarketingEvents/Pinterest/PinterestApiCommerceEvent.ts","webpack://webstaurantstore/./analytics/TrackingPixels/TagEvents/PinterestTagAddToCartEvent.ts"],"sourcesContent":["import { Item, updateUserWithNewCartTotal } from \"~/userAnalytics\";\nimport { sendGtmEvent, clearEcommerceInDataLayer } from \"../definitions\";\nimport {\n sendFacebookPixelAddToCartEvents,\n sendPinterestAddToCartEvents,\n} from \"./addToCartApiHelpers\";\nimport { EcommerceData, formatEcommerceData } from \"./addToCartHelpers\";\nimport { createProducts } from \"../productHelpers\";\n\nexport type AtcAnalyticsProps = {\n source: string;\n carouselProps?: {\n carouselName: string;\n carouselModel: string;\n position: number;\n };\n};\n\nexport const addToCartAnalytics = async (\n atcProps: AtcAnalyticsProps,\n ...items: Item[]\n) => {\n let total = 0;\n const feedIdentifiers: string[] = [];\n\n const products = await createProducts(items);\n if (products.length === 0) {\n return;\n }\n for (const product of products) {\n total += Number(product?.price ?? 0) * Number(product?.quantity ?? 0);\n if (product.feedIdentifier) {\n feedIdentifiers.push(product.feedIdentifier);\n }\n }\n // Done to avoid any floating point errors\n total = parseFloat(total.toFixed(2));\n // Note that prices here are only using P1, as the actual price can vary depending on user to user, so may vary slightly from the actual value.\n const newCartTotal = await updateUserWithNewCartTotal(true, total);\n if (newCartTotal.isError) {\n return;\n }\n sendPinterestAddToCartEvents(products);\n sendFacebookPixelAddToCartEvents(feedIdentifiers, total.toString());\n const formattedEcommerceProducts = formatEcommerceData(products, {\n total,\n position: atcProps.carouselProps?.position ?? 0,\n });\n\n sendGtmAddToCartEvents(\n formattedEcommerceProducts,\n newCartTotal.value,\n atcProps\n );\n};\n\nexport const productRemoveFromCart = async (items: Item[]) => {\n const itemTotalCosts = items.map(\n (item) => (item?.price ?? 0) * (item?.quantity ?? 0)\n );\n const totalCost = itemTotalCosts.reduce((acc, curr) => acc + curr, 0);\n const newCartTotal = await updateUserWithNewCartTotal(false, totalCost);\n if (newCartTotal.isError) {\n return;\n }\n const products = await createProducts(items);\n if (products.length === 0) {\n return;\n }\n const formattedEcommerceProduct = formatEcommerceData(products, {\n total: totalCost,\n });\n clearEcommerceInDataLayer();\n sendGtmEvent({\n event: \"productRemoveFromCart\",\n cart_total: newCartTotal.value,\n ecommerce: formattedEcommerceProduct,\n });\n};\n\nconst sendGtmAddToCartEvents = (\n ecommerce: EcommerceData,\n cartTotal: number,\n atcProps: AtcAnalyticsProps\n) => {\n clearEcommerceInDataLayer();\n sendGtmEvent({\n event: \"addToCart\",\n atc_source: atcProps.carouselProps?.carouselName\n ? \"carousel\"\n : atcProps.source,\n cart_total: cartTotal,\n ecommerce: { ...ecommerce },\n // Reset carousel props to empty string if not present otherwise variables will be previous values\n carouselName: atcProps.carouselProps?.carouselName ?? \"\",\n carouselModel: atcProps.carouselProps?.carouselModel ?? \"\",\n });\n};\n","import { getRandomNumberString } from \"~/userAnalytics\";\nimport {\n getFacebookPixelId,\n getFacebookPixelUserData,\n sendFacebookPixelServerEvent,\n} from \"../apiHelpers\";\nimport PinterestApiCommerceEvent from \"../MarketingEvents/Pinterest/PinterestApiCommerceEvent\";\nimport PinterestTagAddToCartEvent from \"../TrackingPixels/TagEvents/PinterestTagAddToCartEvent\";\nimport MarketingEventHelpers from \"../MarketingHelpers/MarketingEventHelpers\";\nimport { AnalyticsProduct } from \"../productHelpers\";\n\nexport const sendPinterestAddToCartEvents = (products: AnalyticsProduct[]) => {\n new PinterestApiCommerceEvent(\n \"add_to_cart\",\n new PinterestTagAddToCartEvent(products),\n products\n ).sendEvent();\n};\n\nexport const sendFacebookPixelAddToCartEvents = async (\n feedIdentifiers: string[],\n price: string\n) => {\n const eventId = getRandomNumberString();\n const priceOfItemAddedToCart = MarketingEventHelpers.createItemPriceWithTrailingZero(\n parseFloat(price)\n );\n if (typeof fbq !== \"function\") return;\n\n fbq(\"trackSingle\", getFacebookPixelId(), \"AddToCart\", {\n content_ids: feedIdentifiers,\n value: priceOfItemAddedToCart,\n currency: \"USD\",\n content_type: \"product\",\n eventID: eventId,\n });\n\n sendFacebookPixelServerEvent(\n \"AddToCart\",\n eventId,\n getFacebookPixelUserData(),\n {\n content_ids: feedIdentifiers,\n value: priceOfItemAddedToCart,\n currency: \"USD\",\n content_type: \"product\",\n }\n );\n};\n","import { AnalyticsProduct } from \"~/analytics/productHelpers\";\nimport type { Tag, Order } from \"../MarketingDataDefinitions\";\nimport PinterestApiEvent from \"./PinterestApiEvent\";\n\nexport default class PinterestApiCommerceEvent extends PinterestApiEvent {\n products: AnalyticsProduct[];\n\n order?: Order;\n\n constructor(\n eventName: string,\n associatedTagEvent: Tag,\n products: AnalyticsProduct[],\n order?: Order\n ) {\n super(eventName, associatedTagEvent);\n this.products = products;\n this.order = order;\n }\n\n private getProductCostAndOrderNumber() {\n return {\n OrderId: this.order?.orderNumber,\n Value: this.order?.orderTotal?.toString(),\n };\n }\n\n private formatProductsForApiRequest() {\n const contentIds: string[] = [];\n const contents: Array> = [];\n\n const productsForEvent = {\n customData: {\n Contents: contents,\n ContentIds: contentIds,\n ...this.getProductCostAndOrderNumber(),\n ...{ numItems: this.products.length },\n },\n };\n\n this.products.forEach((product) => {\n productsForEvent.customData.ContentIds.push(product.id);\n productsForEvent.customData.Contents.push({\n id: product.id,\n itemPrice: product.price,\n quantity: product.quantity ?? \"1\",\n });\n });\n\n return productsForEvent;\n }\n\n protected formatDataForStashApiRequest() {\n const userAndEventData = super.formatDataForStashApiRequest();\n return { ...userAndEventData, ...this.formatProductsForApiRequest() };\n }\n}\n","import { AnalyticsProduct } from \"~/analytics/productHelpers\";\nimport type { Tag } from \"../../MarketingEvents/MarketingDataDefinitions\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ndeclare const pintrk: any;\nexport default class PinterestTagAddToCartEvent implements Tag {\n eventName = \"addtocart\";\n\n private currency = \"USD\";\n\n eventId = \"\";\n\n private productAddedToCart?: AnalyticsProduct;\n\n constructor(productsAddedToCart: AnalyticsProduct[]) {\n [this.productAddedToCart] = productsAddedToCart;\n }\n\n sendEvent(): void {\n if (typeof pintrk === \"function\") {\n pintrk(\"track\", this.eventName, {\n event_id: this.eventId,\n value: this.productAddedToCart?.price,\n order_quantity: this.productAddedToCart?.quantity,\n currency: this.currency,\n product_id: [this.productAddedToCart?.id],\n });\n }\n }\n}\n"],"names":["addToCartAnalytics","productRemoveFromCart","atcProps","items","total","feedIdentifiers","products","product","newCartTotal","formattedEcommerceProducts","createProducts","length","Number","price","quantity","feedIdentifier","push","parseFloat","toFixed","updateUserWithNewCartTotal","isError","sendPinterestAddToCartEvents","sendFacebookPixelAddToCartEvents","toString","formatEcommerceData","position","carouselProps","sendGtmAddToCartEvents","value","item","itemTotalCosts","totalCost","formattedEcommerceProduct","map","reduce","acc","curr","clearEcommerceInDataLayer","sendGtmEvent","event","cart_total","ecommerce","cartTotal","atc_source","carouselName","source","carouselModel","PinterestApiCommerceEvent","PinterestTagAddToCartEvent","sendEvent","eventId","priceOfItemAddedToCart","getRandomNumberString","MarketingEventHelpers","createItemPriceWithTrailingZero","fbq","getFacebookPixelId","content_ids","currency","content_type","eventID","sendFacebookPixelServerEvent","getFacebookPixelUserData","eventName","associatedTagEvent","order","getProductCostAndOrderNumber","OrderId","this","orderNumber","Value","orderTotal","formatProductsForApiRequest","productsForEvent","customData","Contents","ContentIds","numItems","forEach","id","itemPrice","formatDataForStashApiRequest","PinterestApiEvent","productsAddedToCart","productAddedToCart","pintrk","event_id","order_quantity","product_id"],"sourceRoot":""}