Advertisement
Guest User

Untitled

a guest
May 21st, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import $ from "jquery";
  2. import GoogleAnalyticsScript from "./analytics";
  3.  
  4. const { key, yandexMetrika, template } = window.context;
  5.  
  6. export const Analytics  = {
  7.     interval: 500,
  8.     tryCount: 3,
  9.     yaCounter: (id) => {
  10.         const yaCounter = window[`yaCounter${yandexMetrika}`];
  11.  
  12.         if (typeof yaCounter !== "undefined") {
  13.             yaCounter.reachGoal(id);
  14.         } else {
  15.             let tryCount = 0;
  16.  
  17.             const interval = setInterval(() => {
  18.                 const yaCounter = window[`yaCounter${yandexMetrika}`];
  19.  
  20.                 if (typeof yaCounter !== "undefined") {
  21.                     clearInterval(interval);
  22.                     yaCounter.reachGoal(id);
  23.                 }
  24.                 if (tryCount === Analytics.tryCount) {
  25.                     clearInterval(interval);
  26.                 }
  27.  
  28.                 tryCount++;
  29.             }, Analytics.interval);
  30.         }
  31.     },
  32.     googleAnalytics: (method, type, group, name) => {
  33.         if (typeof ga !== "undefined") {
  34.             ga(method, type, group, name);
  35.         } else {
  36.             let tryCount = 0;
  37.  
  38.             const interval = setInterval(() => {
  39.                 if (typeof ga !== "undefined") {
  40.                     ga(method, type, group, name);
  41.                     clearInterval(interval);
  42.                 }
  43.                 if (tryCount === Analytics.tryCount) {
  44.                     clearInterval(interval);
  45.                 }
  46.  
  47.             }, Analytics.interval);
  48.         }
  49.     },
  50.     roistatGoal: (leadName, text, price) => {
  51.         if (typeof roistatGoal !== "undefined") {
  52.             roistatGoal.reach({
  53.                 loadName: leadName,
  54.                 text: text,
  55.                 price: price
  56.             });
  57.         } else {
  58.             let tryCount = 0;
  59.  
  60.             const interval = setInterval(() => {
  61.                 if (typeof roistatGoal !== "undefined") {
  62.                     roistatGoal.reach({
  63.                         loadName: leadName,
  64.                         text: text,
  65.                         price: price
  66.                     });
  67.                     clearInterval(interval);
  68.                 }
  69.                 if (tryCount === Analytics.tryCount) {
  70.                     clearInterval(interval);
  71.                 }
  72.  
  73.             }, Analytics.interval);
  74.         }
  75.     },
  76.     roistat: (type) => {
  77.         if (typeof roistat !== "undefined") {
  78.             roistat.event.send(type);
  79.         } else {
  80.             let tryCount = 0;
  81.  
  82.             const interval = setInterval(() => {
  83.                 if (typeof roistat !== "undefined") {
  84.                     roistat.event.send(type);
  85.                     clearInterval(interval);
  86.                 }
  87.                 if (tryCount === Analytics.tryCount) {
  88.                     clearInterval(interval);
  89.                 }
  90.  
  91.             }, Analytics.interval);
  92.         }
  93.     }
  94. };
  95.  
  96. $(document).on('af_complete', function(event,response) {
  97.     if (response.success && !response.form[0].classList.contains('calc-form')){
  98.         Analytics.yaCounter('form');
  99.         Analytics.googleAnalytics('send','event','button','form');
  100.         $(response.form).closest('.modal').modal('hide');
  101.     }
  102.     else if(response.success && response.form[0].classList.contains('calc-form')){
  103.         Analytics.yaCounter('calc-form');
  104.         Analytics.googleAnalytics('send','event','button','calc-form');
  105.     }
  106. });
  107.  
  108. $('.video .player a').one('click', function() {
  109.         Analytics.yaCounter('video');
  110.         Analytics.googleAnalytics('send','event','button','video');
  111.     }
  112. );
  113.  
  114. $('.review .new-player audio').one('play', function(){
  115.     Analytics.yaCounter('audio');
  116.     Analytics.googleAnalytics('send','event','button','audio');
  117. });
  118.  
  119. $("a[href*=tel]").one('click', function(){
  120.     Analytics.yaCounter('phone');
  121.     Analytics.googleAnalytics('send','event','button','phone');
  122. });
  123.  
  124. $(".bg-primary.top a.nav-link.vk").one('click', function(){
  125.     Analytics.yaCounter('klik-vk');
  126.     Analytics.googleAnalytics('send','event','button','klik-vk');
  127. });
  128.  
  129. $('#calcmodal').one('shown.bs.modal', function() {
  130.     Analytics.yaCounter('getPrice');
  131.     Analytics.googleAnalytics('send','event','button','getPrice');
  132. });
  133.  
  134. $('#route').one('shown.bs.modal', function(){
  135.     Analytics.googleAnalytics('send','event','button','howToCome');
  136. });
  137.  
  138. $('.landing a[href^="tel:"]').click(function() {
  139.     Analytics.yaCounter('landingPhone');
  140.     Analytics.googleAnalytics('send','event','button','landingPhone');
  141. });
  142.  
  143. const priceCheck = () => {
  144.     let price = document.querySelector(".landing #pricelist .head");
  145.  
  146.     if (!price) { return; }
  147.  
  148.     price = price.getBoundingClientRect().top - window.innerHeight;
  149.  
  150.     if ( price <= 0 ) {
  151.         Analytics.yaCounter('landingPrice');
  152.         Analytics.googleAnalytics('send','event','scrollEvents','landingPrice');
  153.  
  154.         if (key == "perm" && template == 53) {
  155.             Analytics.roistatGoal('Достиг прайса на /apple', "", 0);
  156.             Analytics.roistat("to-price-apple");
  157.         }
  158.  
  159.         window.removeEventListener("scroll", priceCheck);
  160.     }
  161. };
  162.  
  163. const footerCheck = () => {
  164.     let footer = document.querySelector('.landing footer');
  165.  
  166.     if (!footer) { return; }
  167.  
  168.     footer = footer.getBoundingClientRect().top - window.innerHeight;
  169.  
  170.     if ( footer <= 0 ) {
  171.         Analytics.yaCounter('landingFooter');
  172.         Analytics.googleAnalytics('send','event','scrollEvents','landingFooter');
  173.         window.removeEventListener("scroll", footerCheck);
  174.     }
  175. };
  176.  
  177. window.addEventListener("scroll", priceCheck);
  178. window.addEventListener("scroll", footerCheck);
  179. window.addEventListener("load", GoogleAnalyticsScript);
  180.  
  181. priceCheck();
  182. footerCheck();
  183.  
  184. if (key == "perm" && template == 53) {
  185.     setTimeout(() => {
  186.         Analytics.roistatGoal('Свыше двух минут на сайте', "", 0);
  187.         Analytics.roistat("more-two-min");
  188.     }, 120000);
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement