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