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..1d409d78 100644 --- a/front/js/shared/tracking.es6 +++ b/front/js/shared/tracking.es6 @@ -32,9 +32,15 @@ }; 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. + // See our custom the Google Analytics code as reference implementation: + // https://github.com/fidals/refarm-site/pull/314/files + carrotquest.identify({ $phone: phone }); // Ignore ESLintBear (no-undef) }); mediator.subscribe('onOrderSend', () => { reachGoal('CMN_BUY_SEND'); @@ -52,7 +58,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 }); // Ignore ESLintBear (no-undef) + }); mediator.subscribe('onSuccessOrder', (_, orderPositions, orderData) => { yaTracker.purchase(orderPositions, orderData); gaTracker.purchase(orderPositions, orderData); 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 %}