PageSourceSearch

https://flexcode.bg/wp-content/cache/wpfc-minified/76wxepzy/4e3ri.js

js flexcode.bg collected 2026-09-29 18:15:21 UTC 15,720 bytes, 466 lines download raw bytes

1// source --> https://flexcode.bg/wp-content/plugins/enhanced-e-commerce-for-woocommerce-store/public/js/con-gtm-google-analytics.js?ver=7.1.6 
2(function ($) {
3  'use strict';
4  /**
5   * This enables you to define handlers, for when the DOM is ready:
6   * $(function() { });
7   * When the window is loaded:
8   * $( window ).load(function() { }); 
9   */
10})(jQuery);
11
12class TVC_GTM_WP_Enhanced {
13
14  /**
15   * Contact form 7 - formSubmit, Tracks form submissions for Contact Form 7 forms (excluding admin submissions).
16   * Pushes data to the dataLayer for analytics purposes.
17   * 
18   * @param {Event} e The form submit event object.
19   */
20  formsubmit_cf7_tracking(e) {
21    if (this.options.is_admin == true) {
22      return;
23    }
24
25    var form_submit_datalayer = {
26      event: "form_lead_submit",
27      cov_form_name: e.target.ariaLabel,
28      cov_form_type: "CF7 Plugin",
29      cov_form_id: e.detail.contactFormId,
30    };
31    
32    dataLayer.push(form_submit_datalayer);
33  }
34
35  /**
36   * Ninja form - formSubmit, Handles form submission for Ninja Forms with dataLayer push.
37   *
38   * This function is triggered when a Ninja Form is submitted. It checks if the user is in the admin area, and if not, it pushes form submission data to the dataLayer for tracking purposes.
39   *
40   * @param {Event} e The DOM event object for the form submission.
41   * @param {Object} r The response object from the Ninja Forms submission.
42   * @param {number} id The ID of the submitted Ninja Form.
43   * @returns {void}
44   */
45  formsubmit_ninja_tracking(e,r,id) {
46    if (this.options.is_admin == true) {
47      return;
48    }
49    var title = e.target.ariaLabel ? e.target.ariaLabel : r.response.data.settings.title;
50    var form_submit_datalayer = {
51      event: "form_lead_submit",
52      cov_form_name: title,
53      cov_form_type: "Ninja Form Plugin",
54      cov_form_id: r.id,
55    };
56    
57    dataLayer.push(form_submit_datalayer);
58  }
59
60  /**
61   * WpForm & Formidable - FormSubmit, Submits a form using AJAX and pushes data to the dataLayer.
62   *
63   * @param {any[]} fdata The data to be pushed to the dataLayer.
64   * @param {string} is_plugin (optional) A flag indicating if this call originates from a plugin. Defaults to an empty string.
65   */
66  formsubmit_ajax_tracking( fdata = [], is_plugin = '' ) {
67    var postdata = {
68      action: "datalayer_push",
69      nonce: ConvAioGlobal.nonce,
70      is_plugin: is_plugin,
71    };
72
73    if( typeof fdata === 'string' ) {
74      const parts = fdata.split('&');
75      const params = {};
76      for (let i = 0; i < parts.length; i++) {
77        const keyVal = parts[i].split('=');
78        params[decodeURIComponent(keyVal[0])] = decodeURIComponent(keyVal[1] || '');
79      }
80
81      // Formidable plugin related
82      if( 'action' in params && params.action == "frm_entries_create" ) {
83        postdata['form_id'] = params.form_id;
84        postdata['form_action'] = params.action;
85      }
86    }else {
87      // WpForm plugin related
88      if( 'action' in fdata && fdata['action'] == 'wpforms_submit' ) {
89        postdata['form_id'] = fdata['form_id'];
90        postdata['form_action'] = fdata['action'];
91      }
92    }
93
94    jQuery.ajax({
95      type: "POST",
96      url: this.options.tvc_ajax_url,
97      data: postdata,
98      success: function (datalayer) {
99        window.dataLayer = window.dataLayer || [];
100        dataLayer.push(datalayer);
101      }
102    });
103  }
104
105} // End Class::TVC_GTM_WP_Enhanced
106
107class TVC_GTM_Enhanced extends TVC_GTM_WP_Enhanced {
108
109  constructor(options = {}) {
110    super();
111    this.options = {
112      tracking_option: 'UA'
113    };
114    if (options) {
115      Object.assign(this.options, options);
116    }
117  }
118  singleProductaddToCartEventBindings(variations_data, product_detail_addtocart_selector) {
119    var single_btn = "";
120    if (product_detail_addtocart_selector != "") {
121      single_btn = document.querySelectorAll("button[class*='btn-buy-shop'],button[class*='single_add_to_cart_button'], button[class*='add_to_cart']" + product_detail_addtocart_selector);
122    } else {
123      single_btn = document.querySelectorAll("button[class*='btn-buy-shop'],button[class*='single_add_to_cart_button'], button[class*='add_to_cart']");
124    }
125    if (single_btn.length > 0) {
126      single_btn.forEach((aCartBut) => {
127        aCartBut.addEventListener("click", () => this.add_to_cart_click(variations_data, "Product Pages"));
128      });
129    }
130  }
131  ListProductaddToCartEventBindings() {
132    var elements = "";
133    elements = document.querySelectorAll("a[href*=add-to-cart]");
134    if (elements.length > 0) {
135      for (var i = 0; i < elements.length; i++) {
136        if (elements[i]) {
137          elements[i].addEventListener("click", () => this.list_add_to_cart_click());
138        }
139      }
140    }
141  }
142  ListProductSelectItemEventBindings() {
143    var elements = "";
144    elements = document.querySelectorAll("li.product a:not([href*=add-to-cart],.product_type_variable, .product_type_grouped");
145    if (elements.length > 0) {
146      for (var i = 0; i < elements.length; i++) {
147        if (elements[i]) {
148          elements[i].addEventListener("click", () => this.list_select_item_click());
149        }
150      }
151    }
152  }
153  RemoveItemCartEventBindings() {
154    var elements = "";
155    elements = document.querySelectorAll("a[href*=\"?remove_item\"]");
156    if (elements.length > 0) {
157      for (var i = 0; i < elements.length; i++) {
158        if (elements[i]) {
159          elements[i].addEventListener("click", () => this.remove_item_click());
160        }
161      }
162    }
163  }
164  /*
165   * check remarketing option 
166   */
167  is_add_remarketing_tags() {
168    if (this.options.is_admin == false && this.options.ads_tracking_id != "" && (this.options.remarketing_tags == 1 || this.options.dynamic_remarketing_tags == 1)) {
169      return true;
170    } else {
171      return false;
172    }
173  }
174
175  get_variation_data_by_id(variations_data, variation_id) {
176    var r_val = "";
177    if (variations_data.available_variations.length > 0) {
178      variations_data.available_variations.forEach((element, index) => {
179        if (element.variation_id == variation_id) {
180          r_val = element;
181        }
182      });
183      return r_val;
184    }
185  }
186  get_variation_attribute_name(p_attributes) {
187    var p_v_title = "";
188    if (Object.keys(p_attributes).length > 0) {
189      for (var index in p_attributes) {
190        p_v_title += (p_v_title == "") ? p_attributes[index] : ' | ' + p_attributes[index];
191      }
192      return p_v_title;
193    }
194  }
195  get_event_data_layer(event_name) {
196    if (event_name != "") {
197      if (Object.keys(dataLayer).length > 0) {
198        for (var dataLayer_item in dataLayer) {
199          event = dataLayer[dataLayer_item].event;
200          if (event_name == event) {
201            return dataLayer[dataLayer_item];
202          }
203        }
204      }
205    }
206  }
207  get_product_from_product_list(product_id) {
208    if (product_id != "") {
209      if (Object.keys(conProductList).length > 0) {
210        for (var dataLayer_item in conProductList[0]) {
211          if (conProductList[0][dataLayer_item].hasOwnProperty('id')) {
212            var id = conProductList[0][dataLayer_item].id;
213            if (product_id == id) {
214              return conProductList[0][dataLayer_item];
215            }
216          }
217        }
218      }
219    }
220  }
221  get_product_from_product_list_by_url(prod_obj, key, product_url) {
222    if (product_url != "") {
223      if (Object.keys(prod_obj).length > 0) {
224        for (var dataLayer_item in prod_obj[0]) {
225          if (prod_obj[0][dataLayer_item].hasOwnProperty(key)) {
226            var map_val = prod_obj[0][dataLayer_item][key];
227            if (product_url == map_val) {
228              return prod_obj[0][dataLayer_item];
229            }
230          }
231        }
232      }
233    }
234  }
235  list_select_item_click() {
236    var this_var = event.currentTarget;
237    var href = this_var.getAttribute('href');
238    var item = this.get_product_from_product_list_by_url(conProductList, 'productlink', href);
239    var add_to_cart_datalayer = {
240      event: "select_item",
241      ecommerce: {
242        items: [
243          {
244            affiliation: this.options.affiliation,
245            item_id: item.id,
246            item_name: item.name,
247            currency: this.options.currency,
248            item_category: item.category,
249            price: item.price,
250            quantity: 1
251          }]
252      }
253    };
254    dataLayer.push(add_to_cart_datalayer);
255  }
256  remove_item_click(this_var) {
257    var href = this_var.getAttribute('href');
258    if (href) {
259      var item = this.get_product_from_product_list_by_url(conCarttList, 'remove_cart_link', href);
260
261      var ecomval = (item.price * item.quantity).toFixed(2);
262
263      var add_to_cart_datalayer = {
264        event: "remove_from_cart",
265        ecommerce: {
266          currency: this.options.currency,
267          value: parseFloat(ecomval),
268          items: [
269            {
270              affiliation: this.options.affiliation,
271              item_id: item.id,
272              item_name: item.name,
273              currency: this.options.currency,
274              item_category: item.category,
275              price: item.price,
276              quantity: item.quantity
277
278            }]
279        }
280      };
281      dataLayer.push(add_to_cart_datalayer);
282    }
283
284  }
285  list_add_to_cart_click() {
286    var this_var = event.currentTarget;
287    var href = this_var.getAttribute('href');
288    var product_id = this.getParameterByName("add-to-cart", href);
289    var item = this.get_product_from_product_list(product_id);
290    var quantity = 1;
291    if (jQuery(this_var).attr("data-quantity")) {
292      quantity = jQuery(this_var).attr("data-quantity");
293    }
294    var add_to_cart_datalayer = {
295      event: "add_to_cart",
296      ecommerce: {
297        currency: this.options.currency,
298        value: item.price,
299        items: [
300          {
301            affiliation: this.options.affiliation,
302            item_id: item.id,
303            item_name: item.name,
304            currency: this.options.currency,
305            item_category: item.category,
306            price: item.price,
307            quantity: parseInt(quantity)
308          }]
309      }
310    };
311
312    if (this.options.fb_pixel_id != undefined && this.options.fb_pixel_id != null && this.options.fb_pixel_id != "") {
313      add_to_cart_datalayer.fb_event_id = this.options.fb_event_id + 'p' 
313+ item.id;
314    }
315
316    dataLayer.push(add_to_cart_datalayer);
317  }
318  getParameterByName(name, url = window.location.href) {
319    name = name.replace(/[\[\]]/g, '\\$&');
320    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
321      results = regex.exec(url);
322    if (!results) return null;
323    if (!results[2]) return '';
324    return decodeURIComponent(results[2].replace(/\+/g, ' '));
325  }
326  /*
327   * below code run while add to cart on product page. 
328   * ( Event=>  add_to_cart)
329   */
330  add_to_cart_click(variations_data, page_type = "Product Pages") {
331    var this_var = event.currentTarget;
332    var item_dataLayer = this.get_event_data_layer("view_item");
333    if (this.options.is_admin == true) {
334      return;
335    }
336    if (Object.keys(item_dataLayer.ecommerce.items[0]).length > 0) {
337      var item = item_dataLayer.ecommerce.items[0];
338      var variation_attribute_name = "";
339      var vari_data = "";
340      var variation_id = "";
341      var variation_id_obj = document.getElementsByClassName("variation_id");
342      if (variation_id_obj.length > 0) {
343        variation_id = document.getElementsByClassName("variation_id")[0].value;
344      }
345      var varPrice = item.price;
346      if (variation_id != "") {
347        vari_data = this.get_variation_data_by_id(variations_data, variation_id);
348        var p_attributes = vari_data.attributes;
349        if (Object.keys(p_attributes).length > 0) {
350          variation_attribute_name = this.get_variation_attribute_name(p_attributes);
351        }
352        if (vari_data.display_price) {
353          varPrice = vari_data.display_price;
354        } else if (vari_data.display_regular_price) {
355          varPrice = vari_data.display_regular_price;
356        }
357      }
358
359      var ecomval = (item.price * jQuery(this_var).parent().find("input[name=quantity]").val()).toFixed(2)
360
361      var add_to_cart_datalayer = {
362        event: "add_to_cart",
363        ecommerce: {
364          currency: this.options.currency,
365          value: parseFloat(ecomval),
366          items: [
367            {
368              affiliation: item.affiliation,
369              item_id: item.item_id,
370              item_name: item.item_name,
371              currency: item.currency,
372              item_category: item.item_category,
373              price: varPrice,
374              quantity: parseInt(jQuery(this_var).parent().find("input[name=quantity]").val()),
375              item_variant: variation_attribute_name
376
377            }]
378        }
379      };
380      if (this.options.fb_pixel_id != undefined && this.options.fb_pixel_id != null && this.options.fb_pixel_id != "") {
381        add_to_cart_datalayer.fb_event_id = this.options.fb_event_id + 'p' + item.item_id;
382      }
383      dataLayer.push(add_to_cart_datalayer);
384
385    }
386  }
387  /*
388  *
389  */
390  checkout_step_2_tracking() {
391    var item_dataLayer = this.get_event_data_layer("begin_checkout");
392    var item_dataLayer_asi = this.get_event_data_layer("add_shipping_info");
393    if (item_dataLayer_asi == undefined) {
394      if (this.options.is_admin == true) {
395        return;
396      }
397      if (Object.keys(item_dataLayer.ecommerce.items[0]).length > 0) {
398        var checkout_step_2_datalayer = {
399          event: "add_shipping_info",
400          ecommerce: {
401            currency: this.options.currency,
402            value: item_dataLayer.ecommerce.value,
403            items: item_dataLayer.ecommerce.items
404          }
405        };
406        dataLayer.push(checkout_step_2_datalayer);
407      }
408    }
409  }
410  checkout_step_3_tracking() {
411    var item_dataLayer = this.get_event_data_layer("begin_checkout");
412    if (this.options.is_admin == true) {
413      return;
414    }
415    if (Object.keys(item_dataLayer.ecommerce.items[0]).length > 0) {
416      var checkout_step_3_datalayer = {
417        event: "add_payment_info",
418        ecommerce: {
419          currency: this.options.currency,
420          value: item_dataLayer.ecommerce.value,
421          items: item_dataLayer.ecommerce.items
422        }
423      };
424      dataLayer.push(checkout_step_3_datalayer);
425    }
426  }
427
428  getCurrentTime() {
429    if (!Date.now) {
430      return new Date().getTime();
431    } else {
432      //Math.floor(Date.now() / 1000)
433      return Date.now();
434    }
435  }
436  getClientId() {
437    let client_id = this.getCookie("_ga");
438    if (client_id != null && client_id != "") {
439      return client_id;
440    } else {
441      return;
442    }
443  }
444  setCookie(name, value, days) {
445    var expires = "";
446    if (days) {
447      var date = new Date();
448      date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
449      expires = "; expires=" + date.toUTCString();
450    }
451    document.cookie = name + "=" + (value || "") + expires + "; path=/";
452  }
453  getCookie(name) {
454    var nameEQ = name + "=";
455    var ca = document.cookie.split(";");
456    for (var i = 0; i < ca.length; i++) {
457      var c = ca[i];
458      while (c.charAt(0) == " ") c = c.substring(1, c.length);
459      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
460    }
461    return null;
462  }
463  eraseCookie(name) {
464    document.cookie = name + "=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";
465  }
466};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.