1ACC.googleAnalytics = { 2 _autoload: [ 3 "gtmPush", 4 "gtmAddToCartBulk", 5 "gtmReOrder", 6 "gtmPurchaseDetails", 7 "gtmCartCheckout", 8 "gtmQuickOrder", 9 "gtmBackOrder", 10 "gtmColorChart", 11 "gtmAddToQuickOrder", 12 ], 13 // Google Tag Manger Push Function 14 gtmPush: function () 15 { 16 $(".googleAnalytics").on('click', function (e) { 17 ACC.googleAnalytics.push($(this)); 18 19 }); 20 }, 21 22 push: function(ref){ 23 24 var values = ACC.googleAnalytics.getValuesOfInputType(ref); 25 if(values[3] == 'detail'){ 26 ACC.googleAnalytics.googleAnalyticsForProductDetail(values[0],values[3],values[4]); 27 } 28 var productDetails = []; 29 var productCode = values[0]; 30 var action = values[1]; 31 var event = values[2]; 32 ACC.googleAnalytics.createProductDetailArray(productDetails,productCode); 33 ACC.googleAnalytics.googleAnalytics(event,action,productDetails); 34 35 }, 36 gtmAddToCartBulk: function () 37 { 38 $(".googleAnalyticsBulk").on('click', function (e) { 39 var productDetails = []; 40 var action = ''; 41 var event = ''; 42 $("tr.bulkAnalytics").each(function() { 43 var values = ACC.googleAnalytics.getValuesOfInputType($(this)); 44 var productCode = values[0]; 45 action = values[1]; 46 event = values[2]; 47 ACC.googleAnalytics.createProductDetailArray(productDetails,productCode); 48 }); 49 ACC.googleAnalytics.googleAnalytics(event,action,productDetails); 50 }); 51 }, 52 gtmBackOrder: function () 53 { 54 $(".googleAnalyticsForBackOrder").on('click', function (e) { 55 56 var values = ACC.googleAnalytics.getValuesOfInputType($(this)); 57 var productCode = values[0]; 58 59 var productDetails = []; 60 var action = document.getElementById("backOrderAction_"+productCode).value; 61 var event = document.getElementById("backOrderEvent_"+productCode).value; 62 ACC.googleAnalytics.createProductDetailArray(productDetails,productCode); 63 ACC.googleAnalytics.googleAnalytics(event,action,productDetails); 64 sessionStorage.setItem("backOrderQty_"+productCode,true); 65 }); 66 }, 67 68 gtmColorChart: function(){ 69 $(document).on('click',".colorChartAnalytics",function (e) { 70 var event = document.getElementById("colorChartEvent").value; 71 ACC.googleAnalytics.pushEvent(event); 72 ACC.googleAnalytics.push($(this)); 73 }); 74 $(document).on('click',".moreProductInfo",function (e) { 75 var event = document.getElementById("moreProductInfoEvent").value; 76 ACC.googleAnalytics.pushEvent(event); 77 }); 78 }, 79 gtmCallMe: function(){ 80 ACC.googleAnalytics.pushEvent('CallMe'); 81 }, 82 83 pushEvent: function(event) { 84 var json= { 85 "event": event 86 }; 87 dataLayer.push(json); 88 console.log("Pushed to GTM: "+JSON.stringify(json)); 89 }, 90 gtmReOrder: function () 91 { 92 $(".reOrderGoogleAnalyticsBulk").on('click', function (e) { 93 var orderCode=orderCode=$(this).data('orderCode'); 94 var reorderDetails = ''; 95 var isUnavailableproductExist = false; 96 $('.unapprovedProductsModal-reorder .unapprovedProductsList').empty(); 97 $.ajax({ 98 url: ACC.config.encodedContextPath+"/checkout/summary/reorderDetails?orderCode=" + orderCode, 99 type: 'GET', 100 data : JSON.stringify(orderCode), 101 dataType : 'json', 102 contentType: 'application/json', 103 async: false, 104 success: function (response) { 105 reorderDetails = response; 106 $.each(response, function(key,value) { 107 console.log(value.unavailable+"--"+value.product.name); 108 var unavailableText = $('#unavailableText').val(); 109 if(value.unavailable == true) { 110 isUnavailableproductExist = true; 111 $('.unapprovedProductsModal-reorder .unapprovedProductsList').append('<li><span>'+value.product.name+'</span> ('+value.product.code+') '+unavailableText+'</li>'); 112 } 113 }); 114 }, 115 error: function (orderCode) { 116 console.log("Error occured for order number : " + orderCode); 117 } 118 }); 119 if(isUnavailableproductExist != true) { 120 ACC.checkoutsteps.reOrder(); 121 } 122 else { 123 $('.unapprovedProductsModal-reorder').modal('show'); 124 } 125 var productDetails = []; 126 var event = document.getElementById("event").value; 127 var action = document.getElementById("action").value; 128 var currencyCode = ''; 129 if(reorderDetails != undefined && reorderDetails.length>0){ 130 currencyCode = reorderDetails[0] != undefined ? (reorderDetails[0].basePrice.currencyIso) : ''; 131 } 132 133 ACC.googleAnalytics.getProductDetails(reorderDetails,productDetails); 134 ACC.googleAnalytics.reorderGoogleAnalytics(event,action,productDetails,currencyCode); 135 136 }); 137 }, 138 139 gtmCartCheckout: function(){ 140 $(".googleAnalyticsCheckout").on('click', function (e) { 141 var step = document.getElementById("step").value; 142 if((step == 4 && !$('.TermsCheck').is(':checked'))){ 143 return; 144 }else { 145 ACC.googleAnalytics.checkout(); 146 } 147 148 }); 149 }, 150 checkout: function(){ 151 152 var productDetails = []; 153 var action = ''; 154 var event = ''; 155 var option=''; 156 var step = ''; 157 var checkoutOptionAction = ''; 158 var checkoutOptionEvent = ''; 159 var boCheckoutEvent= ''; 160 var boCheckoutAction=''; 161 var backOrderProductDetails = []; 162 163 $(".bulkAnalytics").each(function() {
164 var productCode = $(this).children('.productCode').val(); 165 event = document.getElementById("eventCheckout").value; 166 action = document.getElementById("actionCheckout").value; 167 option= document.getElementById("option").value; 168 if(option == 'Payment'){ 169 option = $(".selected input[name='paymentType']").val(); 170 if(option == undefined || option == ""){ 171 option = $(".selected input[name='creditCardId']").val(); 172 } 173 } 174 step = document.getElementById("step").value; 175 checkoutOptionAction = document.getElementById("checkoutOption").value; 176 checkoutOptionEvent = document.getElementById("checkoutOptionEvent").value; 177 178 boCheckoutAction = document.getElementById("bOCheckoutAction_"+productCode).value; 179 boCheckoutEvent = document.getElementById("bOCheckoutEvent_"+productCode).value; 180 181 sessionStorage.setItem("boCheckoutAction", boCheckoutAction); 182 sessionStorage.setItem("boCheckoutEvent", boCheckoutEvent); 183 184 var isbackOrderEnabled = false; 185 if(sessionStorage.getItem("backOrder") == "true"){ 186 isbackOrderEnabled = true; 187 }else{ 188 isbackOrderEnabled = $("input[data-back-order-enabled = 'true']").length > 0; 189 } 190 if(isbackOrderEnabled == true){ 191 sessionStorage.setItem("backOrder", true); 192 } 193 if(sessionStorage.getItem("backOrder")== "true" && (boCheckoutAction!=null && boCheckoutEvent!= null)){ 194 195 var backOrderQty = sessionStorage.getItem("backOrderQty_"+productCode); 196 if(backOrderQty == "true"){ 197 ACC.googleAnalytics.createProductDetailArray(productDetails,productCode); 198 var index = productDetails.length -1; 199 productDetails[index].product_backorder = backOrderQty; 200 backOrderProductDetails.push(true); 201 202 } else { 203 ACC.googleAnalytics.createProductDetailArray(productDetails,productCode); 204 } 205 } else { 206 ACC.googleAnalytics.createProductDetailArray(productDetails,productCode); 207 } 208 }); 209 210 if(backOrderProductDetails.indexOf(true) > -1 && step == '4' ){ 211 action = sessionStorage.getItem("boCheckoutAction"); 212 event = sessionStorage.getItem("boCheckoutEvent"); 213 option = document.getElementById("backOrderOption").value; 214 } 215 // ACC.googleAnalytics.checkoutGoogleAnalytics(event,action,productDetails,step,option); 216 217 if(checkoutOption!=null || checkoutOption!= 'undefined'){ 218 ACC.googleAnalytics.checkoutGoogleAnalytics(event,action,productDetails,step,option); 219 // ACC.googleAnalytics.checkoutOptionAnalytics(checkoutOptionAction,checkoutOptionEvent,step,option); // Removing due to double event fire issue on checkout 220 } 221 222 }, 223 gtmQuickOrder: function(){ 224 $(document).on('click',".quickOrderAnalytics",function (e) { 225 var values = ACC.googleAnalytics.getValuesOfInputType($(this)); 226 if(values[3] == 'detail'){ 227 ACC.googleAnalytics.googleAnalyticsForProductDetail(values[0],values[3],value[4]); 228 } 229 var productDetails = []; 230 var productCode = values[0]; 231 var action = values[1]; 232 var event = values[2]; 233 ACC.googleAnalytics.createProductDetailArray(productDetails,productCode); 234 ACC.googleAnalytics.googleAnalytics(event,action,productDetails); 235 }); 236 }, 237 gtmAddToQuickOrder: function(){ 238 $(document).on('click',".googleAnalyticsQuickOrderDropDown",function (e) { 239 var event = document.getElementById("event").value; 240 var action = "click"; 241 var productDetails = []; 242 var productCode = $(this).data('pcode'); 243 var productName = $(this).data('pname'); 244 productDetails.push( 245 { 246 "item_name": productName, 247 "item_id" : productCode, 248 }) 249 ACC.googleAnalytics.googleAnalytics(event,action,productDetails); 250 }); 251 }, 252 gtmPurchaseDetails: function (){ 253 var orderCode = ""; 254 $(window).on('load', function() { 255 var id = document.getElementById("transactionId"); 256 if(id!= null && id.value!='undefined'){ 257 orderCode = document.getElementById("transactionId").value; 258 var orderDetails = ""; 259 $.ajax({ 260 url: ACC.config.encodedContextPath+"/checkout/summary/reorderDetails?orderCode=" + orderCode, 261 type: 'GET', 262 data : JSON.stringify(orderCode), 263 dataType : 'json', 264 contentType: 'application/json', 265 async: false, 266 success: function (response) { 267 orderDetails = response; 268 }, 269 error: function (orderCode) { 270 console.log("Error occured for order number : " + orderCode); 271 } 272 }); 273 274 var affiliation = document.getElementById("affiliation").value; 275 var revenue = document.getElementById("revenue").value; 276 var tax = document.getElementById("tax").value; 277 var shipping = document.getElementById("shipping").value; 278 var coupon = document.getElementById("coupon").value; 279 var action = document.getElementById("actionPurchase").value; 280 var event = document.getElementById("eventPurchase").value; 281 var purchaseDetails = [orderCode,affiliation,revenue,tax,shipping,coupon,action,event]; 282 var productDetails = []; 283 284 ACC.googleAnalytics.getProductDetails(orderDetails,productDetails); 285 ACC.googleAnalytics.checkoutPurchaseGoogleAnalytics(action, productDetails,purchaseDetails); 286 if(sessionStorage.getItem("boCheckoutEvent") != null){ 287 sessionStorage.removeItem("boCheckoutEvent"); 288 } 289 if(sessionStorage.getItem("boCheckoutAction") != null){ 290 sessionStorage.removeItem("boCheckoutAction"); 291 } 292 if(sessionStorage.getItem("backOrderProductDetails") !=null){ 293 sessionStorage.removeItem("backOrderProductDetails"); 294 sessionStorage.removeItem("backOrder"); 295 } 296 } 297 }); 298 299 300 }, 301 isEmpty: function (obj) 302 { 303 if (typeof obj == 'undefined' || obj === null || obj === '') return true; 304 return false;
305 }, 306 getValuesOfInputType: function(dom){ 307 var productCode = $(dom).children('.productCode').val(); 308 var action = $(dom).children('#actionClick_'+productCode).val(); 309 var event = $(dom).children('#eventClick_'+productCode).val(); 310 var detail = $(dom).children('#productDetail_'+productCode).val(); 311 var productDetailEvent = $(dom).children('#productDetailEvent_'+productCode).val(); 312 313 if(productCode == 'undefined' || productCode == null){ 314 productCode = $(dom).children().find(".productCode").val(); 315 if (productCode == 'undefined' || productCode == null) { 316 productCode = document.getElementById("productCode").value; 317 productCode = $(dom).prev("#productCode").val(); 318 } 319 } 320 if(productCode == 'undefined' || productCode == null){ 321 productCode = document.getElementById("productCode").value; 322 if(document.getElementById("eventClick_"+productCode)!= undefined){ 323 event = document.getElementById("eventClick_"+productCode).value 324 } 325 if(document.getElementById("actionClick_"+productCode) != undefined){ 326 action = document.getElementById("actionClick_"+productCode).value; 327 } 328 if(document.getElementById("productDetail_"+productCode) != undefined){ 329 detail = document.getElementById("productDetail_"+productCode).value; 330 } 331 if(document.getElementById("productDetailEvent_"+productCode) !=undefined){ 332 productDetailEvent = document.getElementById("productDetailEvent_"+productCode).value; 333 } 334 } 335 if(event == 'undefined' || event == null){ 336 event = document.getElementById("event_"+productCode).value; 337 if(event == 'undefined' || event == null){ 338 event = document.getElementById("event").value; 339 340 } 341 } 342 343 if(action == 'undefined' || action == null){ 344 action = document.getElementById("action_"+productCode).value; 345 if(action == 'undefined' || action == null){ 346 action = document.getElementById("action").value; 347 } 348 } 349 return[productCode,action,event,detail,productDetailEvent]; 350 }, 351 352 googleAnalytics: function(event,action,productDetails){ 353 var json= { 354 "event": event, 355 "ecommerce": { 356 "currency": $("#currentCurrency").val(), 357 "items": [] 358 } 359 }; 360 361 for(let i=0; i<productDetails.length; i++){ 362 json.ecommerce.items.push({ 363 "item_brand": productDetails[i].item_brand, 364 "item_category": productDetails[i].item_category, 365 "item_id" : productDetails[i].item_id, 366 "item_name": productDetails[i].item_name, 367 "item_variant": productDetails[i].item_variant, 368 "price": parseFloat(productDetails[i].price), 369 "quantity": parseInt(productDetails[i].quantity) 370 }) 371 } 372 373 dataLayer.push(json); 374 console.log("Pushed to GTM2: "+JSON.stringify(json)); 375 }, 376 377 googleAnalyticsForProductDetail: function(productCode,detail,productDetailEvent){ 378 var productName = document.getElementById("currentProductName_"+productCode).value; 379 var productBrandName = document.getElementById("currentProductBrandName_"+productCode).value; 380 var productCategory = document.getElementById("currentProductCategory_"+productCode).value; 381 var json= { 382 "event": productDetailEvent, 383 "ecommerce": { 384 "currency": $("#currentCurrency").val(), 385 "items": [{ 386 "item_name": productName, 387 "item_id" : productCode, 388 "item_brand": productBrandName, 389 "item_category": productCategory 390 }] 391 } 392 }; 393 394 // Google Tag Manager Push 395 dataLayer.push(json); 396 console.log("Pushed to GTM3: "+JSON.stringify(json)); 397 }, 398 399 createProductDetailArray: function(productDetails,productCode){ 400 var productName = document.getElementById("currentProductName_"+productCode).value; 401 var productVariant = document.getElementById("currentProductVariant_"+productCode).value; 402 var productPrice = document.getElementById("currentProductPrice_"+productCode).value; 403 var productBrandName = document.getElementById("currentProductBrandName_"+productCode).value; 404 var productCategory = document.getElementById("currentProductCategory_"+productCode).value; 405 var productQuantity = document.getElementsByClassName("mirrorpdpAddtoCartInput_"+productCode); 406 if(productVariant == 'undefined' || productVariant == undefined || productVariant == 'null' || productVariant == null){ 407 productVariant = ''; 408 console.log("setting the productVariant to empty in createProductDetailArray"); 409 } 410 productDetails.push({ 411 "item_name": productName,
412 "item_id" : productCode, 413 "price": productPrice, 414 "item_brand": productBrandName, 415 "item_category": productCategory, 416 "item_variant": productVariant, 417 "quantity": productQuantity[0].value 418 }); 419 }, 420 reorderGoogleAnalytics: function(event,action,productDetails,currencyCode){ 421 var a = {}; 422 a = { 423 "currency": $("#currentCurrency").val(), 424 "items": productDetails 425 }; 426 427 var json= { 428 "event": event, 429 "ecommerce": a 430 }; 431 432 dataLayer.push(json); 433 console.log("Pushed to GTM4: "+JSON.stringify(json)); 434 }, 435 checkoutGoogleAnalytics: function(event,action,productDetails,step,option){ 436 if(step == 1) { 437 event = "begin_checkout" 438 } 439 else if(step == 2) { 440 event = "add_shipping_info" 441 } 442 else if(step == 3) { 443 event = "add_payment_info" 444 } 445 else if(step == 4) { 446 event = "purchase" 447 } 448 var json= { 449 "event": event, 450 "ecommerce": { 451 "currency": $("#currentCurrency").val(), 452 "items": [], 453 checkoutOptionAction: { 454 "actionField": {"step": step,"option": option} 455 } 456 } 457 }; 458 459 for(let i=0; i<productDetails.length; i++){ 460 json.ecommerce.items.push({ 461 "item_name": productDetails[i].item_name, 462 "item_id" : productDetails[i].item_id, 463 "price": parseFloat(productDetails[i].price), 464 "item_brand": productDetails[i].item_brand, 465 "item_category": productDetails[i].item_category, 466 "item_variant": productDetails[i].item_variant, 467 "quantity": parseInt(productDetails[i].quantity) 468 }) 469 } 470 471 dataLayer.push(json); 472 console.log("Pushed to GTM5: "+JSON.stringify(json)); 473 }, 474 475 // Removing due to double event fire issue on checkout 476 477 // checkoutOptionAnalytics: function(checkoutOptionAction,checkoutOptionEvent,step,option){ 478 // if(step == 1) { 479 // checkoutOptionEvent = "begin_checkout" 480 // } 481 // if(step == 2) { 482 // checkoutOptionEvent = "add_shipping_info" 483 // } 484 // if(step == 3) { 485 // checkoutOptionEvent = "add_payment_info" 486 // } 487 // else if(step == 4) { 488 // checkoutOptionEvent = "purchase" 489 // } 490 // var json= { 491 // "event": checkoutOptionEvent, 492 // "ecommerce": { 493 // checkoutOptionAction: { 494 // "actionField": {"step": step,"option": option} 495 // } 496 // } 497 // }; 498 499 // dataLayer.push(json); 500 // console.log("Pushed to GTM6: "+JSON.stringify(json)); 501 // }, 502 503 checkoutPurchaseGoogleAnalytics: function(action, productDetails,purchaseDetails){ 504 505 var a = {}; 506 a = { 507 "transaction_id": purchaseDetails[0], 508 "affiliation": purchaseDetails[1], 509 "value": parseFloat(purchaseDetails[2].substring(1)), 510 "tax": parseFloat(purchaseDetails[3].substring(1)), 511 "shipping": parseFloat(purchaseDetails[4].substring(1)), 512 "coupon": purchaseDetails[5], 513 "items": productDetails 514 }; 515 516 var action = purchaseDetails[6]; 517 var event = purchaseDetails[7]; 518 var json= { 519 "event": event, 520 "ecommerce": a 521 }; 522 523 dataLayer.push(json); 524 console.log("Pushed to GTM7: "+JSON.stringify(json)); 525 }, 526 527 getProductDetails: function(orderDetails,productDetails){ 528 $.each(orderDetails, function (i) { 529 530 var productCode = orderDetails[i].product.code; 531 var productBrandName = orderDetails[i].product.brandName; 532 var productCategory = orderDetails[i].product.categories[0].name; 533 var productVariant = orderDetails[i].product.variantType; 534 var productPrice = ''; 535 if(orderDetails[i].product.price != null) { 536 productPrice = orderDetails[i].product.price.value; 537 } 538 var productQuantity = orderDetails[i].quantity; 539 var productName = orderDetails[i].product.name; 540 currencyCode = orderDetails[i].totalPrice.currencyIso; 541 if(sessionStorage.getItem("backOrderQty_"+productCode) != null){ 542 sessionStorage.removeItem("backOrderQty_"+productCode); 543 } 544 if(productVariant == 'undefined' || productVariant == undefined || productVariant == 'null' || productVariant == null){ 545 productVariant = ''; 546 console.log("setting the productVariant to empty in getProductDetails"); 547 } 548 productDetails.push({ 549 "item_name": productName,
550 "item_id" : productCode, 551 "price": productPrice, 552 "item_brand": productBrandName, 553 "item_category": productCategory, 554 "item_variant": productVariant, 555 "quantity": productQuantity 556 }); 557 }); 558 } 559 560 561}; 562
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.