Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1.  
  2. //события для js поп-апов
  3. (function() {
  4. Element.prototype.remove = function() {
  5. this.parentElement.removeChild(this);
  6. };
  7. NodeList.prototype.remove = HTMLCollection.prototype.remove = function() {
  8. for (var i = this.length - 1; i >= 0; i--) {
  9. if (this[i] && this[i].parentElement) {
  10. this[i].parentElement.removeChild(this[i]);
  11. }
  12. }
  13. };
  14. window.addEventListener('message', function(e) {
  15. if (e.data.command == 'carrotquest.closePopup') {
  16. document.getElementById('carrot_frame_' + e.data.id).remove();
  17. carrotquest.identify([{ op: 'update_or_create', key: 'popup', value: 'closed' }]);
  18. carrotquest.track('Закрыл поп-ап', {
  19. 'id': e.data.id
  20. });
  21. };
  22. if (e.data.command == 'carrotquest.resizeFrame') {
  23. document.getElementById('carrot_frame_' + e.data.id).style.height = e.data.height + 'px';
  24. };
  25. });
  26. window.addEventListener('resize', function(event) {
  27. if (document.carrot_frame) {
  28. document.querySelector('iframe[name="carrot_frame"]').contentWindow.carrotquest.resizeFrame();
  29. };
  30. });
  31. }());
  32.  
  33. //Попытка ухода с сайта
  34. (function() {
  35. init();
  36. function init() {
  37. setTimeout(addMouseout, 5000);
  38. };
  39. function addMouseout() {
  40. document.addEventListener('mouseout', mouseout);
  41. };
  42. function mouseout(e) {
  43. if (Math.round(e.x) >= 0 && Math.round(e.y) <= 0) {
  44. carrotquest.track('Попытка ухода с сайта');
  45. deleteEvent();
  46. setTimeout(addMouseout, 10000);
  47. }
  48. };
  49. function deleteEvent() {
  50. document.removeEventListener('mouseout', mouseout);
  51. };
  52. }());
  53.  
  54. //Определяем есть ли поп-ап на странице
  55. if ($('iframe[id*="carrot_frame"]').length > 0) {
  56. carrotquest.identify([{op: 'update_or_create', key: 'popup', value: 'opened'}]);
  57. }
  58. else {
  59. carrotquest.identify([{op: 'update_or_create', key: 'popup', value: 'closed'}]);
  60. };
  61.  
  62. carrotquest.identify([{op: 'update_or_create', key: 'Последняя посещенная страница', value: location.href}]);
  63.  
  64. function getLocalDay(date) {
  65. var day = date.getDay();
  66. if (day == 0) {
  67. day = 7;
  68. }
  69. return day;
  70. }
  71.  
  72. //запись текущего дня недели в свойство пользователя
  73. var date = new Date();
  74. var currentDay = getLocalDay(date);
  75. carrotquest.identify([{op: 'update_or_create', key: 'Текущий день недели', value: currentDay}]);
  76.  
  77. //запись свойства "Скролл главной страницы до середины" и "Скролл главной страницы до конца"
  78. if (location.href == 'https://kuzmichnatali.ru/') {
  79. sessionStorage['isScrollMiddle'] = false;
  80. $(window).on('scroll', function() {
  81. if ($(window).scrollTop() >= ($(document).height() - $(window).height())*0.5) {
  82. if (sessionStorage['isScrollMiddle'] == 'false') {
  83. carrotquest.track('Скролл главной страницы до середины');
  84. sessionStorage['isScrollMiddle'] = true;
  85. };
  86. };
  87. });
  88.  
  89. sessionStorage['isScrollEnd'] = false;
  90. $(window).on('scroll', function() {
  91. if ($(window).scrollTop() >= $(document).height() - $(window).height() - 100) {
  92. if (sessionStorage['isScrollEnd'] == 'false') {
  93. carrotquest.track('Скролл главной страницы до конца');
  94. sessionStorage['isScrollEnd'] = true;
  95. };
  96. };
  97. });
  98. }
  99.  
  100. //Клики по элементам
  101. $(document).on('click', '#menu a[href="/courses"]', function() {
  102. carrotquest.track('Клик – Курсы');
  103. });
  104.  
  105. $(document).on('click', '#menu a[href="/about"]', function() {
  106. carrotquest.track('Клик – Обо мне');
  107. });
  108.  
  109. $(document).on('click', '#menu a[href="/faq"]', function() {
  110. carrotquest.track('Клик – Частые вопросы');
  111. });
  112.  
  113. $(document).on('click', '.section_1 .start_btn', function() {
  114. carrotquest.track('Клик – Начать');
  115. });
  116.  
  117. $(document).on('click', '.section_3 .start_btn', function() {
  118. carrotquest.track('Клик – Хочу');
  119. });
  120.  
  121. $('.section_6 a.start_btn').eq(0).on('click', function() {
  122. carrotquest.track('Клик – Купить в Лабиринте');
  123. });
  124.  
  125. $('.section_6 a.start_btn').eq(1).on('click', function() {
  126. carrotquest.track('Клик – Купить на Book24');
  127. });
  128.  
  129. $(document).on('click', '.cabinet', function() {
  130. carrotquest.track('Клик – Личный кабинет ');
  131. });
  132.  
  133. //Email
  134. $(document).on('blur', 'input[type="email"]', function() {
  135. carrotquest.identify([{op: 'update_or_create', key: '$email', value: $(this).val()}]);
  136. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement