From 2c342f8451b3db5db538ff08c2f271925290dcab Mon Sep 17 00:00:00 2001 From: duker33 Date: Sun, 29 Sep 2019 14:17:43 +0300 Subject: [PATCH 1/4] #977 Add untested carrotquest object loading --- front/js/components/orderCall.es6 | 2 +- front/js/components/product.es6 | 5 +++-- front/js/shared/mediator.es6 | 2 +- front/js/shared/tracking.es6 | 14 ++++++++++++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/front/js/components/orderCall.es6 b/front/js/components/orderCall.es6 index 07da1dbe..7a73631c 100644 --- a/front/js/components/orderCall.es6 +++ b/front/js/components/orderCall.es6 @@ -39,7 +39,7 @@ server.sendOrderCall(phone, time, url) .then(() => { DOM.$timeText.text(DOM.$timeTag.val()); - mediator.publish('onBackCallSend'); + mediator.publish('onBackCallSend', phone); }); } diff --git a/front/js/components/product.es6 b/front/js/components/product.es6 index 8585a4d2..3ed47c8e 100644 --- a/front/js/components/product.es6 +++ b/front/js/components/product.es6 @@ -96,9 +96,10 @@ helpers.setDisabledState(DOM.$oneClick, 'Ожидайте...'); const { id, quantity } = getProductData(); - server.oneClickBuy(id, quantity, DOM.$phone.val()) + const phone = DOM.$phone.val(); + server.oneClickBuy(id, quantity, phone) .then(() => { - mediator.publish('onOneClickBuy'); + mediator.publish('onOneClickBuy', phone); // Set timeout to wait handling of onOneClickBuy setTimeout(() => { window.location.href = configs.hrefs.orderSuccess; diff --git a/front/js/shared/mediator.es6 b/front/js/shared/mediator.es6 index 9739a01c..17c3f0e1 100644 --- a/front/js/shared/mediator.es6 +++ b/front/js/shared/mediator.es6 @@ -1,5 +1,5 @@ /** - * We implements mediator pattern via jQuery's global events + * We implement mediator pattern via jQuery's global events * on empty object (it could be a window or a documents, also) */ const mediator = { diff --git a/front/js/shared/tracking.es6 b/front/js/shared/tracking.es6 index 1f4485a4..fc413819 100644 --- a/front/js/shared/tracking.es6 +++ b/front/js/shared/tracking.es6 @@ -32,9 +32,16 @@ }; function setUpListeners() { - mediator.subscribe('onOneClickBuy', () => { + mediator.subscribe('onOneClickBuy', (_, phone) => { reachGoal('CMN_BUY_SEND'); reachGoal('FAST_BUY_SEND'); + // @todo #977:120m Create some lazy() wrapper for counters. + // `lazy(my_counter).reachGoal()` should asynchronous delay reaching + // until my_counter object won't be fully loaded. + + // @todo #977:30m Create mock class for carrotquest. + // Fill it's methods with console logs. + carrotquest.identify({'$phone': phone}); }); mediator.subscribe('onOrderSend', () => { reachGoal('CMN_BUY_SEND'); @@ -52,7 +59,10 @@ yaTracker.remove([data]); }); mediator.subscribe('onProductDetail', (_, data) => yaTracker.detail([data])); - mediator.subscribe('onBackCallSend', () => reachGoal('BACK_CALL_SEND')); + mediator.subscribe('onBackCallSend', (_, phone) => { + reachGoal('BACK_CALL_SEND'); + carrotquest.identify({'$phone': phone}); + }); mediator.subscribe('onSuccessOrder', (_, orderPositions, orderData) => { yaTracker.purchase(orderPositions, orderData); gaTracker.purchase(orderPositions, orderData); From 6d165ff04bf9d2362d9d372707a4d5e1c3de873f Mon Sep 17 00:00:00 2001 From: duker33 Date: Mon, 30 Sep 2019 16:59:35 +0300 Subject: [PATCH 2/4] #977 Review#1 fixes. Fix comment and pdd task body --- front/js/shared/tracking.es6 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/front/js/shared/tracking.es6 b/front/js/shared/tracking.es6 index fc413819..4850e9a0 100644 --- a/front/js/shared/tracking.es6 +++ b/front/js/shared/tracking.es6 @@ -38,9 +38,12 @@ // @todo #977:120m Create some lazy() wrapper for counters. // `lazy(my_counter).reachGoal()` should asynchronous delay reaching // until my_counter object won't be fully loaded. + // See our custom the Google Analytics code as reference implementation: + // https://github.com/fidals/refarm-site/pull/314/files // @todo #977:30m Create mock class for carrotquest. // Fill it's methods with console logs. + // We'll use the class for tests created with se#978 issue. carrotquest.identify({'$phone': phone}); }); mediator.subscribe('onOrderSend', () => { From 259d0851a30ecb673c19f3b0cada6b3aec640e0e Mon Sep 17 00:00:00 2001 From: duker33 Date: Mon, 30 Sep 2019 18:43:23 +0300 Subject: [PATCH 3/4] #983 Add carrotquest object --- front/js/shared/tracking.es6 | 4 ---- templates/layout/google_tag_manager.html | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/front/js/shared/tracking.es6 b/front/js/shared/tracking.es6 index 4850e9a0..f38e3cf4 100644 --- a/front/js/shared/tracking.es6 +++ b/front/js/shared/tracking.es6 @@ -40,10 +40,6 @@ // until my_counter object won't be fully loaded. // See our custom the Google Analytics code as reference implementation: // https://github.com/fidals/refarm-site/pull/314/files - - // @todo #977:30m Create mock class for carrotquest. - // Fill it's methods with console logs. - // We'll use the class for tests created with se#978 issue. carrotquest.identify({'$phone': phone}); }); mediator.subscribe('onOrderSend', () => { diff --git a/templates/layout/google_tag_manager.html b/templates/layout/google_tag_manager.html index 2702b071..cbf54e08 100644 --- a/templates/layout/google_tag_manager.html +++ b/templates/layout/google_tag_manager.html @@ -66,6 +66,20 @@ goals: goals, } }()); + + var carrotquest = (function() { + var data_ = []; + + var identify = function(data) { + data_.push(data); + console.log(data); + }; + + return { + identify: identify, + data: data_, + } + }()); {% endif %} {% endif %} From d72c165b1e69a8a9e46e69b15639a59cfd9857d9 Mon Sep 17 00:00:00 2001 From: duker33 Date: Mon, 30 Sep 2019 19:26:24 +0300 Subject: [PATCH 4/4] #977 Apply linter rules --- front/js/shared/tracking.es6 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/front/js/shared/tracking.es6 b/front/js/shared/tracking.es6 index f38e3cf4..1d409d78 100644 --- a/front/js/shared/tracking.es6 +++ b/front/js/shared/tracking.es6 @@ -40,7 +40,7 @@ // until my_counter object won't be fully loaded. // See our custom the Google Analytics code as reference implementation: // https://github.com/fidals/refarm-site/pull/314/files - carrotquest.identify({'$phone': phone}); + carrotquest.identify({ $phone: phone }); // Ignore ESLintBear (no-undef) }); mediator.subscribe('onOrderSend', () => { reachGoal('CMN_BUY_SEND'); @@ -60,7 +60,7 @@ mediator.subscribe('onProductDetail', (_, data) => yaTracker.detail([data])); mediator.subscribe('onBackCallSend', (_, phone) => { reachGoal('BACK_CALL_SEND'); - carrotquest.identify({'$phone': phone}); + carrotquest.identify({ $phone: phone }); // Ignore ESLintBear (no-undef) }); mediator.subscribe('onSuccessOrder', (_, orderPositions, orderData) => { yaTracker.purchase(orderPositions, orderData);