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", () => this.add_to_cart_click(variations_data, "Product Pages")); 127 }); 128 } 129 } 130 ListProductaddToCartEventBindings() { 131 var elements = ""; 132 elements = document.querySelectorAll("a[href*=add-to-cart]"); 133 if (elements.length > 0) { 134 for (var i = 0; i < elements.length; i++) { 135 if (elements[i]) { 136 elements[i].addEventListener("click", () => this.list_add_to_cart_click()); 137 } 138 } 139 } 140 } 141 ListProductSelectItemEventBindings() { 142 var elements = ""; 143 elements = document.querySelectorAll("li.product a:not([href*=add-to-cart],.product_type_variable, .product_type_grouped"); 144 if (elements.length > 0) { 145 for (var i = 0; i < elements.length; i++) { 146 if (elements[i]) { 147 elements[i].addEventListener("click", () => this.list_select_item_click()); 148 } 149 } 150 } 151 } 152 RemoveItemCartEventBindings() { 153 var elements = ""; 154 elements = document.querySelectorAll("a[href*=\"?remove_item\"]"); 155 if (elements.length > 0) { 156 for (var i = 0; i < elements.length; i++) { 157 if (elements[i]) { 158 elements[i].addEventListener("click", () => this.remove_item_click()); 159 } 160 } 161 } 162 } 163 /* 164 * check remarketing option 165 */ 166 is_add_remarketing_tags() { 167 if (this.options.is_admin == false && this.options.ads_tracking_id != "" && (this.options.remarketing_tags == 1 || this.options.dynamic_remarketing_tags == 1)) { 168 return true; 169 } else { 170 return false; 171 } 172 } 173 174 get_variation_data_by_id(variations_data, variation_id) { 175 var r_val = ""; 176 if (variations_data.available_variations.length > 0) { 177 variations_data.available_variations.forEach((element, index) => { 178 if (element.variation_id == variation_id) { 179 r_val = element; 180 } 181 }); 182 return r_val; 183 } 184 } 185 get_variation_attribute_name(p_attributes) { 186 var p_v_title = ""; 187 if (Object.keys(p_attributes).length > 0) { 188 for (var index in p_attributes) { 189 p_v_title += (p_v_title == "") ? p_attributes[index] : ' | ' + p_attributes[index]; 190 } 191 return p_v_title; 192 } 193 } 194 get_event_data_layer(event_name) { 195 if (event_name != "") { 196 if (Object.keys(dataLayer).length > 0) { 197 for (var dataLayer_item in dataLayer) { 198 event = dataLayer[dataLayer_item].event; 199 if (event_name == event) { 200 return dataLayer[dataLayer_item]; 201 } 202 } 203 } 204 } 205 } 206 get_product_from_product_list(product_id) { 207 if (product_id != "") { 208 if (Object.keys(conProductList).length > 0) { 209 for (var dataLayer_item in conProductList[0]) { 210 if (conProductList[0][dataLayer_item].hasOwnProperty('id')) { 211 var id = conProductList[0][dataLayer_item].id; 212 if (product_id == id) { 213 return conProductList[0][dataLayer_item]; 214 } 215 } 216 } 217 } 218 } 219 } 220 get_product_from_product_list_by_url(prod_obj, key, product_url) { 221 if (product_url != "") { 222 if (Object.keys(prod_obj).length > 0) { 223 for (var dataLayer_item in prod_obj[0]) { 224 if (prod_obj[0][dataLayer_item].hasOwnProperty(key)) { 225 var map_val = prod_obj[0][dataLayer_item][key]; 226 if (product_url == map_val) { 227 return prod_obj[0][dataLayer_item]; 228 } 229 } 230 } 231 } 232 } 233 } 234 list_select_item_click() { 235 var this_var = event.currentTarget; 236 var href = this_var.getAttribute('href'); 237 var item = this.get_product_from_product_list_by_url(conProductList, 'productlink', href); 238 var add_to_cart_datalayer = { 239 event: "select_item", 240 ecommerce: { 241 items: [ 242 { 243 affiliation: this.options.affiliation, 244 item_id: item.id, 245 item_name: item.name, 246 currency: this.options.currency, 247 item_category: item.category, 248 price: item.price, 249 quantity: 1 250 }] 251 } 252 }; 253 dataLayer.push(add_to_cart_datalayer); 254 } 255 remove_item_click(this_var) { 256 var href = this_var.getAttribute('href'); 257 if (href) { 258 var item = this.get_product_from_product_list_by_url(conCarttList, 'remove_cart_link', href); 259 260 var ecomval = (item.price * item.quantity).toFixed(2); 261 262 var add_to_cart_datalayer = { 263 event: "remove_from_cart", 264 ecommerce: { 265 currency: this.options.currency, 266 value: parseFloat(ecomval), 267 items: [ 268 { 269 affiliation: this.options.affiliation, 270 item_id: item.id, 271 item_name: item.name, 272 currency: this.options.currency, 273 item_category: item.category, 274 price: item.price, 275 quantity: item.quantity 276 277 }] 278 } 279 }; 280 dataLayer.push(add_to_cart_datalayer); 281 } 282 283 } 284 list_add_to_cart_click() { 285 var this_var = event.currentTarget; 286 var href = this_var.getAttribute('href'); 287 var product_id = this.getParameterByName("add-to-cart", href); 288 var item = this.get_product_from_product_list(product_id); 289 var quantity = 1; 290 if (jQuery(this_var).attr("data-quantity")) { 291 quantity = jQuery(this_var).attr("data-quantity"); 292 } 293 var add_to_cart_datalayer = { 294 event: "add_to_cart", 295 ecommerce: { 296 currency: this.options.currency, 297 value: item.price, 298 items: [ 299 { 300 affiliation: this.options.affiliation, 301 item_id: item.id, 302 item_name: item.name, 303 currency: this.options.currency, 304 item_category: item.category, 305 price: item.price, 306 quantity: parseInt(quantity) 307 }] 308 } 309 }; 310 311 if (this.options.fb_pixel_id != undefined && this.options.fb_pixel_id != null && this.options.fb_pixel_id != "") { 312 add_to_cart_datalayer.fb_event_id = this.options.fb_event_id + 'p'
312+ item.id; 313 } 314 315 dataLayer.push(add_to_cart_datalayer); 316 } 317 getParameterByName(name, url = window.location.href) { 318 name = name.replace(/[\[\]]/g, '\\$&'); 319 var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), 320 results = regex.exec(url); 321 if (!results) return null; 322 if (!results[2]) return ''; 323 return decodeURIComponent(results[2].replace(/\+/g, ' ')); 324 } 325 /* 326 * below code run while add to cart on product page. 327 * ( Event=> add_to_cart) 328 */ 329 add_to_cart_click(variations_data, page_type = "Product Pages") { 330 var this_var = event.currentTarget; 331 var item_dataLayer = this.get_event_data_layer("view_item"); 332 if (this.options.is_admin == true) { 333 return; 334 } 335 if (Object.keys(item_dataLayer.ecommerce.items[0]).length > 0) { 336 var item = item_dataLayer.ecommerce.items[0]; 337 var variation_attribute_name = ""; 338 var vari_data = ""; 339 var variation_id = ""; 340 var variation_id_obj = document.getElementsByClassName("variation_id"); 341 if (variation_id_obj.length > 0) { 342 variation_id = document.getElementsByClassName("variation_id")[0].value; 343 } 344 var varPrice = item.price; 345 if (variation_id != "") { 346 vari_data = this.get_variation_data_by_id(variations_data, variation_id); 347 var p_attributes = vari_data.attributes; 348 if (Object.keys(p_attributes).length > 0) { 349 variation_attribute_name = this.get_variation_attribute_name(p_attributes); 350 } 351 if (vari_data.display_price) { 352 varPrice = vari_data.display_price; 353 } else if (vari_data.display_regular_price) { 354 varPrice = vari_data.display_regular_price; 355 } 356 } 357 358 var ecomval = (item.price * jQuery(this_var).parent().find("input[name=quantity]").val()).toFixed(2) 359 360 var add_to_cart_datalayer = { 361 event: "add_to_cart", 362 ecommerce: { 363 currency: this.options.currency, 364 value: parseFloat(ecomval), 365 items: [ 366 { 367 affiliation: item.affiliation, 368 item_id: item.item_id, 369 item_name: item.item_name, 370 currency: item.currency, 371 item_category: item.item_category, 372 price: varPrice, 373 quantity: parseInt(jQuery(this_var).parent().find("input[name=quantity]").val()), 374 item_variant: variation_attribute_name 375 376 }] 377 } 378 }; 379 if (this.options.fb_pixel_id != undefined && this.options.fb_pixel_id != null && this.options.fb_pixel_id != "") { 380 add_to_cart_datalayer.fb_event_id = this.options.fb_event_id + 'p' + item.item_id; 381 } 382 dataLayer.push(add_to_cart_datalayer); 383 384 } 385 } 386 /* 387 * 388 */ 389 checkout_step_2_tracking() { 390 var item_dataLayer = this.get_event_data_layer("begin_checkout"); 391 var item_dataLayer_asi = this.get_event_data_layer("add_shipping_info"); 392 if (item_dataLayer_asi == undefined) { 393 if (this.options.is_admin == true) { 394 return; 395 } 396 if (Object.keys(item_dataLayer.ecommerce.items[0]).length > 0) { 397 var checkout_step_2_datalayer = { 398 event: "add_shipping_info", 399 ecommerce: { 400 currency: this.options.currency, 401 value: item_dataLayer.ecommerce.value, 402 items: item_dataLayer.ecommerce.items 403 } 404 }; 405 dataLayer.push(checkout_step_2_datalayer); 406 } 407 } 408 } 409 checkout_step_3_tracking() { 410 var item_dataLayer = this.get_event_data_layer("begin_checkout"); 411 if (this.options.is_admin == true) { 412 return; 413 } 414 if (Object.keys(item_dataLayer.ecommerce.items[0]).length > 0) { 415 var checkout_step_3_datalayer = { 416 event: "add_payment_info", 417 ecommerce: { 418 currency: this.options.currency, 419 value: item_dataLayer.ecommerce.value, 420 items: item_dataLayer.ecommerce.items 421 } 422 }; 423 dataLayer.push(checkout_step_3_datalayer); 424 } 425 } 426 427 getCurrentTime() { 428 if (!Date.now) { 429 return new Date().getTime(); 430 } else { 431 //Math.floor(Date.now() / 1000) 432 return Date.now(); 433 } 434 } 435 getClientId() {
436 let client_id = this.getCookie("_ga"); 437 if (client_id != null && client_id != "") { 438 return client_id; 439 } else { 440 return; 441 } 442 } 443 setCookie(name, value, days) { 444 var expires = ""; 445 if (days) { 446 var date = new Date(); 447 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); 448 expires = "; expires=" + date.toUTCString(); 449 } 450 document.cookie = name + "=" + (value || "") + expires + "; path=/"; 451 } 452 getCookie(name) { 453 var nameEQ = name + "="; 454 var ca = document.cookie.split(";"); 455 for (var i = 0; i < ca.length; i++) { 456 var c = ca[i]; 457 while (c.charAt(0) == " ") c = c.substring(1, c.length); 458 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); 459 } 460 return null; 461 } 462 eraseCookie(name) { 463 document.cookie = name + "=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;"; 464 } 465}
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.