Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Аналитика личного кабинета
- * https://docs.google.com/spreadsheets/d/1vDJ6VgErqgP3lDb1Z4KrvpHmWgp-DHnMB8VhQiQ0nNE/edit#gid=1848405132
- */
- /**
- * @param {GaConfig} config
- * @param {boolean} sendOnce
- */
- function sendFormCabinetGa(config, sendOnce = false) {
- config.action = config.action ?? 'order';
- sendToGoogleAnalytics(config, sendOnce, 'Form-Cabinet')
- }
- document.querySelector(document).addEventListener('ready', () => {
- /**
- * back-to-all-orders-top - нажатие на вернуться к заказам вверху
- * back-to-all-orders-below - нажатие на вернуться к заказам внизу страницы
- */
- document.querySelector(document).addEventListener('click', '.n-profile-orders__back a', (e) => {
- let position = document.querySelector(e.currentTarget).attr('data-position');
- if (!isValidPosition(position)) {
- return;
- }
- let config = getGaConfig();
- config.label = 'back-to-all-orders-' + position;
- sendFormCabinetGa(config);
- });
- /**
- * receipt-open - нажатие на электронный чек (открытие попапа)
- */
- document.querySelector(document).addEventListener('click', '[data-open-check]', () => {
- let config = getGaConfig();
- config.label = 'receipt-open';
- config.value = getOrderId();
- sendFormCabinetGa(config);
- });
- /**
- * receipt-close - закрытие попапа чека
- */
- document.querySelector(document).addEventListener('tmp-popup:hide', (e) => {
- if (e.tmp_popup_id === 'popupProfileCheck') {
- let config = getGaConfig();
- config.label = 'receipt-close';
- config.value = getOrderId();
- sendFormCabinetGa(config);
- }
- })
- /**
- * receipt-download - нажатие на скачать в попапе
- */
- document.querySelector(document).addEventListener('click', '#popupProfileCheck .profile-popup-info__btn', () => {
- let config = getGaConfig();
- config.label = 'receipt-download';
- config.value = getOrderId();
- sendFormCabinetGa(config);
- })
- /**
- * report-issue-button-top - нажатие на кнопку сообщить о проблеме вверху
- * report-issue-button-below - нажатие на кнопку сообщить о проблеме внизу страницы
- */
- document.querySelector(document).addEventListener('click', '[data-report-an-issue-popup]', (e) => {
- let position = document.querySelector(e.currentTarget).parents('.n-profile-orders-list-item-buttons-wrap').attr('data-position');
- if (position && !isValidPosition(position)) {
- return;
- }
- let config = getGaConfig();
- config.label = 'report-issue-button' + (position ? '-' + position : '');
- config.value = getOrderId();
- sendFormCabinetGa(config);
- });
- /**
- * report-issue-close - закрытие попапа сообщить о проблеме, через Х (закрыть)
- * report-issue-thanks-close - закрытие попапа спасибо, через Х (закрыть)
- */
- document.querySelector(document).addEventListener('click', '#popupProfileProblem .F-popup__close', (e) => {
- let config = getGaConfig();
- if (document.querySelector(e.currentTarget).attr('data-close-thanks')) {
- config.label = 'report-issue-thanks-close';
- } else {
- config.label = 'report-issue-close';
- }
- config.value = getOrderId();
- sendFormCabinetGa(config);
- });
- /**
- * report-issue-thanks - показали пользователю попап спасибо https://skr.sh/sAsmaFUuvPs
- */
- document.querySelector(document).addEventListener('issue_popup:show_success_message', () => {
- let config = getGaConfig();
- config.label = 'report-issue-thanks';
- config.value = getOrderId();
- sendFormCabinetGa(config);
- });
- /**
- * report-issue-cancel - закрытие попапа сообщить о проблеме через кнопку отмена
- */
- document.querySelector(document).addEventListener('click', '#popupProfileProblem .profile-popup-info__btn_cancel', () => {
- let config = getGaConfig();
- config.label = 'report-issue-cancel';
- config.value = getOrderId();
- sendFormCabinetGa(config);
- });
- /**
- * report-issue-edit-description - внесение хотя бы 3 символа в поле "что пошло не так?"
- */
- document.querySelector(document).addEventListener('keyup', '#popupProfileProblem .profile-popup-info__problem', (e) => {
- let textarea = document.querySelector(e.currentTarget);
- if (textarea.value.length <= 3) {
- return;
- }
- let config = getGaConfig();
- config.label = 'report-issue-edit-description';
- config.value = getOrderId();
- sendFormCabinetGa(config, true);
- });
- /**
- * report-issue-send - нажатие на кнопку отправить
- */
- document.querySelector(document).addEventListener('click', '#popupProfileProblem .profile-popup-info__btn', () => {
- let config = getGaConfig();
- config.label = 'report-issue-send';
- config.value = getOrderId();
- sendFormCabinetGa(config);
- });
- /**
- * repeat-order-button-top - нажатие на кнопку повторить заказ вверху
- * repeat-order-button-below - нажатие на кнопку повторить заказ внизу страницы
- */
- document.querySelector(document).addEventListener('click', '[data-repeat-order]', (e) => {
- let position = document.querySelector(e.currentTarget).parents('.n-profile-orders-list-item-buttons-wrap').attr('data-position');
- if (position && !isValidPosition(position)) {
- return;
- }
- let config = getGaConfig();
- config.label = 'repeat-order-button' + (position ? '-' + position : '');
- config.value = getOrderId();
- sendFormCabinetGa(config);
- });
- /**
- * pay-order-inactive-button-top - нажатие на не активную кнопку оплатить заказ вверху
- * pay-order-inactive-button-below - нажатие на не активную кнопку оплатить заказ внизу страницы
- */
- document.querySelector(document).addEventListener('click', '.n-profile-orders-list-item__btn-pay_disabled', (e) => {
- let position = document.querySelector(e.currentTarget).parents('.n-profile-orders-list-item-buttons-wrap').attr('data-position');
- if (position && !isValidPosition(position)) {
- return;
- }
- let config = getGaConfig();
- config.label = 'pay-order-inactive-button' + (position ? '-' + position : '');
- config.value = getOrderId();
- sendFormCabinetGa(config);
- });
- /**
- * pay-order-active-button-top - нажатие на активную кнопку оплатить заказ вверху
- * pay-order-active-button-below - нажатие на активную кнопку оплатить заказ внизу страницы
- */
- document.querySelector(document).addEventListener('click', '.n-profile-orders-list-item__btn-pay', (e) => {
- let position = document.querySelector(e.currentTarget).parents('.n-profile-orders-list-item-buttons-wrap').attr('data-position');
- if (position && !isValidPosition(position)) {
- return;
- }
- let config = getGaConfig();
- config.label = 'pay-order-active-button' + (position ? '-' + position : '');
- config.value = getOrderId();
- sendFormCabinetGa(config);
- });
- /**
- * order-information-hide - скрыли информацию о заказе
- * order-information-show - показали информацию о заказе
- */
- document.querySelector(document).addEventListener('click', '.n-profile-orders-detail-info__more', (e) => {
- let type = document.querySelector(e.currentTarget).attr('data-type');
- let config = getGaConfig();
- config.label = 'order-information-' + type;
- config.value = getOrderId();
- sendFormCabinetGa(config);
- });
- /**
- * order-information-map - нажатие на смотреть на карте
- */
- document.querySelector(document).addEventListener('click', '[data-map-link] a', () => {
- let config = getGaConfig();
- config.label = 'order-information-map';
- config.value = getOrderId();
- sendFormCabinetGa(config);
- });
- /**
- * order-information-waybill - нажатие на ТТН
- */
- document.querySelector(document).addEventListener('click', '[data-ttn-link] a', () => {
- let config = getGaConfig();
- config.label = 'order-information-waybill';
- config.value = getOrderId();
- sendFormCabinetGa(config);
- });
- /**
- * order-products-hide - скрыли товары в заказе
- * order-products-show - показали товары в заказе
- */
- document.querySelector(document).addEventListener('click', '.n-profile-orders-detail-goods__more', (e) => {
- let type = document.querySelector(e.currentTarget).attr('data-type');
- let config = getGaConfig();
- config.label = 'order-information-' + type;
- config.value = getOrderId();
- sendFormCabinetGa(config);
- });
- /**
- * product-add-car - нажатие на добавить авто
- * product-change-car - нажатие на изменить авто
- */
- document.querySelector(document).addEventListener('click', '[data-auto-add]', (e) => {
- let type = document.querySelector(e.currentTarget).attr('data-type');
- let config = getGaConfig();
- config.label = 'product-' + type + '-car';
- sendFormCabinetGa(config);
- });
- /**
- * popup-car-close - закрытие попапа с выбором машины, через Х (закрыть)
- */
- document.querySelector(document).addEventListener('click', '#popupProfileAuto .F-popup__close', () => {
- let config = getGaConfig();
- config.label = 'popup-car-close';
- sendFormCabinetGa(config);
- });
- /**
- * popup-car-select - выбор машины из списка
- */
- document.querySelector(document).addEventListener('change', '.profile-popup-auto-list__item input', () => {
- let config = getGaConfig();
- config.label = 'popup-car-select';
- sendFormCabinetGa(config);
- });
- /**
- * popup-car-add-new-car - нажатие на кнопку добавить другое авто
- */
- document.querySelector(document).addEventListener('click', '[data-add-new-car]', () => {
- let config = getGaConfig();
- config.label = 'popup-car-add-new-car';
- sendFormCabinetGa(config);
- });
- /**
- * product-add-rating-link - нажатие на оценить
- * product-change-rating - нажатие на изменить оценку
- */
- document.querySelector(document).addEventListener('click', '.n-profile-orders-detail-goods-list-item__review-box-btn', (e) => {
- let reviewBox = document.querySelector(e.currentTarget).parents('.n-profile-orders-detail-goods-list-item__review-box');
- let config = getGaConfig();
- config.label = reviewBox.attr('data-type') === 'add'
- ? 'product-add-rating-link'
- : 'product-change-rating';
- sendFormCabinetGa(config);
- });
- /**
- * product-add-rating-star - нажатие на звездочку
- * product-change-rating-star - нажатие на звездочку
- */
- document.querySelector(document).addEventListener('click', '.n-profile-orders-detail-goods-list-item-rate__item', (e) => {
- let star = document.querySelector(e.currentTarget).attr('data-star');
- let type = document.querySelector(e.currentTarget).parents('.n-profile-orders-detail-goods-list-item__review-box').attr('data-type');
- let config = getGaConfig();
- config.label = 'product-' + type + '-rating-star'
- if (type === 'add') {
- config.value = star;
- }
- sendFormCabinetGa(config);
- });
- /**
- * popup-rating-close - закрытие попапа оценки товара, через Х (закрыть)
- */
- document.querySelector(document).addEventListener('click', '[id^="popup-rate-"] .F-popup__close', () => {
- let config = getGaConfig();
- config.label = 'popup-rating-close';
- sendFormCabinetGa(config);
- });
- /**
- * popup-rating-add-tag - выбор тега
- */
- document.querySelector(document).addEventListener('change', '.answer-clickable', (e) => {
- if (!document.querySelector(e.currentTarget).is(':checked')) {
- return;
- }
- let config = getGaConfig();
- config.label = 'popup-rating-add-tag';
- config.value = document.querySelector(e.currentTarget).value;
- sendFormCabinetGa(config);
- });
- /**
- * popup-rating-activate-description - фокус в поле описание
- */
- document.querySelector(document).addEventListener('focus', '.rate-card-state__textarea', () => {
- let config = getGaConfig();
- config.label = 'popup-rating-activate-description';
- sendFormCabinetGa(config, true);
- });
- /**
- * popup-rating-add-description - внесение хотя бы 3 символов в поле
- */
- document.querySelector(document).addEventListener('keyup', '.rate-card-state__textarea', (e) => {
- let textarea = document.querySelector(e.currentTarget);
- if (textarea.value.length <= 3) {
- return;
- }
- let config = getGaConfig();
- config.label = 'popup-rating-add-description';
- sendFormCabinetGa(config, true);
- });
- /**
- * popup-rating-add-rating-star - нажатие на звездочку
- */
- document.querySelector(document).addEventListener('click', '.rate-card-recom-rate__item', (e) => {
- let config = getGaConfig();
- config.label = 'popup-rating-add-rating-star';
- config.value = document.querySelector(e.currentTarget).attr('data-star');
- sendFormCabinetGa(config);
- });
- /**
- * popup-rating-done - нажатие на кнопку готово
- */
- document.querySelector(document).addEventListener('click', '.rate-card__btn-done', () => {
- let config = getGaConfig();
- config.label = 'popup-rating-done';
- sendFormCabinetGa(config);
- });
- /**
- * product-name-detail - нажатие на бренд товара в блоке товаров
- * добавить параметры продукта по типу тех что летят при переходе с плитки на карточку https://skr.sh/sC0kd47kMfG
- */
- document.querySelector(document).addEventListener('click', '.n-profile-orders-detail-goods-list-item__title-box-title', (e) => {
- addGaProduct(document.querySelector(e.currentTarget).parent().attr('data-op-id'))
- let config = getGaConfig();
- config.label = 'product-name-detail';
- config.value = getOrderId();
- sendFormCabinetGa(config);
- });
- /**
- * product-photo-detail - нажатие на фото товара в блоке товаров
- * добавить параметры продукта по типу тех что летят при переходе с плитки на карточку https://skr.sh/sC0kd47kMfG
- */
- document.querySelector(document).addEventListener('click', '.n-profile-orders-detail-goods-list-item__title-box-img', (e) => {
- addGaProduct(document.querySelector(e.currentTarget).parent().attr('data-op-id'))
- let config = getGaConfig();
- config.label = 'product-photo-detail';
- config.value = getOrderId();
- sendFormCabinetGa(config);
- });
- /**
- * popup-rating-product-detail - нажатие на товар
- */
- document.querySelector(document).addEventListener('click', '.rate-card__serie', (e) => {
- let opId = document.querySelector(e.currentTarget).parents('.rate-card').attr('data-id');
- addGaProduct(opId);
- let config = getGaConfig();
- config.label = 'popup-rating-product-detail';
- config.value = getOrderId();
- sendFormCabinetGa(config);
- });
- /**
- * details-button - нажатие на кнопку "Детали заказа" или ">"
- */
- document.querySelector(document).addEventListener('click', '.n-profile-orders-list-item__more', (e) => {
- let config = getGaConfig();
- config.label = 'details-button';
- config.value = document.querySelector(e.currentTarget)
- .parents('.n-profile-orders-list-item.pagination-item')
- .attr('data-order-id');
- config.action = 'orders';
- sendFormCabinetGa(config);
- });
- /**
- * details - нажатие на № заказа
- */
- document.querySelector(document).addEventListener('click', '.n-profile-orders-list-item__title', (e) => {
- let config = getGaConfig();
- config.label = 'details';
- config.value = document.querySelector(e.currentTarget)
- .parents('.n-profile-orders-list-item.pagination-item')
- .attr('data-order-id');
- config.action = 'orders';
- sendFormCabinetGa(config);
- });
- /**
- * details - нажатие на № заказа
- */
- document.querySelector(document).addEventListener('click', '.n-profile-orders-cart__pics.orders-pics li', (e) => {
- let config = getGaConfig();
- config.action = 'orders';
- config.label = 'details-product-photo';
- config.value =document.querySelector(e.currentTarget)
- .parents('.n-profile-orders-list-item.pagination-item')
- .attr('data-order-id');
- sendFormCabinetGa(config);
- });
- /***********************
- * Купленные товары
- **********************/
- /**
- * переход на артикул с купленных товаров
- * goods-purchased:name - нажатие на бренд товара
- */
- document.querySelector(document).addEventListener('click', '.product-card__layout-name', () => {
- let config = getGaConfig();
- config.category = 'UX-Click';
- config.action = 'detail-click';
- config.label = 'goods-purchased:name'
- sendToGoogleAnalytics(config, config.category);
- });
- /**
- * переход на артикул с купленных товаров
- * goods-purchased:photo - нажатие на фото товара
- */
- document.querySelector(document).addEventListener('click', '.product-card__layout-pic', () => {
- let config = getGaConfig();
- config.category = 'UX-Click';
- config.action = 'detail-click';
- config.label = 'goods-purchased:photo'
- sendToGoogleAnalytics(config, config.category);
- });
- /**
- * переход на артикул с купленных товаров
- * goods-purchased:more - нажатие на смотреть подробней
- */
- document.querySelector(document).addEventListener('click', '.product-card__bottom-block a', () => {
- let config = getGaConfig();
- config.category = 'UX-Click';
- config.action = 'detail-click';
- config.label = 'goods-purchased:more'
- sendToGoogleAnalytics(config, config.category);
- });
- /**
- * переход на артикул с купленных товаров
- * goods-purchased:star - нажатие на оценку товара"
- */
- document.querySelector(document).addEventListener('click', '.product-card-recom_link', () => {
- let config = getGaConfig();
- config.category = 'UX-Click';
- config.action = 'detail-click';
- config.label = 'goods-purchased:star'
- sendToGoogleAnalytics(config, config.category);
- });
- /**
- * кнопка "Купить" в купленных товарах
- */
- document.querySelector(document).addEventListener('click', '.n-profile-orders-goods-list-wrap .product-card__button-buy', (e) => {
- let btn = document.querySelector(e.currentTarget);
- if (btn.classList.contains('in-cart')) {
- return;
- }
- let config = getGaConfig();
- config.category = 'UX-Click';
- config.action = 'add-to-cart';
- config.label = 'goods-purchased';
- let product;
- let position = btn.parents('.product-card_n-profile').attr('data-position');
- if (cartRes) {
- for (var i = 0; i < cartRes.length; i++) {
- if (cartRes[i].position == position) {
- product = cartRes[i];
- break;
- }
- }
- gaWrapper.ga('ec:addProduct', product);
- gaWrapper.ga('ec:setAction', 'detail', {'list': product.list});
- sendToGoogleAnalytics(config, config.category);
- }
- });
- /**
- * кнопка "Аналоги" в купленных товарах
- */
- document.querySelector(document).addEventListener('click', '.to-analogs-button-tile', () => {
- let config = getGaConfig();
- config.category = 'UX-Click';
- config.action = 'see-analogs';
- config.label = 'goods-purchased';
- sendToGoogleAnalytics(config, config.category);
- });
- document.querySelector(document).addEventListener('click', '.favorite-heart.favorite-heart_empty', () => {
- let config = getGaConfig();
- config.category = 'Favorite';
- config.action = 'add-to-favorite';
- config.label = 'goods-purchased';
- sendToGoogleAnalytics(config, config.category);
- });
- document.querySelector(document).addEventListener('click', '.favorite-heart.favorite-heart_full', () => {
- let config = getGaConfig();
- config.category = 'Favorite';
- config.action = 'favorite-visit';
- config.label = 'goods-purchased';
- sendToGoogleAnalytics(config, config.category);
- });
- document.querySelector(document).addEventListener('copy', '.product-card__layout-name', () => {
- AnalyticsCopying.copyEvent('profile-goods-purchased');
- });
- document.querySelector(document).addEventListener('copy', '.n-profile-orders-detail-goods-list-item__title-box', () => {
- AnalyticsCopying.copyEvent('profile-order');
- })
- document.querySelector('.n-profile-orders-filters__btn_sort .select-sort-current').click(function () {
- let isOpen = document.querySelector(this).parent().classList.contains('select-sort_open')
- || document.querySelector('.catalog__sort-form-mobile').is(':visible');
- let config = getGaConfig();
- config.category = 'Products-Sort';
- config.action = 'sort-option';
- config.label = isOpen ? 'activate' : 'deactivate';
- sendToGoogleAnalytics(config, config.category);
- });
- document.querySelector(document).addEventListener('click', '.filters-close', () => {
- let config = getGaConfig();
- config.category = 'Products-Filter';
- config.action = 'filter-popup';
- config.label = 'close';
- sendToGoogleAnalytics(config, config.category);
- });
- document.querySelector('.catalog__mob-filter-btn').addEventListener('click', () => {
- let config = getGaConfig();
- config.category = 'Products-Filter';
- config.action = 'filter-popup';
- config.label = 'open';
- sendToGoogleAnalytics(config, config.category);
- });
- //открытие/закрытие панели фильтров через конкретный блок
- document.querySelector('.n-profile-orders-filters__btn_filter').addEventListener('click', (event) => {
- let name = document.querySelector(event.currentTarget).children('.select-sort-current').text();
- let target = document.querySelector(`.filter__title[data-name=${name}]`);
- if (target.length === 0){
- return;
- }
- let filter = target.siblings('.filter__list').attr('data-key');
- let config = getGaConfig();
- config.category = 'Products-Filter';
- config.action = 'filter-popup-section';
- config.label = filter;
- sendToGoogleAnalytics(config, config.category);
- });
- document.querySelector(document).addEventListener('click', '.filter__title', (event) => {
- let filter = document.querySelector(event.currentTarget).siblings('.filter__list').attr('data-key');
- let config = getGaConfig();
- config.category = 'Products-Filter';
- config.action = 'section-click';
- config.label = filter;
- sendToGoogleAnalytics(config, config.category);
- });
- document.querySelector(document).addEventListener('click', 'input[type="checkbox"]', (event) => {
- let target = event.currentTarget;
- let parent = document.querySelector(target).closest('.filter__list');
- let filter = parent.attr('data-key');
- let config = getGaConfig();
- config.category = 'Products-Filter';
- config.action = 'filter-tick';
- config.label = filter + ':' + document.querySelector(target).attr('data-value');
- config.value = parent.querySelector('input').index(document.querySelector(target)) + 1;
- sendToGoogleAnalytics(config, config.category);
- });
- document.querySelector(document).addEventListener('click', '.filter-btn_show', () => {
- let label = '';
- $.each(document.querySelector('.filter_list_checkbox'), function (number, filter) {
- let key = document.querySelector(filter).attr('data-key');
- let listItem = document.querySelector(filter).querySelector('input[type="checkbox"]:checked');
- $.each(listItem, function (number, item) {
- let value = document.querySelector(item).attr('data-value');
- label += `;${key}:${value}`;
- });
- });
- let config = getGaConfig();
- config.category = 'Products-Filter';
- config.action = 'filter-submit';
- config.label = label.substring(1);
- sendToGoogleAnalytics(config, config.category);
- });
- document.querySelector('.n-profile-orders-chosen-filters__item').addEventListener('click', (event) => {
- let target = event.currentTarget;
- let items = document.querySelector('.n-profile-orders-chosen-filters__item');
- let config = getGaConfig();
- config.category = 'Products-Filter';
- config.action = 'filter-delete';
- config.label = document.querySelector(target).attr('data-id') + ':' + document.querySelector(target).attr('data-value');
- config.value = (items.index(target) + 1) + ':' + items.length;
- sendToGoogleAnalytics(config, config.category);
- });
- document.querySelector('.n-profile-orders-chosen-filters__clear').addEventListener('click', () => {
- let config = getGaConfig();
- config.category = 'Products-Filter';
- config.action = 'filter-delete-all';
- config.label = '';
- config.value = document.querySelector('#filter-count').text();
- sendToGoogleAnalytics(config, config.category);
- });
- });
- /**
- * @param {string} position
- */
- function isValidPosition(position) {
- if (position !== 'top' && position !== 'below') {
- console.error('position может быть только top или below');
- return false;
- }
- return true;
- }
- function sendDeactivateSortGA() {
- let config = getGaConfig();
- config.category = 'Products-Sort';
- config.action = 'sort-option';
- config.label = 'deactivate';
- sendToGoogleAnalytics(config, config.category);
- }
- function sendSelectedSortGA(label) {
- let config = getGaConfig();
- config.category = 'Products-Sort';
- config.action = 'sort-complete';
- config.label = label;
- sendToGoogleAnalytics(config, config.category);
- }
- function sendShowMoreGa(count, type) {
- let config = getGaConfig();
- if (type === 'products') {
- config.category = 'Products-list';
- config.action = 'show-more';
- config.label = 'goods-purchased';
- config.value = count;
- }
- if (type === 'orders') {
- config.category = 'Form-Cabinet';
- config.action = 'orders';
- config.label = 'show-more';
- config.value = count;
- }
- sendToGoogleAnalytics(config, config.category);
- }
- /**
- * @returns {string}
- */
- function getOrderId() {
- return document.querySelector('.inner-page[data-order-id]').attr('data-order-id');
- }
- /**
- * @param opId
- */
- function addGaProduct(opId) {
- gaWrapper.ga('ec:addProduct', gaProducts[opId]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement