From e43e7e2304d0a29a3a75b9020c4fd15066dd73e1 Mon Sep 17 00:00:00 2001 From: captainbeer Date: Wed, 6 Mar 2019 18:34:40 +0200 Subject: [PATCH] -Gtag event sending rebuilt --- frontend/web/js/script.js | 90 ++++++++++++++++++++---------------------------------------------------------------------- 1 file changed, 20 insertions(+), 70 deletions(-) diff --git a/frontend/web/js/script.js b/frontend/web/js/script.js index 43a358b..abd2dd0 100755 --- a/frontend/web/js/script.js +++ b/frontend/web/js/script.js @@ -116,77 +116,27 @@ $( /* нужно для гугл аналитики */ - $(".close, .modal.fade").on('click', function(){ - // $("#feedback-form")['0'].reset(); - $(".send-form").removeAttr("id") - }); $(".press-consultation").on('click',function(){ - // $("#feedback-form")['0'].reset(); - $(".send-form").attr('id', 'consultation'); + gtagEventSender.setState('consultation'); }); $(".press-specialist").on('click',function(){ - // $("#feedback-form")['0'].reset(); - $(".send-form").attr('id', 'specialist'); + gtagEventSender.setState('specialist'); }); $(".press-calculate").on('click',function(){ - // $("#feedback-form")['0'].reset(); - $(".send-form").attr('id', 'calculate'); + gtagEventSender.setState('calculate'); }); $(".press-order").on('click',function(){ - // $("#feedback-form")['0'].reset(); - $(".send-form").attr('id', 'order'); + gtagEventSender.setState('order'); }); $(".press-call").on('click',function(){ - // $("#feedback-form")['0'].reset(); - $(".send-form").attr('id', 'call'); + gtagEventSender.setState('call'); }); $(".press-callback").on('click',function(){ - // $("#feedback-form")['0'].reset(); - $(".send-form").attr('id', 'callback'); + gtagEventSender.setState('callback'); }); $(document).on('click', '.send-form', function() { - var id = $(this).attr('id'); - switch (id) { - case 'consultation' : - gtag('event', 'send', { - 'event_category': 'consultation' - }); - console.log(id); - break; - case 'specialist' : - gtag('event', 'send', { - 'event_category': 'specialist' - }); - console.log(id); - break; - case 'calculate' : - gtag('event', 'send', { - 'event_category': 'calculate' - }); - console.log(id); - break; - case 'order' : - gtag('event', 'send', { - 'event_category': 'order' - }); - console.log(id); - break; - case 'call' : - gtag('event', 'send', { - 'event_category': 'call' - }); - console.log(id); - break; - case 'callback' : - gtag('event', 'send', { - 'event_category': 'callback' - }); - console.log(id); - break; - default: - console.log('Id didn\'t match any case') - } + gtagEventSender.pushEvent(); }); function phoneMask(maskCssSelector) { @@ -205,19 +155,11 @@ $( } } - - - - - - - - $('body').on('click','.cokeis-close',function () { $('.cookie-modal').addClass('hide-bl'); var date = new Date(new Date().getTime() + 48 * 60 * 60 * 1000); document.cookie = "sowCookieModal=1; path=/; expires=" + date.toUTCString(); - }) + }); if($('.home-text-wr').length) { $('.home-text-wr').mCustomScrollbar( @@ -228,10 +170,18 @@ $( ); } + var gtagEventSender = { + state : '' + }; + gtagEventSender.setState = function(newState) { + this.state = newState; + }; - - - - + gtagEventSender.pushEvent = function() { + gtag('event', 'send', { + 'event_category': this.state + }); + console.log(this.state); + } }); \ No newline at end of file -- libgit2 0.21.4