Advertisement
Dzhubal

Untitled

Dec 11th, 2020 (edited)
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. document.addEventListener('mousedown', function(e) {
  2.     if (e.target.matches('#getExempleModal form input.btn.btn-default')) {
  3.         var form = getClosest(e.target, 'form'),
  4.             name = form.querySelector('input[name="UNAME"]').value,
  5.             email = form.querySelector('input[name="UEMAIL"]').value,
  6.             company = form.querySelector('input[name="UCOMPANY"]').value,
  7.             comment = form.querySelector('textarea[name="UMESSAGE"]').value,
  8.             phone = form.querySelector('input[name="UPHONE"]').value,
  9.             messageText = '\
  10. '+comment+'<br>\
  11. Имя: '+name+'<br>\
  12. Email: '+email+'<br>\
  13. Телефон: '+phone+'<br>\
  14. Компания: '+company+'',
  15.             http = new XMLHttpRequest(),
  16.             url = 'https://api.carrotquest.io/v1/users/' + carrotquest.data.user.id + '/startconversation',
  17.             params = 'auth_token='+carrotquest.data.auth_token+'&body='+messageText;
  18.         if (document.querySelector('.b-modal-form h4').innerHTML.indexOf('Цена') >-1 ||
  19.             document.querySelector('.b-modal-form h4').innerHTML.indexOf('цену') >-1) {
  20.             carrotquest.track('Заполнена форма "Узнать цену"');
  21.             var productName = document.querySelector('.col-xs-6 h2').textContent.trim();
  22.             var fileAttached = document.querySelectorAll('.b-file-input__item').length>0?', Файл: приложен. Проверять через почту':'';
  23.             messageText = '\
  24. Хочу узнать цену на продукт. Продукт: '+productName+',<br>\
  25. Имя: '+name+',<br>\
  26. Email: '+email+',<br>\
  27. Телефон: '+phone+',<br>\
  28. Компания: '+company+',<br>\
  29. Сообщение: '+comment+' '+fileAttached,
  30.             params = 'auth_token='+carrotquest.data.auth_token+'&body='+messageText;
  31.         } else if (document.querySelector('.b-modal-form h4').innerHTML.indexOf('Получить на тестирование') >-1) {
  32.             carrotquest.track('Заполнена форма "Получить образец"')
  33.         } else if (document.querySelector('.b-modal-form h4').innerHTML.indexOf('Получить демонстрацию') >-1) {
  34.             carrotquest.track('Заполнена форма "Получить демонстрацию"')
  35.         }
  36.         http.open('POST', url, true);
  37.         http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  38.         http.send(params);
  39.         carrotquest.identify([
  40.             {op: 'update_or_create', key: '$name', value: name},
  41.             {op: 'update_or_create', key: '$email', value: email},
  42.             {op: 'update_or_create', key: 'Компания', value: company},
  43.             {op: 'update_or_create', key: 'Сообщение из формы', value: comment},
  44.             {op: 'update_or_create', key: '$phone', value: phone}
  45.         ]);
  46.     };
  47. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement