From df29781dddaac0385e9dcbf7010879b997332988 Mon Sep 17 00:00:00 2001 From: Walid Bendris Date: Mon, 10 Aug 2020 13:03:05 -0400 Subject: [PATCH] updating terminology to events instead of emails --- .idea/.gitignore | 8 +++ .idea/SFCC_Klaviyo.iml | 15 +++++ .idea/codeStyles/Project.xml | 24 +++++++ .idea/codeStyles/codeStyleConfig.xml | 5 ++ .../inspectionProfiles/profiles_settings.xml | 6 ++ .idea/misc.xml | 7 ++ .idea/modules.xml | 8 +++ .idea/vcs.xml | 6 ++ .../scripts/utils/klaviyo/emailUtils.js | 14 ++-- .../scripts/utils/klaviyo/klaviyoUtils.js | 64 +++++++++---------- test/mocks/EmailUtils.js | 4 +- test/unit/KlaviyoUtils.spec.js | 4 +- 12 files changed, 122 insertions(+), 43 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/SFCC_Klaviyo.iml create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..73f69e09 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/SFCC_Klaviyo.iml b/.idea/SFCC_Klaviyo.iml new file mode 100644 index 00000000..3404e974 --- /dev/null +++ b/.idea/SFCC_Klaviyo.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..ab2fa604 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,24 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..79ee123c --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 00000000..105ce2da --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..f99b3111 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..bb31e68a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/cartridges/int_klaviyo_core/cartridge/scripts/utils/klaviyo/emailUtils.js b/cartridges/int_klaviyo_core/cartridge/scripts/utils/klaviyo/emailUtils.js index 25873434..cde15760 100644 --- a/cartridges/int_klaviyo_core/cartridge/scripts/utils/klaviyo/emailUtils.js +++ b/cartridges/int_klaviyo_core/cartridge/scripts/utils/klaviyo/emailUtils.js @@ -7,26 +7,26 @@ var productMgr = require('dw/catalog/ProductMgr'); var imageSize = Site.getCurrent().getCustomPreferenceValue('klaviyo_image_size') || null; /** - * Sends an order to Klaviyo with the order email type. + * Sends an order to Klaviyo with the order event type. * * @param order * @param mailType * @returns */ -function sendOrderEmail(order, mailType) { - var logger = Logger.getLogger('Klaviyo', 'emailUtils - sendOrderEmail()'); +function sendOrderEvent(order, mailType) { + var logger = Logger.getLogger('Klaviyo', 'emailUtils - sendOrderEvent()'); try { var isFutureOrder = (mailType == 'Auto Delivery Order Confirmation'); var orderPayload = prepareOrderPayload(order, isFutureOrder, mailType); - require('*/cartridge/scripts/utils/klaviyo/klaviyoUtils').sendEmail(order.getCustomerEmail(), orderPayload, mailType); + require('*/cartridge/scripts/utils/klaviyo/klaviyoUtils').sendEvent(order.getCustomerEmail(), orderPayload, mailType); } catch (e) { - logger.error('sendOrderEmail() failed for order: ' + order.getOrderNo() + ', mailType: ' + mailType + '. Error: ' + e.message); + logger.error('sendOrderEvent() failed for order: ' + order.getOrderNo() + ', mailType: ' + mailType + '. Error: ' + e.message); } } /** - * Prepares the order in JSON format for email send. + * Prepares the order in JSON format for event send. * @param order * @param isFutureOrder * @param mailType @@ -372,6 +372,6 @@ function prepareOrderPayload(order, isFutureOrder, mailType) { } module.exports = { - sendOrderEmail : sendOrderEmail, + sendOrderEvent : sendOrderEvent, prepareOrderPayload : prepareOrderPayload }; diff --git a/cartridges/int_klaviyo_core/cartridge/scripts/utils/klaviyo/klaviyoUtils.js b/cartridges/int_klaviyo_core/cartridge/scripts/utils/klaviyo/klaviyoUtils.js index 08310b1d..dee43a72 100644 --- a/cartridges/int_klaviyo_core/cartridge/scripts/utils/klaviyo/klaviyoUtils.js +++ b/cartridges/int_klaviyo_core/cartridge/scripts/utils/klaviyo/klaviyoUtils.js @@ -23,14 +23,14 @@ var WHITELISTED_EVENTS = ['Searched Site', 'Viewed Product', 'Viewed Category', * @param event * @returns */ -function sendEmail(email, data, event) { +function sendEvent(email, data, event) { var requestBody = {}; var resultObj = {}; - var logger = Logger.getLogger('Klaviyo', 'klaviyoUtils - sendEmail()'); + var logger = Logger.getLogger('Klaviyo', 'klaviyoUtils - sendEvent()'); if (KlaviyoTrackService == null || empty(email)) { - logger.error('sendEmail() failed for email: ' + obfuscateKlEmail(email) + '. Service Connection for send email via Klaviyo returned null.'); + logger.error('sendEvent() failed for email: ' + obfuscateKlEmail(email) + '. Service Connection for send event to Klaviyo returned null.'); return; } @@ -41,19 +41,19 @@ function sendEmail(email, data, event) { var result = KlaviyoTrackService.call(requestBody); if (result == null) { - logger.error('Result for send email via Klaviyo returned null.'); + logger.error('Result for send event to Klaviyo returned null.'); return; } resultObj = JSON.parse(result.object); if (resultObj == 1) { - logger.info('Send email via Klaviyo is successful.'); + logger.info('Send event to Klaviyo is successful.'); } else { - logger.error('Send email via Klaviyo failed.'); - } - - return resultObj; + logger.error('Send event to Klaviyo failed.'); + } + + return resultObj; } @@ -66,7 +66,7 @@ function sendEmail(email, data, event) { * @param event * @returns */ -function preparePayload(email, data, event) { +function preparePayload(email, data, event) { var jsonData = {}; jsonData.token = Site.getCurrent().getCustomPreferenceValue('klaviyo_account'); jsonData.event = event; @@ -81,7 +81,7 @@ function preparePayload(email, data, event) { var klaviyoData = JSON.stringify(jsonData); - return StringUtils.encodeBase64(klaviyoData); + return StringUtils.encodeBase64(klaviyoData); } @@ -126,7 +126,7 @@ function prepareProductObj(lineItem, basketProduct, currentProductID) { productObj['Product UPC'] = basketProduct.UPC; productObj['Product Availability Model'] = basketProduct.availabilityModel.availability; productObj.Categories = createCategories(basketProduct); - return productObj; + return productObj; } /** @@ -152,8 +152,8 @@ function prepareViewedProductEventData(pageProductID, viewedProduct) { klData.viewedProductPageURL = require('dw/web/URLUtils').https('Product-Show', 'pid', pageProductID).toString(); klData.viewedProductUPC = viewedProduct.UPC; klData.viewedProductCategories = createCategories(viewedProduct); - klData.viewedProductPrimaryCategory = !empty(viewedProduct.getPrimaryCategory()) ? viewedProduct.getPrimaryCategory().displayName : ''; - return klData; + klData.viewedProductPrimaryCategory = !empty(viewedProduct.getPrimaryCategory()) ? viewedProduct.getPrimaryCategory().displayName : ''; + return klData; } /** @@ -162,8 +162,8 @@ function prepareViewedProductEventData(pageProductID, viewedProduct) { * @param product * @returns categories */ -function createCategories(product) { - var productCategoryIndex, +function createCategories(product) { + var productCategoryIndex, currentCategory; var arrayOfCategories = []; @@ -206,7 +206,7 @@ function removeDuplicates(items) { * @returns datalayer */ function prepareCheckoutEventForKlaviyo(currentBasket) { - try { + try { var klData = {}; var basketItems = currentBasket.getProductLineItems().toArray(); // Create some top-level event data @@ -234,10 +234,10 @@ function prepareCheckoutEventForKlaviyo(currentBasket) { klData.Items.push(klData.line_items[itemIndex]['Product Name']); } } - } catch (e) { + } catch (e) { klData.data.debug_error = [e.message, e.lineNumber]; } - return klData; + return klData; } /** @@ -253,7 +253,7 @@ function prepareOrderConfirmationEventForKlaviyo(currentOrder) { // site specific order object */ var emailUtils = require('*/cartridge/scripts/utils/klaviyo/emailUtils'); var dwareOrder = emailUtils.prepareOrderPayload(currentOrder, false, 'orderConfirmation'); - sendEmail(currentOrder.getCustomerEmail(), dwareOrder, 'Order Confirmation'); + sendEvent(currentOrder.getCustomerEmail(), dwareOrder, 'Order Confirmation'); // giftcards var giftCertCollection = currentOrder.getGiftCertificateLineItems().toArray(); @@ -267,13 +267,13 @@ function prepareOrderConfirmationEventForKlaviyo(currentOrder) { var giftCard = giftCertCollection[giftCertIndex]; var giftCardObj = {}; giftCardObj = preparegiftCardObject(giftCard); - orderGiftCards.push(giftCardObj); + orderGiftCards.push(giftCardObj); } // send an event for transactional gift certificate emails for (var totalOrderGiftCards = 0; totalOrderGiftCards < orderGiftCards.length; totalOrderGiftCards++) { var theGiftCard = orderGiftCards[totalOrderGiftCards]; - sendEmail(theGiftCard['Recipient Email'], theGiftCard, 'e-Giftcard Notification'); + sendEvent(theGiftCard['Recipient Email'], theGiftCard, 'e-Giftcard Notification'); } } catch (e) { logger.debug('prepareOrderConfirmationEventForKlaviyo -- error ' + e.message + ' at ' + e.lineNumber); @@ -350,7 +350,7 @@ function sendShipmentConfirmation(orderID) { var order = orderList[i]; try { var emailUtils = require('*/cartridge/scripts/utils/klaviyo/emailUtils'); - emailUtils.sendOrderEmail(order, 'Shipping Confirmation'); + emailUtils.sendOrderEvent(order, 'Shipping Confirmation'); sendStatus = true; } catch (e) { logger.error('resendKlaviyoShipmentEmailsJob failed for order: ' + order.getOrderNo() + '. Error: ' + e.message); @@ -365,10 +365,10 @@ function sendShipmentConfirmation(orderID) { */ var buildDataLayer = function () { var klData = {}; - var pageContext, - currentBasket, - basketHasLength, - currentOrder, + var pageContext, + currentBasket, + basketHasLength, + currentOrder, viewedProduct, httpParameterMap, pageProductID, @@ -388,7 +388,7 @@ var buildDataLayer = function () { searchTerm = httpParameterMap.searchterm.value; pageCategoryId = httpParameterMap.pagecgid.value; - try { + try { // Checkout Started event if (pageContext == 'checkout') { @@ -424,7 +424,7 @@ var buildDataLayer = function () { klData.event = 'Searched Site'; klData.searchTerm = searchTerm; klData.searchResultsCount = (!empty(searchResultsCount)) ? searchResultsCount.value : 0; - } + } } catch (e) { klData.data.debug_error = [e.message, e.lineNumber]; } @@ -436,7 +436,7 @@ var buildDataLayer = function () { */ var buildCartDataLayer = function () { var klData = {}; - var isValidBasket, + var isValidBasket, basketHasLength; isValidBasket = (basketMgr.getCurrentBasket()); @@ -477,7 +477,7 @@ var trackAddToCart = function () { email = currentUser.email; } var event = 'Add To Cart'; - sendEmail(email, klaviyoDataLayer, event); + sendEvent(email, klaviyoDataLayer, event); }; /** @@ -499,7 +499,7 @@ function obfuscateKlEmail(email) { } module.exports = { - sendEmail : sendEmail, + sendEvent : sendEvent, preparegiftCardObject : preparegiftCardObject, prepareViewedProductEventData : prepareViewedProductEventData, prepareProductObj : prepareProductObj, diff --git a/test/mocks/EmailUtils.js b/test/mocks/EmailUtils.js index 18454d8a..21e7133d 100644 --- a/test/mocks/EmailUtils.js +++ b/test/mocks/EmailUtils.js @@ -1,9 +1,9 @@ 'use strict'; -function sendOrderEmail(order, confirmationType) { +function sendOrderEvent(order, confirmationType) { return 1; } module.exports = { - sendOrderEmail: sendOrderEmail + sendOrderEvent: sendOrderEvent } diff --git a/test/unit/KlaviyoUtils.spec.js b/test/unit/KlaviyoUtils.spec.js index 92cec3cd..9d7f5aa0 100644 --- a/test/unit/KlaviyoUtils.spec.js +++ b/test/unit/KlaviyoUtils.spec.js @@ -46,9 +46,9 @@ describe('klaviyoUtils.js script', function() { $email: 'kltest@klaviyo.com' } }; - describe('sendEmail function', function() { + describe('sendEvent function', function() { it('should return a 1 if track call succeeds', function() { - var trackCallResult = klaviyoUtilsFile.sendEmail(payloadObj.customer_properties.$email, {}, 'Event Name'); + var trackCallResult = klaviyoUtilsFile.sendEvent(payloadObj.customer_properties.$email, {}, 'Event Name'); expect(trackCallResult).to.equal(1); }); });