Advertisement
akozhomka

JS (themes/redesign/custom-js/profile_filters.js)

Feb 23rd, 2022
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Аналитика личного кабинета
  3.  * https://docs.google.com/spreadsheets/d/1vDJ6VgErqgP3lDb1Z4KrvpHmWgp-DHnMB8VhQiQ0nNE/edit#gid=1848405132
  4.  */
  5.  
  6. /**
  7.  * @param {GaConfig} config
  8.  * @param {boolean} sendOnce
  9.  */
  10. function sendFormCabinetGa(config, sendOnce = false) {
  11.     config.action = config.action ?? 'order';
  12.     sendToGoogleAnalytics(config, sendOnce, 'Form-Cabinet')
  13. }
  14.  
  15. document.querySelector(document).addEventListener('ready', () => {
  16.     /**
  17.      * back-to-all-orders-top - нажатие на вернуться к заказам вверху
  18.      * back-to-all-orders-below - нажатие на вернуться к заказам внизу страницы
  19.      */
  20.     document.querySelector(document).addEventListener('click', '.n-profile-orders__back a', (e) => {
  21.         let position = document.querySelector(e.currentTarget).attr('data-position');
  22.  
  23.         if (!isValidPosition(position)) {
  24.             return;
  25.         }
  26.         let config = getGaConfig();
  27.         config.label = 'back-to-all-orders-' + position;
  28.  
  29.         sendFormCabinetGa(config);
  30.     });
  31.  
  32.     /**
  33.      * receipt-open - нажатие на электронный чек (открытие попапа)
  34.      */
  35.     document.querySelector(document).addEventListener('click', '[data-open-check]', () => {
  36.         let config = getGaConfig();
  37.         config.label = 'receipt-open';
  38.         config.value = getOrderId();
  39.  
  40.         sendFormCabinetGa(config);
  41.     });
  42.  
  43.     /**
  44.      * receipt-close - закрытие попапа чека
  45.      */
  46.     document.querySelector(document).addEventListener('tmp-popup:hide', (e) => {
  47.         if (e.tmp_popup_id === 'popupProfileCheck') {
  48.             let config = getGaConfig();
  49.             config.label = 'receipt-close';
  50.             config.value = getOrderId();
  51.  
  52.             sendFormCabinetGa(config);
  53.         }
  54.     })
  55.  
  56.     /**
  57.      * receipt-download - нажатие на скачать в попапе
  58.      */
  59.     document.querySelector(document).addEventListener('click', '#popupProfileCheck .profile-popup-info__btn', () => {
  60.         let config = getGaConfig();
  61.         config.label = 'receipt-download';
  62.         config.value = getOrderId();
  63.  
  64.         sendFormCabinetGa(config);
  65.     })
  66.  
  67.     /**
  68.      * report-issue-button-top - нажатие на кнопку сообщить о проблеме вверху
  69.      * report-issue-button-below - нажатие на кнопку сообщить о проблеме  внизу страницы
  70.      */
  71.     document.querySelector(document).addEventListener('click', '[data-report-an-issue-popup]', (e) => {
  72.         let position = document.querySelector(e.currentTarget).parents('.n-profile-orders-list-item-buttons-wrap').attr('data-position');
  73.         if (position && !isValidPosition(position)) {
  74.             return;
  75.         }
  76.         let config = getGaConfig();
  77.         config.label = 'report-issue-button' + (position ? '-' + position : '');
  78.         config.value = getOrderId();
  79.  
  80.         sendFormCabinetGa(config);
  81.     });
  82.  
  83.     /**
  84.      * report-issue-close - закрытие попапа сообщить о проблеме, через Х (закрыть)
  85.      * report-issue-thanks-close - закрытие попапа спасибо, через Х (закрыть)
  86.      */
  87.     document.querySelector(document).addEventListener('click', '#popupProfileProblem .F-popup__close', (e) => {
  88.         let config = getGaConfig();
  89.         if (document.querySelector(e.currentTarget).attr('data-close-thanks')) {
  90.             config.label = 'report-issue-thanks-close';
  91.         } else {
  92.             config.label = 'report-issue-close';
  93.         }
  94.         config.value = getOrderId();
  95.         sendFormCabinetGa(config);
  96.     });
  97.  
  98.     /**
  99.      * report-issue-thanks - показали пользователю попап спасибо https://skr.sh/sAsmaFUuvPs
  100.      */
  101.     document.querySelector(document).addEventListener('issue_popup:show_success_message', () => {
  102.         let config = getGaConfig();
  103.         config.label = 'report-issue-thanks';
  104.         config.value = getOrderId();
  105.         sendFormCabinetGa(config);
  106.     });
  107.  
  108.     /**
  109.      * report-issue-cancel - закрытие попапа сообщить о проблеме через кнопку отмена
  110.      */
  111.     document.querySelector(document).addEventListener('click', '#popupProfileProblem .profile-popup-info__btn_cancel', () => {
  112.         let config = getGaConfig();
  113.         config.label = 'report-issue-cancel';
  114.         config.value = getOrderId();
  115.         sendFormCabinetGa(config);
  116.     });
  117.  
  118.     /**
  119.      * report-issue-edit-description - внесение хотя бы 3 символа в поле "что пошло не так?"
  120.      */
  121.     document.querySelector(document).addEventListener('keyup', '#popupProfileProblem .profile-popup-info__problem', (e) => {
  122.         let textarea = document.querySelector(e.currentTarget);
  123.         if (textarea.value.length <= 3) {
  124.             return;
  125.         }
  126.         let config = getGaConfig();
  127.         config.label = 'report-issue-edit-description';
  128.         config.value = getOrderId();
  129.         sendFormCabinetGa(config, true);
  130.     });
  131.  
  132.     /**
  133.      * report-issue-send - нажатие на кнопку отправить
  134.      */
  135.     document.querySelector(document).addEventListener('click', '#popupProfileProblem .profile-popup-info__btn', () => {
  136.         let config = getGaConfig();
  137.         config.label = 'report-issue-send';
  138.         config.value = getOrderId();
  139.         sendFormCabinetGa(config);
  140.     });
  141.  
  142.     /**
  143.      * repeat-order-button-top - нажатие на кнопку повторить заказ вверху
  144.      * repeat-order-button-below - нажатие на кнопку повторить заказ  внизу страницы
  145.      */
  146.     document.querySelector(document).addEventListener('click', '[data-repeat-order]', (e) => {
  147.         let position = document.querySelector(e.currentTarget).parents('.n-profile-orders-list-item-buttons-wrap').attr('data-position');
  148.         if (position && !isValidPosition(position)) {
  149.             return;
  150.         }
  151.         let config = getGaConfig();
  152.         config.label = 'repeat-order-button' + (position ? '-' + position : '');
  153.         config.value = getOrderId();
  154.  
  155.         sendFormCabinetGa(config);
  156.     });
  157.  
  158.     /**
  159.      * pay-order-inactive-button-top - нажатие на не активную кнопку оплатить заказ вверху
  160.      * pay-order-inactive-button-below - нажатие на не активную кнопку оплатить заказ  внизу страницы
  161.      */
  162.     document.querySelector(document).addEventListener('click', '.n-profile-orders-list-item__btn-pay_disabled', (e) => {
  163.         let position = document.querySelector(e.currentTarget).parents('.n-profile-orders-list-item-buttons-wrap').attr('data-position');
  164.         if (position && !isValidPosition(position)) {
  165.             return;
  166.         }
  167.         let config = getGaConfig();
  168.         config.label = 'pay-order-inactive-button' + (position ? '-' + position : '');
  169.         config.value = getOrderId();
  170.  
  171.         sendFormCabinetGa(config);
  172.     });
  173.  
  174.     /**
  175.      * pay-order-active-button-top - нажатие на активную кнопку оплатить заказ вверху
  176.      * pay-order-active-button-below - нажатие на активную кнопку оплатить заказ внизу страницы
  177.      */
  178.     document.querySelector(document).addEventListener('click', '.n-profile-orders-list-item__btn-pay', (e) => {
  179.         let position = document.querySelector(e.currentTarget).parents('.n-profile-orders-list-item-buttons-wrap').attr('data-position');
  180.         if (position && !isValidPosition(position)) {
  181.             return;
  182.         }
  183.         let config = getGaConfig();
  184.         config.label = 'pay-order-active-button' + (position ? '-' + position : '');
  185.         config.value = getOrderId();
  186.  
  187.         sendFormCabinetGa(config);
  188.     });
  189.  
  190.     /**
  191.      * order-information-hide - скрыли информацию о заказе
  192.      * order-information-show - показали информацию о заказе
  193.      */
  194.     document.querySelector(document).addEventListener('click', '.n-profile-orders-detail-info__more', (e) => {
  195.         let type = document.querySelector(e.currentTarget).attr('data-type');
  196.         let config = getGaConfig();
  197.         config.label = 'order-information-' + type;
  198.         config.value = getOrderId();
  199.  
  200.         sendFormCabinetGa(config);
  201.     });
  202.  
  203.     /**
  204.      * order-information-map - нажатие на смотреть на карте
  205.      */
  206.     document.querySelector(document).addEventListener('click', '[data-map-link] a', () => {
  207.         let config = getGaConfig();
  208.         config.label = 'order-information-map';
  209.         config.value = getOrderId();
  210.  
  211.         sendFormCabinetGa(config);
  212.     });
  213.  
  214.     /**
  215.      * order-information-waybill - нажатие на ТТН
  216.      */
  217.     document.querySelector(document).addEventListener('click', '[data-ttn-link] a', () => {
  218.         let config = getGaConfig();
  219.         config.label = 'order-information-waybill';
  220.         config.value = getOrderId();
  221.  
  222.         sendFormCabinetGa(config);
  223.     });
  224.  
  225.     /**
  226.      * order-products-hide - скрыли товары в заказе
  227.      * order-products-show - показали товары в заказе
  228.      */
  229.     document.querySelector(document).addEventListener('click', '.n-profile-orders-detail-goods__more', (e) => {
  230.         let type = document.querySelector(e.currentTarget).attr('data-type');
  231.         let config = getGaConfig();
  232.         config.label = 'order-information-' + type;
  233.         config.value = getOrderId();
  234.  
  235.         sendFormCabinetGa(config);
  236.     });
  237.  
  238.     /**
  239.      * product-add-car - нажатие на добавить авто
  240.      * product-change-car - нажатие на изменить авто
  241.      */
  242.     document.querySelector(document).addEventListener('click', '[data-auto-add]', (e) => {
  243.         let type = document.querySelector(e.currentTarget).attr('data-type');
  244.         let config = getGaConfig();
  245.         config.label = 'product-' + type + '-car';
  246.  
  247.         sendFormCabinetGa(config);
  248.     });
  249.  
  250.     /**
  251.      * popup-car-close - закрытие попапа с выбором машины, через Х (закрыть)
  252.      */
  253.     document.querySelector(document).addEventListener('click', '#popupProfileAuto .F-popup__close', () => {
  254.         let config = getGaConfig();
  255.         config.label = 'popup-car-close';
  256.  
  257.         sendFormCabinetGa(config);
  258.     });
  259.  
  260.     /**
  261.      * popup-car-select - выбор машины из списка
  262.      */
  263.     document.querySelector(document).addEventListener('change', '.profile-popup-auto-list__item input', () => {
  264.         let config = getGaConfig();
  265.         config.label = 'popup-car-select';
  266.  
  267.         sendFormCabinetGa(config);
  268.     });
  269.  
  270.     /**
  271.      * popup-car-add-new-car - нажатие на кнопку добавить другое авто
  272.      */
  273.     document.querySelector(document).addEventListener('click', '[data-add-new-car]', () => {
  274.         let config = getGaConfig();
  275.         config.label = 'popup-car-add-new-car';
  276.  
  277.         sendFormCabinetGa(config);
  278.     });
  279.  
  280.     /**
  281.      * product-add-rating-link - нажатие на оценить
  282.      * product-change-rating - нажатие на изменить оценку
  283.      */
  284.     document.querySelector(document).addEventListener('click', '.n-profile-orders-detail-goods-list-item__review-box-btn', (e) => {
  285.         let reviewBox = document.querySelector(e.currentTarget).parents('.n-profile-orders-detail-goods-list-item__review-box');
  286.         let config = getGaConfig();
  287.         config.label = reviewBox.attr('data-type') === 'add'
  288.             ? 'product-add-rating-link'
  289.             : 'product-change-rating';
  290.  
  291.         sendFormCabinetGa(config);
  292.     });
  293.  
  294.     /**
  295.      * product-add-rating-star - нажатие на звездочку
  296.      * product-change-rating-star - нажатие на звездочку
  297.      */
  298.     document.querySelector(document).addEventListener('click', '.n-profile-orders-detail-goods-list-item-rate__item', (e) => {
  299.         let star = document.querySelector(e.currentTarget).attr('data-star');
  300.         let type = document.querySelector(e.currentTarget).parents('.n-profile-orders-detail-goods-list-item__review-box').attr('data-type');
  301.  
  302.         let config = getGaConfig();
  303.         config.label = 'product-' + type + '-rating-star'
  304.         if (type === 'add') {
  305.             config.value = star;
  306.         }
  307.  
  308.         sendFormCabinetGa(config);
  309.     });
  310.  
  311.     /**
  312.      * popup-rating-close - закрытие попапа оценки товара, через Х (закрыть)
  313.      */
  314.     document.querySelector(document).addEventListener('click', '[id^="popup-rate-"] .F-popup__close', () => {
  315.         let config = getGaConfig();
  316.         config.label = 'popup-rating-close';
  317.  
  318.         sendFormCabinetGa(config);
  319.     });
  320.  
  321.     /**
  322.      * popup-rating-add-tag - выбор тега
  323.      */
  324.     document.querySelector(document).addEventListener('change', '.answer-clickable', (e) => {
  325.         if (!document.querySelector(e.currentTarget).is(':checked')) {
  326.             return;
  327.         }
  328.         let config = getGaConfig();
  329.         config.label = 'popup-rating-add-tag';
  330.         config.value = document.querySelector(e.currentTarget).value;
  331.  
  332.         sendFormCabinetGa(config);
  333.     });
  334.  
  335.     /**
  336.      * popup-rating-activate-description - фокус в поле описание
  337.      */
  338.     document.querySelector(document).addEventListener('focus', '.rate-card-state__textarea', () => {
  339.         let config = getGaConfig();
  340.         config.label = 'popup-rating-activate-description';
  341.  
  342.         sendFormCabinetGa(config, true);
  343.     });
  344.  
  345.     /**
  346.      * popup-rating-add-description - внесение хотя бы 3 символов в поле
  347.      */
  348.     document.querySelector(document).addEventListener('keyup', '.rate-card-state__textarea', (e) => {
  349.         let textarea = document.querySelector(e.currentTarget);
  350.         if (textarea.value.length <= 3) {
  351.             return;
  352.         }
  353.         let config = getGaConfig();
  354.         config.label = 'popup-rating-add-description';
  355.  
  356.         sendFormCabinetGa(config, true);
  357.     });
  358.  
  359.     /**
  360.      * popup-rating-add-rating-star - нажатие на звездочку
  361.      */
  362.     document.querySelector(document).addEventListener('click', '.rate-card-recom-rate__item', (e) => {
  363.         let config = getGaConfig();
  364.         config.label = 'popup-rating-add-rating-star';
  365.         config.value = document.querySelector(e.currentTarget).attr('data-star');
  366.  
  367.         sendFormCabinetGa(config);
  368.     });
  369.  
  370.     /**
  371.      * popup-rating-done - нажатие на кнопку готово
  372.      */
  373.     document.querySelector(document).addEventListener('click', '.rate-card__btn-done', () => {
  374.         let config = getGaConfig();
  375.         config.label = 'popup-rating-done';
  376.  
  377.         sendFormCabinetGa(config);
  378.     });
  379.  
  380.     /**
  381.      * product-name-detail - нажатие на бренд товара в блоке товаров
  382.      * добавить параметры продукта по типу тех что летят при переходе с плитки на карточку https://skr.sh/sC0kd47kMfG
  383.      */
  384.     document.querySelector(document).addEventListener('click', '.n-profile-orders-detail-goods-list-item__title-box-title', (e) => {
  385.         addGaProduct(document.querySelector(e.currentTarget).parent().attr('data-op-id'))
  386.         let config = getGaConfig();
  387.         config.label = 'product-name-detail';
  388.         config.value = getOrderId();
  389.  
  390.         sendFormCabinetGa(config);
  391.     });
  392.  
  393.     /**
  394.      * product-photo-detail - нажатие на фото товара в блоке товаров
  395.      * добавить параметры продукта по типу тех что летят при переходе с плитки на карточку https://skr.sh/sC0kd47kMfG
  396.      */
  397.     document.querySelector(document).addEventListener('click', '.n-profile-orders-detail-goods-list-item__title-box-img', (e) => {
  398.         addGaProduct(document.querySelector(e.currentTarget).parent().attr('data-op-id'))
  399.         let config = getGaConfig();
  400.         config.label = 'product-photo-detail';
  401.         config.value = getOrderId();
  402.  
  403.         sendFormCabinetGa(config);
  404.     });
  405.  
  406.     /**
  407.      * popup-rating-product-detail - нажатие на товар
  408.      */
  409.     document.querySelector(document).addEventListener('click', '.rate-card__serie', (e) => {
  410.         let opId = document.querySelector(e.currentTarget).parents('.rate-card').attr('data-id');
  411.         addGaProduct(opId);
  412.  
  413.         let config = getGaConfig();
  414.         config.label = 'popup-rating-product-detail';
  415.         config.value = getOrderId();
  416.  
  417.         sendFormCabinetGa(config);
  418.     });
  419.  
  420.     /**
  421.      * details-button - нажатие на кнопку "Детали заказа" или ">"
  422.      */
  423.     document.querySelector(document).addEventListener('click', '.n-profile-orders-list-item__more', (e) => {
  424.         let config = getGaConfig();
  425.         config.label = 'details-button';
  426.         config.value = document.querySelector(e.currentTarget)
  427.             .parents('.n-profile-orders-list-item.pagination-item')
  428.             .attr('data-order-id');
  429.         config.action = 'orders';
  430.  
  431.         sendFormCabinetGa(config);
  432.     });
  433.  
  434.     /**
  435.      * details - нажатие на № заказа
  436.      */
  437.     document.querySelector(document).addEventListener('click', '.n-profile-orders-list-item__title', (e) => {
  438.         let config = getGaConfig();
  439.         config.label = 'details';
  440.         config.value = document.querySelector(e.currentTarget)
  441.             .parents('.n-profile-orders-list-item.pagination-item')
  442.             .attr('data-order-id');
  443.         config.action = 'orders';
  444.  
  445.         sendFormCabinetGa(config);
  446.     });
  447.  
  448.     /**
  449.      * details - нажатие на № заказа
  450.      */
  451.     document.querySelector(document).addEventListener('click', '.n-profile-orders-cart__pics.orders-pics li', (e) => {
  452.         let config = getGaConfig();
  453.         config.action = 'orders';
  454.         config.label = 'details-product-photo';
  455.         config.value =document.querySelector(e.currentTarget)
  456.             .parents('.n-profile-orders-list-item.pagination-item')
  457.             .attr('data-order-id');
  458.  
  459.         sendFormCabinetGa(config);
  460.     });
  461.  
  462.     /***********************
  463.      * Купленные товары
  464.      **********************/
  465.  
  466.     /**
  467.      * переход на артикул с купленных товаров
  468.      * goods-purchased:name - нажатие на бренд товара
  469.      */
  470.     document.querySelector(document).addEventListener('click', '.product-card__layout-name', () => {
  471.         let config = getGaConfig();
  472.         config.category = 'UX-Click';
  473.         config.action = 'detail-click';
  474.         config.label = 'goods-purchased:name'
  475.         sendToGoogleAnalytics(config, config.category);
  476.     });
  477.  
  478.     /**
  479.      * переход на артикул с купленных товаров
  480.      * goods-purchased:photo - нажатие на фото товара
  481.      */
  482.     document.querySelector(document).addEventListener('click', '.product-card__layout-pic', () => {
  483.         let config = getGaConfig();
  484.         config.category = 'UX-Click';
  485.         config.action = 'detail-click';
  486.         config.label = 'goods-purchased:photo'
  487.         sendToGoogleAnalytics(config, config.category);
  488.     });
  489.  
  490.     /**
  491.      * переход на артикул с купленных товаров
  492.      * goods-purchased:more - нажатие на смотреть подробней
  493.      */
  494.     document.querySelector(document).addEventListener('click', '.product-card__bottom-block a', () => {
  495.         let config = getGaConfig();
  496.         config.category = 'UX-Click';
  497.         config.action = 'detail-click';
  498.         config.label = 'goods-purchased:more'
  499.         sendToGoogleAnalytics(config, config.category);
  500.     });
  501.  
  502.     /**
  503.      * переход на артикул с купленных товаров
  504.      * goods-purchased:star - нажатие на оценку товара"
  505.      */
  506.     document.querySelector(document).addEventListener('click', '.product-card-recom_link', () => {
  507.         let config = getGaConfig();
  508.         config.category = 'UX-Click';
  509.         config.action = 'detail-click';
  510.         config.label = 'goods-purchased:star'
  511.         sendToGoogleAnalytics(config, config.category);
  512.     });
  513.  
  514.     /**
  515.      * кнопка "Купить" в купленных товарах
  516.      */
  517.     document.querySelector(document).addEventListener('click', '.n-profile-orders-goods-list-wrap .product-card__button-buy', (e) => {
  518.         let btn = document.querySelector(e.currentTarget);
  519.         if (btn.classList.contains('in-cart')) {
  520.             return;
  521.         }
  522.  
  523.         let config = getGaConfig();
  524.         config.category = 'UX-Click';
  525.         config.action = 'add-to-cart';
  526.         config.label = 'goods-purchased';
  527.         let product;
  528.         let position = btn.parents('.product-card_n-profile').attr('data-position');
  529.         if (cartRes) {
  530.             for (var i = 0; i < cartRes.length; i++) {
  531.                 if (cartRes[i].position == position) {
  532.                     product = cartRes[i];
  533.                     break;
  534.                 }
  535.             }
  536.  
  537.             gaWrapper.ga('ec:addProduct', product);
  538.             gaWrapper.ga('ec:setAction', 'detail', {'list': product.list});
  539.             sendToGoogleAnalytics(config, config.category);
  540.         }
  541.     });
  542.  
  543.     /**
  544.      * кнопка "Аналоги" в купленных товарах
  545.      */
  546.     document.querySelector(document).addEventListener('click', '.to-analogs-button-tile', () => {
  547.         let config = getGaConfig();
  548.         config.category = 'UX-Click';
  549.         config.action = 'see-analogs';
  550.         config.label = 'goods-purchased';
  551.         sendToGoogleAnalytics(config, config.category);
  552.     });
  553.  
  554.     document.querySelector(document).addEventListener('click', '.favorite-heart.favorite-heart_empty', () => {
  555.         let config = getGaConfig();
  556.         config.category = 'Favorite';
  557.         config.action = 'add-to-favorite';
  558.         config.label = 'goods-purchased';
  559.         sendToGoogleAnalytics(config, config.category);
  560.     });
  561.  
  562.     document.querySelector(document).addEventListener('click', '.favorite-heart.favorite-heart_full', () => {
  563.         let config = getGaConfig();
  564.         config.category = 'Favorite';
  565.         config.action = 'favorite-visit';
  566.         config.label = 'goods-purchased';
  567.         sendToGoogleAnalytics(config, config.category);
  568.     });
  569.  
  570.     document.querySelector(document).addEventListener('copy', '.product-card__layout-name', () => {
  571.         AnalyticsCopying.copyEvent('profile-goods-purchased');
  572.     });
  573.  
  574.     document.querySelector(document).addEventListener('copy', '.n-profile-orders-detail-goods-list-item__title-box', () => {
  575.         AnalyticsCopying.copyEvent('profile-order');
  576.     })
  577.  
  578.     document.querySelector('.n-profile-orders-filters__btn_sort .select-sort-current').click(function () {
  579.         let isOpen = document.querySelector(this).parent().classList.contains('select-sort_open')
  580.             || document.querySelector('.catalog__sort-form-mobile').is(':visible');
  581.         let config = getGaConfig();
  582.         config.category = 'Products-Sort';
  583.         config.action = 'sort-option';
  584.         config.label = isOpen ? 'activate' : 'deactivate';
  585.         sendToGoogleAnalytics(config, config.category);
  586.     });
  587.  
  588.     document.querySelector(document).addEventListener('click', '.filters-close', () => {
  589.         let config = getGaConfig();
  590.         config.category = 'Products-Filter';
  591.         config.action = 'filter-popup';
  592.         config.label = 'close';
  593.         sendToGoogleAnalytics(config, config.category);
  594.     });
  595.  
  596.     document.querySelector('.catalog__mob-filter-btn').addEventListener('click', () => {
  597.         let config = getGaConfig();
  598.         config.category = 'Products-Filter';
  599.         config.action = 'filter-popup';
  600.         config.label = 'open';
  601.         sendToGoogleAnalytics(config, config.category);
  602.     });
  603.  
  604.     //открытие/закрытие панели фильтров через конкретный блок
  605.     document.querySelector('.n-profile-orders-filters__btn_filter').addEventListener('click', (event) => {
  606.         let name = document.querySelector(event.currentTarget).children('.select-sort-current').text();
  607.         let target = document.querySelector(`.filter__title[data-name=${name}]`);
  608.         if (target.length === 0){
  609.             return;
  610.         }
  611.  
  612.         let filter = target.siblings('.filter__list').attr('data-key');
  613.  
  614.         let config = getGaConfig();
  615.         config.category = 'Products-Filter';
  616.         config.action = 'filter-popup-section';
  617.         config.label = filter;
  618.         sendToGoogleAnalytics(config, config.category);
  619.     });
  620.  
  621.     document.querySelector(document).addEventListener('click', '.filter__title', (event) => {
  622.         let filter = document.querySelector(event.currentTarget).siblings('.filter__list').attr('data-key');
  623.  
  624.         let config = getGaConfig();
  625.         config.category = 'Products-Filter';
  626.         config.action = 'section-click';
  627.         config.label = filter;
  628.         sendToGoogleAnalytics(config, config.category);
  629.     });
  630.  
  631.     document.querySelector(document).addEventListener('click', 'input[type="checkbox"]', (event) => {
  632.         let target = event.currentTarget;
  633.         let parent = document.querySelector(target).closest('.filter__list');
  634.         let filter = parent.attr('data-key');
  635.  
  636.         let config = getGaConfig();
  637.         config.category = 'Products-Filter';
  638.         config.action = 'filter-tick';
  639.         config.label = filter + ':' + document.querySelector(target).attr('data-value');
  640.         config.value = parent.querySelector('input').index(document.querySelector(target)) + 1;
  641.         sendToGoogleAnalytics(config, config.category);
  642.     });
  643.  
  644.     document.querySelector(document).addEventListener('click', '.filter-btn_show', () => {
  645.         let label = '';
  646.         $.each(document.querySelector('.filter_list_checkbox'), function (number, filter) {
  647.             let key = document.querySelector(filter).attr('data-key');
  648.             let listItem = document.querySelector(filter).querySelector('input[type="checkbox"]:checked');
  649.             $.each(listItem, function (number, item) {
  650.                 let value = document.querySelector(item).attr('data-value');
  651.                 label += `;${key}:${value}`;
  652.             });
  653.         });
  654.  
  655.         let config = getGaConfig();
  656.         config.category = 'Products-Filter';
  657.         config.action = 'filter-submit';
  658.         config.label = label.substring(1);
  659.         sendToGoogleAnalytics(config, config.category);
  660.     });
  661.  
  662.     document.querySelector('.n-profile-orders-chosen-filters__item').addEventListener('click', (event) => {
  663.         let target = event.currentTarget;
  664.         let items = document.querySelector('.n-profile-orders-chosen-filters__item');
  665.  
  666.         let config = getGaConfig();
  667.         config.category = 'Products-Filter';
  668.         config.action = 'filter-delete';
  669.         config.label = document.querySelector(target).attr('data-id') + ':' + document.querySelector(target).attr('data-value');
  670.         config.value = (items.index(target) + 1) + ':' + items.length;
  671.         sendToGoogleAnalytics(config, config.category);
  672.     });
  673.  
  674.     document.querySelector('.n-profile-orders-chosen-filters__clear').addEventListener('click', () => {
  675.         let config = getGaConfig();
  676.         config.category = 'Products-Filter';
  677.         config.action = 'filter-delete-all';
  678.         config.label = '';
  679.         config.value = document.querySelector('#filter-count').text();
  680.         sendToGoogleAnalytics(config, config.category);
  681.     });
  682. });
  683.  
  684. /**
  685.  * @param {string} position
  686.  */
  687. function isValidPosition(position) {
  688.     if (position !== 'top' && position !== 'below') {
  689.         console.error('position может быть только top или below');
  690.         return false;
  691.     }
  692.  
  693.     return true;
  694. }
  695.  
  696. function sendDeactivateSortGA() {
  697.     let config = getGaConfig();
  698.     config.category = 'Products-Sort';
  699.     config.action = 'sort-option';
  700.     config.label = 'deactivate';
  701.     sendToGoogleAnalytics(config, config.category);
  702. }
  703.  
  704. function sendSelectedSortGA(label) {
  705.     let config = getGaConfig();
  706.     config.category = 'Products-Sort';
  707.     config.action = 'sort-complete';
  708.     config.label = label;
  709.     sendToGoogleAnalytics(config, config.category);
  710. }
  711.  
  712. function sendShowMoreGa(count, type) {
  713.     let config = getGaConfig();
  714.     if (type === 'products') {
  715.         config.category = 'Products-list';
  716.         config.action = 'show-more';
  717.         config.label = 'goods-purchased';
  718.         config.value = count;
  719.     }
  720.  
  721.     if (type === 'orders') {
  722.         config.category = 'Form-Cabinet';
  723.         config.action = 'orders';
  724.         config.label = 'show-more';
  725.         config.value = count;
  726.     }
  727.  
  728.     sendToGoogleAnalytics(config, config.category);
  729. }
  730.  
  731. /**
  732.  * @returns {string}
  733.  */
  734. function getOrderId() {
  735.     return document.querySelector('.inner-page[data-order-id]').attr('data-order-id');
  736. }
  737.  
  738. /**
  739.  * @param opId
  740.  */
  741. function addGaProduct(opId) {
  742.     gaWrapper.ga('ec:addProduct', gaProducts[opId]);
  743. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement