Commit e43e7e2304d0a29a3a75b9020c4fd15066dd73e1

Authored by Alexey Boroda
1 parent ba6b0548

-Gtag event sending rebuilt

Showing 1 changed file with 20 additions and 70 deletions   Show diff stats
frontend/web/js/script.js
... ... @@ -116,77 +116,27 @@ $(
116 116  
117 117 /* нужно для гугл аналитики */
118 118  
119   - $(".close, .modal.fade").on('click', function(){
120   - // $("#feedback-form")['0'].reset();
121   - $(".send-form").removeAttr("id")
122   - });
123 119 $(".press-consultation").on('click',function(){
124   - // $("#feedback-form")['0'].reset();
125   - $(".send-form").attr('id', 'consultation');
  120 + gtagEventSender.setState('consultation');
126 121 });
127 122 $(".press-specialist").on('click',function(){
128   - // $("#feedback-form")['0'].reset();
129   - $(".send-form").attr('id', 'specialist');
  123 + gtagEventSender.setState('specialist');
130 124 });
131 125 $(".press-calculate").on('click',function(){
132   - // $("#feedback-form")['0'].reset();
133   - $(".send-form").attr('id', 'calculate');
  126 + gtagEventSender.setState('calculate');
134 127 });
135 128 $(".press-order").on('click',function(){
136   - // $("#feedback-form")['0'].reset();
137   - $(".send-form").attr('id', 'order');
  129 + gtagEventSender.setState('order');
138 130 });
139 131 $(".press-call").on('click',function(){
140   - // $("#feedback-form")['0'].reset();
141   - $(".send-form").attr('id', 'call');
  132 + gtagEventSender.setState('call');
142 133 });
143 134 $(".press-callback").on('click',function(){
144   - // $("#feedback-form")['0'].reset();
145   - $(".send-form").attr('id', 'callback');
  135 + gtagEventSender.setState('callback');
146 136 });
147 137  
148 138 $(document).on('click', '.send-form', function() {
149   - var id = $(this).attr('id');
150   - switch (id) {
151   - case 'consultation' :
152   - gtag('event', 'send', {
153   - 'event_category': 'consultation'
154   - });
155   - console.log(id);
156   - break;
157   - case 'specialist' :
158   - gtag('event', 'send', {
159   - 'event_category': 'specialist'
160   - });
161   - console.log(id);
162   - break;
163   - case 'calculate' :
164   - gtag('event', 'send', {
165   - 'event_category': 'calculate'
166   - });
167   - console.log(id);
168   - break;
169   - case 'order' :
170   - gtag('event', 'send', {
171   - 'event_category': 'order'
172   - });
173   - console.log(id);
174   - break;
175   - case 'call' :
176   - gtag('event', 'send', {
177   - 'event_category': 'call'
178   - });
179   - console.log(id);
180   - break;
181   - case 'callback' :
182   - gtag('event', 'send', {
183   - 'event_category': 'callback'
184   - });
185   - console.log(id);
186   - break;
187   - default:
188   - console.log('Id didn\'t match any case')
189   - }
  139 + gtagEventSender.pushEvent();
190 140 });
191 141  
192 142 function phoneMask(maskCssSelector) {
... ... @@ -205,19 +155,11 @@ $(
205 155 }
206 156 }
207 157  
208   -
209   -
210   -
211   -
212   -
213   -
214   -
215   -
216 158 $('body').on('click','.cokeis-close',function () {
217 159 $('.cookie-modal').addClass('hide-bl');
218 160 var date = new Date(new Date().getTime() + 48 * 60 * 60 * 1000);
219 161 document.cookie = "sowCookieModal=1; path=/; expires=" + date.toUTCString();
220   - })
  162 + });
221 163  
222 164 if($('.home-text-wr').length) {
223 165 $('.home-text-wr').mCustomScrollbar(
... ... @@ -228,10 +170,18 @@ $(
228 170 );
229 171 }
230 172  
  173 + var gtagEventSender = {
  174 + state : ''
  175 + };
231 176  
  177 + gtagEventSender.setState = function(newState) {
  178 + this.state = newState;
  179 + };
232 180  
233   -
234   -
235   -
236   -
  181 + gtagEventSender.pushEvent = function() {
  182 + gtag('event', 'send', {
  183 + 'event_category': this.state
  184 + });
  185 + console.log(this.state);
  186 + }
237 187 });
238 188 \ No newline at end of file
... ...