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 if (this.options.fb_pixel_id != undefined && this.options.fb_pixel_id != null && this.options.fb_pixel_id != "") { 314 add_to_cart_datalayer.fb_event_id = this.options.fb_event_id + 'p'
314+ item.id; 315 } 316 317 dataLayer.push(add_to_cart_datalayer); 318 } 319 getParameterByName(name, url = window.location.href) { 320 name = name.replace(/[\[\]]/g, '\\$&'); 321 var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), 322 results = regex.exec(url); 323 if (!results) return null; 324 if (!results[2]) return ''; 325 return decodeURIComponent(results[2].replace(/\+/g, ' ')); 326 } 327 /* 328 * below code run while add to cart on product page. 329 * ( Event=> add_to_cart) 330 */ 331 add_to_cart_click(variations_data, page_type = "Product Pages", event) { 332 var this_var = event.currentTarget; 333 var item_dataLayer = this.get_event_data_layer("view_item"); 334 if (this.options.is_admin == true) { 335 return; 336 } 337 if (Object.keys(item_dataLayer.ecommerce.items[0]).length > 0) { 338 var item = item_dataLayer.ecommerce.items[0]; 339 var variation_attribute_name = ""; 340 var vari_data = ""; 341 var variation_id = ""; 342 var variation_id_obj = document.getElementsByClassName("variation_id"); 343 if (variation_id_obj.length > 0) { 344 variation_id = document.getElementsByClassName("variation_id")[0].value; 345 } 346 var varPrice = item.price; 347 if (variation_id != "" && variation_id != "0") { 348 vari_data = this.get_variation_data_by_id(variations_data, variation_id); 349 var p_attributes = vari_data.attributes; 350 if (Object.keys(p_attributes).length > 0) { 351 variation_attribute_name = this.get_variation_attribute_name(p_attributes); 352 } 353 if (vari_data.display_price) { 354 varPrice = vari_data.display_price; 355 } else if (vari_data.display_regular_price) { 356 varPrice = vari_data.display_regular_price; 357 } 358 } 359 360 var ecomval = (item.price * jQuery(this_var).parent().find("input[name=quantity]").val()).toFixed(2) 361 362 var add_to_cart_datalayer = { 363 event: "add_to_cart", 364 ecommerce: { 365 currency: this.options.currency, 366 value: parseFloat(ecomval), 367 items: [ 368 { 369 affiliation: item.affiliation, 370 item_id: item.item_id, 371 item_name: item.item_name, 372 currency: item.currency, 373 item_category: item.item_category, 374 price: varPrice, 375 quantity: parseInt(jQuery(this_var).parent().find("input[name=quantity]").val()), 376 item_variant: variation_attribute_name 377 378 }] 379 } 380 }; 381 if (this.options.fb_pixel_id != undefined && this.options.fb_pixel_id != null && this.options.fb_pixel_id != "") { 382 add_to_cart_datalayer.fb_event_id = this.options.fb_event_id + 'p' + item.item_id; 383 } 384 dataLayer.push(add_to_cart_datalayer); 385 386 } 387 } 388 /* 389 * 390 */ 391 checkout_step_2_tracking() { 392 var item_dataLayer = this.get_event_data_layer("begin_checkout"); 393 var item_dataLayer_asi = this.get_event_data_layer("add_shipping_info"); 394 if (item_dataLayer_asi == undefined) { 395 if (this.options.is_admin == true) { 396 return; 397 } 398 if (Object.keys(item_dataLayer.ecommerce.items[0]).length > 0) { 399 var checkout_step_2_datalayer = { 400 event: "add_shipping_info", 401 ecommerce: { 402 currency: this.options.currency, 403 value: item_dataLayer.ecommerce.value, 404 items: item_dataLayer.ecommerce.items 405 } 406 }; 407 dataLayer.push(checkout_step_2_datalayer); 408 } 409 } 410 } 411 checkout_step_3_tracking() { 412 var item_dataLayer = this.get_event_data_layer("begin_checkout"); 413 if (this.options.is_admin == true) { 414 return; 415 } 416 if (Object.keys(item_dataLayer.ecommerce.items[0]).length > 0) { 417 var checkout_step_3_datalayer = { 418 event: "add_payment_info", 419 ecommerce: { 420 currency: this.options.currency, 421 value: item_dataLayer.ecommerce.value, 422 items: item_dataLayer.ecommerce.items 423 } 424 }; 425 dataLayer.push(checkout_step_3_datalayer); 426 } 427 } 428 429 getCurrentTime() { 430 if (!Date.now) { 431 return new Date().getTime(); 432 } else { 433 //Math.floor(Date.now() / 1000) 434 return Date.now(); 435 } 436 } 437 getClientId() {
438 let client_id = this.getCookie("_ga"); 439 if (client_id != null && client_id != "") { 440 return client_id; 441 } else { 442 return; 443 } 444 } 445 setCookie(name, value, days) { 446 var expires = ""; 447 if (days) { 448 var date = new Date(); 449 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); 450 expires = "; expires=" + date.toUTCString(); 451 } 452 document.cookie = name + "=" + (value || "") + expires + "; path=/"; 453 } 454 getCookie(name) { 455 var nameEQ = name + "="; 456 var ca = document.cookie.split(";"); 457 for (var i = 0; i < ca.length; i++) { 458 var c = ca[i]; 459 while (c.charAt(0) == " ") c = c.substring(1, c.length); 460 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); 461 } 462 return null; 463 } 464 eraseCookie(name) { 465 document.cookie = name + "=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;"; 466 } 467}
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.