Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import $ from "jquery";
- import GoogleAnalyticsScript from "./analytics";
- const { key, yandexMetrika, template } = window.context;
- export const Analytics = {
- interval: 500,
- tryCount: 3,
- yaCounter: (id) => {
- const yaCounter = window[`yaCounter${yandexMetrika}`];
- if (typeof yaCounter !== "undefined") {
- yaCounter.reachGoal(id);
- } else {
- let tryCount = 0;
- const interval = setInterval(() => {
- const yaCounter = window[`yaCounter${yandexMetrika}`];
- if (typeof yaCounter !== "undefined") {
- clearInterval(interval);
- yaCounter.reachGoal(id);
- }
- if (tryCount === Analytics.tryCount) {
- clearInterval(interval);
- }
- tryCount++;
- }, Analytics.interval);
- }
- },
- googleAnalytics: (method, type, group, name) => {
- if (typeof ga !== "undefined") {
- ga(method, type, group, name);
- } else {
- let tryCount = 0;
- const interval = setInterval(() => {
- if (typeof ga !== "undefined") {
- ga(method, type, group, name);
- clearInterval(interval);
- }
- if (tryCount === Analytics.tryCount) {
- clearInterval(interval);
- }
- }, Analytics.interval);
- }
- },
- roistatGoal: (leadName, text, price) => {
- if (typeof roistatGoal !== "undefined") {
- roistatGoal.reach({
- loadName: leadName,
- text: text,
- price: price
- });
- } else {
- let tryCount = 0;
- const interval = setInterval(() => {
- if (typeof roistatGoal !== "undefined") {
- roistatGoal.reach({
- loadName: leadName,
- text: text,
- price: price
- });
- clearInterval(interval);
- }
- if (tryCount === Analytics.tryCount) {
- clearInterval(interval);
- }
- }, Analytics.interval);
- }
- },
- roistat: (type) => {
- if (typeof roistat !== "undefined") {
- roistat.event.send(type);
- } else {
- let tryCount = 0;
- const interval = setInterval(() => {
- if (typeof roistat !== "undefined") {
- roistat.event.send(type);
- clearInterval(interval);
- }
- if (tryCount === Analytics.tryCount) {
- clearInterval(interval);
- }
- }, Analytics.interval);
- }
- }
- };
- $(document).on('af_complete', function(event,response) {
- if (response.success && !response.form[0].classList.contains('calc-form')){
- Analytics.yaCounter('form');
- Analytics.googleAnalytics('send','event','button','form');
- $(response.form).closest('.modal').modal('hide');
- }
- else if(response.success && response.form[0].classList.contains('calc-form')){
- Analytics.yaCounter('calc-form');
- Analytics.googleAnalytics('send','event','button','calc-form');
- }
- });
- $('.video .player a').one('click', function() {
- Analytics.yaCounter('video');
- Analytics.googleAnalytics('send','event','button','video');
- }
- );
- $('.review .new-player audio').one('play', function(){
- Analytics.yaCounter('audio');
- Analytics.googleAnalytics('send','event','button','audio');
- });
- $("a[href*=tel]").one('click', function(){
- Analytics.yaCounter('phone');
- Analytics.googleAnalytics('send','event','button','phone');
- });
- $(".bg-primary.top a.nav-link.vk").one('click', function(){
- Analytics.yaCounter('klik-vk');
- Analytics.googleAnalytics('send','event','button','klik-vk');
- });
- $('#calcmodal').one('shown.bs.modal', function() {
- Analytics.yaCounter('getPrice');
- Analytics.googleAnalytics('send','event','button','getPrice');
- });
- $('#route').one('shown.bs.modal', function(){
- Analytics.googleAnalytics('send','event','button','howToCome');
- });
- $('.landing a[href^="tel:"]').click(function() {
- Analytics.yaCounter('landingPhone');
- Analytics.googleAnalytics('send','event','button','landingPhone');
- });
- const priceCheck = () => {
- let price = document.querySelector(".landing #pricelist .head");
- if (!price) { return; }
- price = price.getBoundingClientRect().top - window.innerHeight;
- if ( price <= 0 ) {
- Analytics.yaCounter('landingPrice');
- Analytics.googleAnalytics('send','event','scrollEvents','landingPrice');
- if (key == "perm" && template == 53) {
- Analytics.roistatGoal('Достиг прайса на /apple', "", 0);
- Analytics.roistat("to-price-apple");
- }
- window.removeEventListener("scroll", priceCheck);
- }
- };
- const footerCheck = () => {
- let footer = document.querySelector('.landing footer');
- if (!footer) { return; }
- footer = footer.getBoundingClientRect().top - window.innerHeight;
- if ( footer <= 0 ) {
- Analytics.yaCounter('landingFooter');
- Analytics.googleAnalytics('send','event','scrollEvents','landingFooter');
- window.removeEventListener("scroll", footerCheck);
- }
- };
- window.addEventListener("scroll", priceCheck);
- window.addEventListener("scroll", footerCheck);
- window.addEventListener("load", GoogleAnalyticsScript);
- priceCheck();
- footerCheck();
- if (key == "perm" && template == 53) {
- setTimeout(() => {
- Analytics.roistatGoal('Свыше двух минут на сайте', "", 0);
- Analytics.roistat("more-two-min");
- }, 120000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement