1/* global id_product, combinations, attributesCombinations, trackingAdsConversionId, trackingAdsConversionLabel */ 2 3/** 4 * File from https://prestashow.pl 5 * 6 * DISCLAIMER 7 * Do not edit or add to this file if you wish to upgrade this module to newer 8 * versions in the future. 9 * 10 * @authors PrestaShow.pl <[email protected]> 11 * @copyright 2018 PrestaShow.pl 12 * @license https://prestashow.pl/license 13 */ 14 15PShowConversionJS_base.dataLayer.productListImpressionInterval = function (listObj, listId) { 16 17 if (!listObj.is(':visible')) { 18 return; 19 } 20 21 clearInterval(PShowConversionJS_base.dataLayer.intervals[listId]); 22 23 var gtmProducts = []; 24 25 var bodyId = $('body').attr('id'); 26 27 var listName = ''; 28 if (bodyId && bodyId === 'search') { 29 listName = 'Search results'; 30 } else if (typeof listId !== 'undefined' && listId.length) { 31 listName = listId; 32 } 33 34 var products = listObj.find('.product-container'); 35 36 if (PShowConversionJS_base.dataLayer.debug) { 37 PShowConversionJS_base.dataLayer.log("found " + products.length 38 + " products on the list: " + listName); 39 } 40 41 var position = 0; 42 if (listObj.parents('.center_column').length && bodyId !== 'index') { 43 position = PShowConversionJS_base.dataLayer.currentPage * PShowConversionJS_base.dataLayer.ps_products_per_page; 44 } 45 46 products.each(function () { 47 48 ++position; 49 50 var productDetails = { 51 'name': $(this).find('[itemprop="name"]').text().trim(), 52 'price': $(this).find('[itemprop="price"]').text().trim() 53 .replace(/([^0-9\.\,]+)/g, '').replace(',', '.'), 54 'position': position 55 }; 56 57 if (listName) { 58 productDetails.list = listName; 59 } 60 61 gtmProducts.push(productDetails); 62 63 }); 64 65 var fullData = {'event': 'impressions', 'ecommerce': {'impressions': gtmProducts}}; 66 67 PShowConversionJS_base.dataLayer.push(fullData); 68 69 // ads - dynamic remarketing 70 // PShowConversionJS_base.dataLayer.push({ 71 // 'event': 'view_item_list', 72 // 'items': gtmProducts 73 // }); 74 75}; 76 77PShowConversionJS_base.dataLayer.initGTMMeasuring = function () { 78 79 if (!PShowConversionJS_base.dataLayer.active) { 80 return; 81 } 82 83 // try to get page from request uri 84 PShowConversionJS_base.dataLayer.currentPage = parseInt(document.location.href.replace(/.*p=([0-9]+).*/, '$1')); 85 if (isNaN(PShowConversionJS_base.dataLayer.currentPage)) { 86 // try to get page from url hash 87 PShowConversionJS_base.dataLayer.currentPage = parseInt(document.location.href.replace(/.*page-([0-9]+).*/, '$1')); 88 } 89 if (isNaN(PShowConversionJS_base.dataLayer.currentPage)) { 90 // set default page 91 PShowConversionJS_base.dataLayer.currentPage = 1; 92 } 93 PShowConversionJS_base.dataLayer.currentPage -= 1; 94 95 96 /* 97 * Measuring Product Impressions 98 * https://developers.google.com/tag-manager/enhanced-ecommerce#product-impressions 99 */ 100 var productLists = $('.product_list'); 101 102 if (productLists.length) { 103 104 if (PShowConversionJS_base.dataLayer.debug) { 105 PShowConversionJS_base.dataLayer.log("found " + productLists.length + " product lists"); 106 } 107 108 var listNum = 0; 109 110 productLists.each(function () { 111 112 ++listNum; 113 114 var listObj = $(this); 115 var listId = listObj.attr('id'); 116 117 if (!listId) { 118 listId = $('body').attr('id') + "_listnum_" + listNum; 119 } 120 121 PShowConversionJS_base.dataLayer.intervals[listId] = setInterval(function () { 122 PShowConversionJS_base.dataLayer.productListImpressionInterval(listObj, listId); 123 }, 3000); 124 125 }); 126 127 } 128 /* 129 * End of Measuring Product Impressions 130 */ 131 132 /* 133 * Measuring Views of Product Details 134 * https://developers.google.com/tag-manager/enhanced-ecommerce#product-impressions 135 */ 136 if ($('body').attr('id') === 'product') { 137 138 var productContainer = $('#main[itemtype="https://schema.org/Product"]'); 139 if (!productContainer.length) {
140 productContainer = $('#main[itemtype="http://schema.org/Product"]'); 141 } 142 if (!productContainer.length) { 143 productContainer = $('[itemtype="https://schema.org/Product"]:first'); 144 } 145 if (!productContainer.length) { 146 productContainer = $('[itemtype="http://schema.org/Product"]:first'); 147 } 148 149 // prepare product details 150 var productDetails = {}; 151 152 // append product name 153 if (productContainer.find('h1[itemprop="name"]').length) { 154 productDetails.name = productContainer.find('h1[itemprop="name"]:first').text().trim(); 155 } else if (productContainer.find('[itemprop="name"]').length) { 156 productDetails.name = productContainer.find('[itemprop="name"]:first').text().trim(); 157 } 158 159 // append product id 160 var productId = parseInt($('body').attr('class').replace(/.*product\-([0-9]+).*/, '$1')); 161 if (isNaN(productId) && typeof id_product !== 'undefined' && !isNaN(id_product)) { 162 productId = id_product; 163 } 164 if (!isNaN(productId)) { 165 productDetails.id = productId; 166 167 // append product price 168 if (productContainer.find('[itemprop="price"]').length) { 169 var price = productContainer.find('[itemprop="price"]:first').attr('content'); 170 if (typeof price === 'undefined') { 171 price = productContainer.find('[itemprop="price"]:first').text(); 172 } 173 productDetails.price = price.trim().replace(/([^0-9.,]+)/, '').replace(',', '.'); 174 } 175 176 // append product category 177 if ($('.breadcrumb a').length) { 178 productDetails.category = $('.breadcrumb a').last() 179 .closest('li').prev('li').find('a').text().trim() 180 .toLowerCase().replace(' ', '-'); 181 } 182 183 if (PShowConversionJS_base.dataLayer.debug) { 184 PShowConversionJS_base.dataLayer.log("displayed details of the product #" + productDetails.id); 185 } 186 187 PShowConversionJS_base.getProductDetails([productDetails.id], function (_productDetails) { 188 if (_productDetails) { 189 productDetails = Object.assign(productDetails, _productDetails[productDetails.id]); 190 } 191 192 var ecommerce = { 193 'detail': { 194 'actionField': { 195 'list': 'product-page' 196 }, 197 'products': [productDetails] 198 } 199 }; 200 var currency = PShowConversionJS_base.getCurrencyIsoCode(); 201 if (currency) { 202 ecommerce.currencyCode = currency; 203 } 204 205 var fullData = { 206 'event': 'productDetailImpression', 'ecommerce': ecommerce 207 }; 208 209 // push event 210 PShowConversionJS_base.dataLayer.push(fullData); 211 212 // ads - dynamic remarketing 213 // PShowConversionJS_base.dataLayer.push({ 214 // 'event': 'view_item', 215 // 'value': productDetails.price, 216 // 'items': [{ 217 // 'id': productDetails.id, 218 // 'google_business_vertical': 'retail' 219 // }] 220 // }); 221 }); 222 223 // var fullData = { 224 // 'event': 'detail', 'ecommerce': {'detail': {'products': [productDetails]}} 225 // }; 226 // 227 // // push event 228 // PShowConversionJS_base.dataLayer.push(fullData); 229 230 // ads - dynamic remarketing 231 // PShowConversionJS_base.dataLayer.push({ 232 // 'event': 'view_item', 233 // 'value': productDetails.price, 234 // 'items': [{ 235 // 'id': productDetails.id, 236 // 'google_business_vertical': 'retail' 237 // }] 238 // }); 239 240 } 241 } 242 /* 243 * End of Measuring Views of Product Details 244 */ 245 246 /* 247 * Measuring Product Clicks 248 * https://developers.google.com/tag-manager/enhanced-ecommerce#product-clicks 249 */ 250 $(document).on('click', '.product-container a:not(.quick-view):not(.ajax_add_to_cart_button)', function (e) { 251 252 e.preventDefault(); 253 254 // give half second for script to push event and redirect 255 setTimeout(function () { 256 document.location = productUrl; 257 }, 500); 258
259 var productContainer = $(this).closest('.product-container'); 260 if (!productContainer.length) { 261 productContainer = $('#main[itemtype="https://schema.org/Product"]'); 262 } 263 if (!productContainer.length) { 264 productContainer = $('#main[itemtype="http://schema.org/Product"]'); 265 } 266 if (!productContainer.length) { 267 productContainer = $('[itemtype="https://schema.org/Product"]:first'); 268 } 269 if (!productContainer.length) { 270 productContainer = $('[itemtype="http://schema.org/Product"]:first'); 271 } 272 273 var productUrl = $(this).attr('href').trim(); 274 275 if (productContainer.find('h1[itemprop="name"]').length) { 276 productName = productContainer.find('h1[itemprop="name"]:first').text().trim(); 277 } else if (productContainer.find('[itemprop="name"]').length) { 278 productName = productContainer.find('[itemprop="name"]:first').text().trim(); 279 } else { 280 return; 281 } 282 283 // find position of the clicked item 284 var position = parseInt(productContainer.index('.product-container')) + 1; 285 position += PShowConversionJS_base.dataLayer.currentPage * PShowConversionJS_base.dataLayer.ps_products_per_page; 286 287 // prepare product details 288 var productDetails = { 289 'name': productName, 290 'id': productUrl.replace(/.*id_product=([0-9]+).*/, '$1'), 291 'price': productContainer.find('[itemprop="price"]').text().trim() 292 .replace(/([^0-9\.\,]+)/g, '').replace(',', '.'), 293 'position': position, 294 }; 295 if (isNaN(productDetails.id)) { 296 productDetails.id = productUrl.replace(/.*([0-9]+).*\.html/, '$1'); 297 } 298 299 if (PShowConversionJS_base.dataLayer.debug) { 300 PShowConversionJS_base.dataLayer.log("clicked on product " + productDetails.name); 301 PShowConversionJS_base.dataLayer.log(productDetails, true); 302 } 303 304 var fullData = { 305 'event': 'productClick', 306 'ecommerce': {'click': {'products': [productDetails]}}, 307 'eventCallback': function () { 308 // redirect to the product page 309 document.location = productUrl; 310 } 311 }; 312 313 // push event 314 PShowConversionJS_base.dataLayer.push(fullData); 315 316 return false; 317 }); 318 /* 319 * End of Measuring Product Clicks 320 */ 321 322 /* 323 * Measuring Additions to a Shopping Cart 324 * https://developers.google.com/tag-manager/enhanced-ecommerce#add 325 */ 326 $(document).on('click', '.ajax_add_to_cart_button', function (e) { 327 328 // var productContainer = $(this).closest('.product-container'); 329 var productContainer = $('#main[itemtype="https://schema.org/Product"]'); 330 if (!productContainer.length) { 331 productContainer = $('#main[itemtype="http://schema.org/Product"]'); 332 } 333 if (!productContainer.length) { 334 productContainer = $('[itemtype="https://schema.org/Product"]:first'); 335 } 336 if (!productContainer.length) { 337 productContainer = $('[itemtype="http://schema.org/Product"]:first'); 338 } 339 340 var productUrl = productContainer.find(".lnk_view").attr('href').trim(); 341 342 if (productContainer.find('h1[itemprop="name"]').length) { 343 productName = productContainer.find('h1[itemprop="name"]:first').text().trim(); 344 } else if (productContainer.find('[itemprop="name"]').length) { 345 productName = productContainer.find('[itemprop="name"]:first').text().trim(); 346 } else { 347 return; 348 } 349 350 // prepare product details 351 var productDetails = { 352 'name': productName, 353 'id': productUrl.replace(/.*id_product=([0-9]+).*/, '$1'), 354 'price': productContainer.find('[itemprop="price"]').text().trim() 355 .replace(/([^0-9\.\,]+)/, '').replace(',', '.'), 356 'quantity': 1 357 }; 358 if (isNaN(productDetails.id)) { 359 productDetails.id = productUrl.replace(/.*([0-9]+).*\.html/, '$1'); 360 } 361 362 if (PShowConversionJS_base.dataLayer.debug) { 363 PShowConversionJS_base.dataLayer.log("added product to cart " + productDetails.id); 364 } 365 366 var fullData = { 367 'event': 'addToCart', 368 'ecommerce': {'add': {'products': [productDetails]}} 369 }; 370 371 // push event 372 PShowConversionJS_base.dataLayer.push(fullData); 373 374 // ads - dynamic remarketing 375 // PShowConversionJS_base.dataLayer.push({ 376 // 'event': 'add_to_cart', 377 // 'value': productDetails.price, 378 // 'items': [{ 379 // 'id': productDetails.id, 380 // 'google_business_vertical': 'custom' 381 // }] 382 // }); 383 384 }); 385 $(document).on('click', '#add_to_cart input, #add_to_cart button', function (e) { 386
387 // var productContainer = $(this).closest('.product-container'); 388 var productContainer = $('#main[itemtype="https://schema.org/Product"]'); 389 if (!productContainer.length) { 390 productContainer = $('#main[itemtype="http://schema.org/Product"]'); 391 } 392 if (!productContainer.length) { 393 productContainer = $('[itemtype="https://schema.org/Product"]:first'); 394 } 395 if (!productContainer.length) { 396 productContainer = $('[itemtype="http://schema.org/Product"]:first'); 397 } 398 399 if (productContainer.find('h1[itemprop="name"]').length) { 400 productName = productContainer.find('h1[itemprop="name"]:first').text().trim(); 401 } else if (productContainer.find('[itemprop="name"]').length) { 402 productName = productContainer.find('[itemprop="name"]:first').text().trim(); 403 } else { 404 return; 405 } 406 407 // prepare product details 408 var productDetails = { 409 'name': productName, 410 'id': $('#product_page_product_id').val(), 411 'price': productContainer.find("[itemprop=\"price\"]").eq(0).text().trim() 412 .replace(/([^0-9\.\,]+)/, '').replace(',', '.'), 413 'quantity': productContainer.find('#quantity_wanted').val() 414 }; 415 416 if (PShowConversionJS_base.dataLayer.debug) { 417 PShowConversionJS_base.dataLayer.log("added product to cart " + productDetails.id); 418 } 419 420 // find selected combination and 421 // prepare variant string (selected attributes separated by comma and space) 422 var idCombination = parseInt($('#idCombination').val()); 423 if (!isNaN(idCombination) && idCombination && 424 (typeof combinations !== 'undefined' && 425 typeof attributesCombinations !== 'undefined')) { 426 427 // find id's of the selected attributes 428 var idsAttributes = []; 429 for (var x in combinations) { 430 if (parseInt(combinations[x].idCombination) === idCombination) { 431 idsAttributes = combinations[x].idsAttributes; 432 break; 433 } 434 } 435 436 if (idsAttributes.length) { 437 productDetails.variant = ''; 438 439 for (var x in idsAttributes) { 440 for (var y in attributesCombinations) { 441 if (parseInt(idsAttributes[x]) === parseInt(attributesCombinations[y].id_attribute)) { 442 productDetails.variant += attributesCombinations[y].attribute.ucfirst() + ', '; 443 break; 444 } 445 } 446 } 447 448 productDetails.variant = productDetails.variant.trim(); 449 productDetails.variant = productDetails.variant.substr(0, (productDetails.variant.length - 1)); 450 } 451 } 452 453 var fullData = { 454 'event': 'addToCart', 455 'ecommerce': {'add': {'products': [productDetails]}} 456 }; 457 458 // push event 459 PShowConversionJS_base.dataLayer.push(fullData); 460 461 // ads - dynamic remarketing 462 // PShowConversionJS_base.dataLayer.push({ 463 // 'event': 'add_to_cart', 464 // 'value': productDetails.price, 465 // 'items': [{ 466 // 'id': productDetails.id, 467 // 'google_business_vertical': 'custom' 468 // }] 469 // }); 470 471 }); 472 $(document).on('click', '.cart_quantity_up', function (e) { 473 474 // find product id 475 var productId = parseInt($(this).attr('id').replace('cart_quantity_up_', '')); 476 477 if (PShowConversionJS_base.dataLayer.debug) { 478 PShowConversionJS_base.dataLayer.log("changed quantity (+1) for product " + productId); 479 } 480 481 // prepare product details 482 var productDetails = { 483 'id': productId, 484 'quantity': 1 485 }; 486 487 var fullData = { 488 'event': 'addToCart', 489 'ecommerce': {'add': {'products': [productDetails]}} 490 }; 491 492 // push event 493 PShowConversionJS_base.dataLayer.push(fullData); 494 495 // ads - dynamic remarketing 496 // PShowConversionJS_base.dataLayer.push({ 497 // 'event': 'add_to_cart', 498 // 'value': productDetails.price, 499 // 'items': [{ 500 // 'id': productDetails.id, 501 // 'google_business_vertical': 'custom' 502 // }] 503 // }); 504 505 }); 506 /* 507 * End of Measuring Additions to a Shopping Cart 508 */ 509 510 /* 511 * Measuring Removals from a Shopping Cart 512 * https://developers.google.com/tag-manager/enhanced-ecommerce#add 513 */ 514 $(document).on('click', '.ajax_cart_block_remove_link', function (e) { 515 516 // customized product management 517 var customizationId = 0; 518 var productId = 0; 519 var customizableProductDiv = $($(this).parent().parent()) 520 .find("div[id^=devareCustomizableProduct_]"); 521 522 if (customizableProductDiv && $(customizableProductDiv).length) { 523 $(customizableProductDiv).each(function () { 524 var ids = $(this).attr('id').split('_'); 525 if (typeof (ids[1]) !== 'undefined') { 526 customizationId = parseInt(ids[1]); 527 productId = parseInt(ids[2]); 528 return false;
529 } 530 }); 531 } 532 533 // common product management 534 if (!customizationId) { 535 try { 536 // retrieve idProduct and idCombination from the displayed product in the block cart 537 var firstCut = $(this).parent().parent() 538 .attr('id').replace('cart_block_product_', ''); 539 firstCut = firstCut.replace('devareCustomizableProduct_', ''); 540 ids = firstCut.split('_'); 541 productId = parseInt(ids[0]); 542 } catch (e) { 543 PShowConversionJS_base.dataLayer.error(e); 544 } 545 } 546 547 if (PShowConversionJS_base.dataLayer.debug) { 548 PShowConversionJS_base.dataLayer.log("removed product from cart " + productId); 549 } 550 551 // prepare product details 552 var productDetails = { 553 'id': productId 554 }; 555 556 var productQty = parseInt($($(this).parent().parent()) 557 .find(".quantity").text()); 558 if (!isNaN(productQty) && productQty > 0) { 559 productDetails.quantity = productQty; 560 } 561 562 productDetails.variant = $($(this).parent().parent()).find(".product-atributes").text().trim(); 563 564 var fullData = { 565 'event': 'removeFromCart', 566 'ecommerce': {'remove': {'products': [productDetails]}} 567 }; 568 569 // push event 570 PShowConversionJS_base.dataLayer.push(fullData); 571 572 }); 573 $(document).on('click', '.cart_quantity_devare', function (e) { 574 575 // find product id 576 var productId = parseInt($(this).attr('id')); 577 578 if (PShowConversionJS_base.dataLayer.debug) { 579 PShowConversionJS_base.dataLayer.log("removed product from cart " + productId); 580 } 581 582 // prepare product details 583 var productDetails = { 584 'id': productId 585 }; 586 587 var fullData = { 588 'event': 'removeFromCart', 589 'ecommerce': {'remove': {'products': [productDetails]}} 590 }; 591 592 // push event 593 PShowConversionJS_base.dataLayer.push(fullData); 594 595 }); 596 $(document).on('click', '.cart_quantity_down', function (e) { 597 598 // find product id 599 var productId = parseInt($(this).attr('id').replace('cart_quantity_down_', '')); 600 601 if (PShowConversionJS_base.dataLayer.debug) { 602 PShowConversionJS_base.dataLayer.log("changed quantity (-1) for product " + productId); 603 } 604 605 // prepare product details 606 var productDetails = { 607 'id': productId, 608 'quantity': 1 609 }; 610 611 var fullData = { 612 'event': 'removeFromCart', 613 'ecommerce': {'remove': {'products': [productDetails]}} 614 }; 615 616 // push event 617 PShowConversionJS_base.dataLayer.push(fullData); 618 619 }); 620 /* 621 * End of Measuring Removals from a Shopping Cart 622 */ 623 624 /* 625 * Measuring Additions and Removals from a Shopping Cart 626 * https://developers.google.com/tag-manager/enhanced-ecommerce#add 627 */ 628 $(document).on('focusin', '.cart_quantity_input', function (e) { 629 // save current value 630 $(this).data('val', $(this).val()); 631 632 if (PShowConversionJS_base.dataLayer.debug) { 633 PShowConversionJS_base.dataLayer.log("saved current quantity: " + $(this).val()); 634 } 635 }); 636 $(document).on('change', '.cart_quantity_input', function (e) { 637 638 if (PShowConversionJS_base.dataLayer.debug) { 639 PShowConversionJS_base.dataLayer.log("changed quantity to: " + $(this).val()); 640 } 641 642 // find product id 643 var productId = parseInt($(this).attr('name').replace('quantity_', '')); 644 645 // find quantities 646 var newQty = parseInt($(this).val()); 647 var oldQty = parseInt($(this).data('val')); 648 var difference = Math.abs(newQty - oldQty); 649 if (!difference) { 650 return; 651 } 652 653 // prepare product details 654 var productDetails = { 655 'id': productId, 656 'quantity': difference 657 }; 658 659 var fullData = { 660 'event': ((newQty > oldQty) ? 'addToCart' : 'removeFromCart'), 661 'ecommerce': ((newQty > oldQty) ? 662 {'add': {'products': [productDetails]}} : 663 {'remove': {'products': [productDetails]}} 664 ) 665 }; 666 667 // push event 668 PShowConversionJS_base.dataLayer.push(fullData); 669 670 }); 671 /* 672 * End of Measuring Removals from a Shopping Cart 673 */ 674 675 /** 676 * Measuring Checkout Options 677 * https://developers.google.com/tag-manager/enhanced-ecommerce#checkout_option 678 */ 679 $(document).on('change', 'input.delivery_option_radio', function () { 680 681 if (PShowConversionJS_base.dataLayer.debug) { 682 PShowConversionJS_base.dataLayer.log("changed shipping method"); 683 } 684 685 var optionValue = $(this).val(); 686 if ((temp = $(this).closest('tr')) && temp.length && 687 (temp = temp.find('td.delivery_option_logo')) && temp.length && 688 (temp = temp.next('td')) && temp.length && 689 (temp = temp.find('strong')) && temp.length) { 690 optionValue = temp.text().trim(); 691 } 692 693 var checkoutOption = { 694 'event': 'checkoutOption', 695 'ecommerce': { 696 'checkoutOption': { 697 'actionField': { 698 'step': (PShowConversionJS_base.dataLayer.orderStep ? PShowConversionJS_base.dataLayer.orderStep : 0), 699 'option': optionValue 700 } 701 } 702 } 703 }; 704 705 PShowConversionJS_base.dataLayer.push(checkoutOption); 706 }); 707 708 $(document).on('click', '.payment_module a', function (e) { 709 710 // give half second for script to push event and redirect 711 setTimeout(function () { 712 document.location = anchor.attr('href'); 713 }, 500); 714 715 e.preventDefault(); 716 717 if (PShowConversionJS_base.dataLayer.debug) { 718 PShowConversionJS_base.dataLayer.log("selected payment method"); 719 } 720 721 var anchor = $(this); 722 723 var checkoutOption = { 724 'event': 'checkoutOption', 725 'ecommerce': { 726 'checkoutOption': { 727 'actionField': { 728 'step': (PShowConversionJS_base.dataLayer.orderStep ? PShowConversionJS_base.dataLayer.orderStep : 0), 729 'option': anchor.attr('title').trim() 730 } 731 } 732 }, 733 'eventCallback': function () { 734 document.location = anchor.attr('href'); 735 } 736 737 }; 738 739 PShowConversionJS_base.dataLayer.push(checkoutOption); 740 741 return false;
742 }); 743 /** 744 * End of Measuring Checkout Options 745 */ 746 747 /** 748 * Measuring Checkout Steps 749 * https://developers.google.com/tag-manager/enhanced-ecommerce#checkout_option 750 */ 751 if (typeof PShowConversionJS_base.dataLayer.orderOpc !== 'undefined') { 752 753 if ($('.delivery_options').length && PShowConversionJS_base.dataLayer.orderOpc === 0) { 754 PShowConversionJS_base.dataLayer.orderStep = 3; 755 } 756 757 if ($('.payment_module').length && PShowConversionJS_base.dataLayer.orderOpc === 0) { 758 PShowConversionJS_base.dataLayer.orderStep = 4; 759 } 760 761 if (PShowConversionJS_base.dataLayer.controller === 'orderconfirmation') { 762 PShowConversionJS_base.dataLayer.orderStep = 5; 763 } 764 765 if (PShowConversionJS_base.dataLayer.orderOpc === 0 && PShowConversionJS_base.dataLayer.orderStep === null) { 766 PShowConversionJS_base.dataLayer.orderStep = 1; 767 } 768 769 var fullData = {'event': 'checkout', 'ecommerce': {'checkout': {}}}; 770 771 if (PShowConversionJS_base.dataLayer.orderStep > 0) { 772 if (PShowConversionJS_base.dataLayer.debug) { 773 PShowConversionJS_base.dataLayer.log("order step: " + PShowConversionJS_base.dataLayer.orderStep); 774 } 775 776 fullData.ecommerce.checkout.actionField = {'step': PShowConversionJS_base.dataLayer.orderStep}; 777 } else { 778 if (PShowConversionJS_base.dataLayer.debug) { 779 PShowConversionJS_base.dataLayer.log("order opc"); 780 } 781 } 782 783 if ($('#cart_summary').length) { 784 var products = []; 785 786 $('#cart_summary .cart_item').each(function () { 787 var productDetails = { 788 'id': parseInt($(this).attr('id').replace('product_', '')), 789 'name': $(this).find('.product-name').text().trim(), 790 'quantity': parseInt($(this).find('.cart_quantity_input').val()) 791 }; 792 793 var variantElement = $(this).find('.cart_ref').next('small'); 794 if (variantElement.length) { 795 items = variantElement.text().split(','); 796 productDetails.variant = ''; 797 for (var i in items) { 798 productDetails.variant += ' ' + items[i].replace(/.*\: (.*)/, '$1'); 799 } 800 productDetails.variant = productDetails.variant.trim(); 801 } 802 803 products.push(productDetails); 804 }); 805 806 if (products.length) { 807 fullData.ecommerce.checkout.products = products; 808 }/* global id_product, combinations, attributesCombinations, trackingAdsConversionId, trackingAdsConversionLabel */ 809 810 /** 811 * File from https://prestashow.pl 812 * 813 * DISCLAIMER 814 * Do not edit or add to this file if you wish to upgrade this module to newer 815 * versions in the future. 816 * 817 * @authors PrestaShow.pl <[email protected]> 818 * @copyright 2018 PrestaShow.pl 819 * @license https://prestashow.pl/license 820 */ 821 822 PShowConversionJS_base.dataLayer.productListImpressionInterval = function (listObj, listId) { 823 824 if (!listObj.is(':visible')) { 825 return; 826 } 827 828 clearInterval(PShowConversionJS_base.dataLayer.intervals[listId]); 829 830 var gtmProducts = []; 831 832 var bodyId = $('body').attr('id'); 833 834 var listName = ''; 835 if (bodyId && bodyId === 'search') { 836 listName = 'Search results'; 837 } else if (typeof listId !== 'undefined' && listId.length) { 838 listName = listId; 839 } 840 841 var products = listObj.find('.product-container'); 842 843 if (PShowConversionJS_base.dataLayer.debug) { 844 PShowConversionJS_base.dataLayer.log("found " + products.length 845 + " products on the list: " + listName); 846 } 847 848 var position = 0; 849 if (listObj.parents('.center_column').length && bodyId !== 'index') { 850 position = PShowConversionJS_base.dataLayer.currentPage * PShowConversionJS_base.dataLayer.ps_products_per_page; 851 } 852 853 products.each(function () { 854 855 ++position; 856 857 var productDetails = { 858 'name': $(this).find('[itemprop="name"]').text().trim(), 859 'price': $(this).find('[itemprop="price"]').text().trim() 860 .replace(/([^0-9\.\,]+)/g, '').replace(',', '.'), 861 'position': position 862 }; 863 864 if (listName) { 865 productDetails.list = listName; 866 } 867 868 gtmProducts.push(productDetails); 869 870 }); 871 872 var fullData = {'event': 'impressions', 'ecommerce': {'impressions': gtmProducts}}; 873 874 PShowConversionJS_base.dataLayer.push(fullData); 875 876 // ads - dynamic remarketing 877 // PShowConversionJS_base.dataLayer.push({ 878 // 'event': 'view_item_list', 879 // 'items': gtmProducts 880 // }); 881 882 }; 883 884 PShowConversionJS_base.dataLayer.initGTMMeasuring = function () { 885 886 if (!PShowConversionJS_base.dataLayer.active) { 887 return; 888 } 889 890 // try to get page from request uri 891 PShowConversionJS_base.dataLayer.currentPage = parseInt(document.location.href.replace(/.*p=([0-9]+).*/, '$1')); 892 if (isNaN(PShowConversionJS_base.dataLayer.currentPage)) { 893 // try to get page from url hash 894 PShowConversionJS_base.dataLayer.currentPage = parseInt(document.location.href.replace(/.*page-([0-9]+).*/, '$1')); 895 } 896 if (isNaN(PShowConversionJS_base.dataLayer.currentPage)) { 897 // set default page 898 PShowConversionJS_base.dataLayer.currentPage = 1; 899 } 900 PShowConversionJS_base.dataLayer.currentPage -= 1; 901 902 903 /* 904 * Measuring Product Impressions 905 * https://developers.google.com/tag-manager/enhanced-ecommerce#product-impressions 906 */ 907 var productLists = $('.product_list'); 908 909 if (productLists.length) { 910 911 if (PShowConversionJS_base.dataLayer.debug) { 912 PShowConversionJS_base.dataLayer.log("found " + productLists.length + " product lists"); 913 } 914 915 var listNum = 0; 916 917 productLists.each(function () { 918 919 ++listNum; 920 921 var listObj = $(this); 922 var listId = listObj.attr('id'); 923 924 if (!listId) { 925 listId = $('body').attr('id') + "_listnum_" + listNum; 926 } 927 928 PShowConversionJS_base.dataLayer.intervals[listId] = setInterval(function () { 929 PShowConversionJS_base.dataLayer.productListImpressionInterval(listObj, listId); 930 }, 3000); 931 932 }); 933 934 } 935 /* 936 * End of Measuring Product Impressions 937 */ 938 939 /* 940 * Measuring Views of Product Details 941 * https://developers.google.com/tag-manager/enhanced-ecommerce#product-impressions 942 */ 943 if ($('body').attr('id') === 'product') { 944
945 var productContainer = $('#main[itemtype="https://schema.org/Product"]'); 946 if (!productContainer.length) { 947 productContainer = $('#main[itemtype="http://schema.org/Product"]'); 948 } 949 if (!productContainer.length) { 950 productContainer = $('[itemtype="https://schema.org/Product"]:first'); 951 } 952 if (!productContainer.length) { 953 productContainer = $('[itemtype="http://schema.org/Product"]:first'); 954 } 955 956 // prepare product details 957 var productDetails = {}; 958 959 // append product name 960 if (productContainer.find('h1[itemprop="name"]').length) { 961 productDetails.name = productContainer.find('h1[itemprop="name"]:first').text().trim(); 962 } else if (productContainer.find('[itemprop="name"]').length) { 963 productDetails.name = productContainer.find('[itemprop="name"]:first').text().trim(); 964 } 965 966 // append product id 967 var productId = parseInt($('body').attr('class').replace(/.*product\-([0-9]+).*/, '$1')); 968 if (isNaN(productId) && typeof id_product !== 'undefined' && !isNaN(id_product)) { 969 productId = id_product; 970 } 971 if (!isNaN(productId)) { 972 productDetails.id = productId; 973 974 // append product price 975 if (productContainer.find('[itemprop="price"]').length) { 976 var price = productContainer.find('[itemprop="price"]:first').attr('content'); 977 if (typeof price === 'undefined') { 978 price = productContainer.find('[itemprop="price"]:first').text(); 979 } 980 productDetails.price = price.trim().replace(/([^0-9.,]+)/, '').replace(',', '.'); 981 } 982 983 // append product category 984 if ($('.breadcrumb a').length) { 985 productDetails.category = $('.breadcrumb a').last() 986 .closest('li').prev('li').find('a').text().trim() 987 .toLowerCase().replace(' ', '-'); 988 } 989 990 if (PShowConversionJS_base.dataLayer.debug) { 991 PShowConversionJS_base.dataLayer.log("displayed details of the product #" + productDetails.id); 992 } 993 994 PShowConversionJS_base.getProductDetails([productDetails.id], function (_productDetails) { 995 if (_productDetails) { 996 productDetails = Object.assign(productDetails, _productDetails[productDetails.id]); 997 } 998 999 var ecommerce = { 1000 'detail': { 1001 'actionField': { 1002 'list': 'product-page' 1003 }, 1004 'products': [productDetails] 1005 } 1006 }; 1007 var currency = PShowConversionJS_base.getCurrencyIsoCode(); 1008 if (currency) { 1009 ecommerce.currencyCode = currency; 1010 } 1011 1012 var fullData = { 1013 'event': 'productDetailImpression', 'ecommerce': ecommerce 1014 }; 1015 1016 // push event 1017 PShowConversionJS_base.dataLayer.push(fullData); 1018 1019 // ads - dynamic remarketing 1020 // PShowConversionJS_base.dataLayer.push({ 1021 // 'event': 'view_item', 1022 // 'value': productDetails.price, 1023 // 'items': [{ 1024 // 'id': productDetails.id, 1025 // 'google_business_vertical': 'retail' 1026 // }] 1027 // }); 1028 }); 1029 1030 // var fullData = { 1031 // 'event': 'detail', 'ecommerce': {'detail': {'products': [productDetails]}} 1032 // }; 1033 // 1034 // // push event 1035 // PShowConversionJS_base.dataLayer.push(fullData); 1036 1037 // ads - dynamic remarketing 1038 // PShowConversionJS_base.dataLayer.push({ 1039 // 'event': 'view_item', 1040 // 'value': productDetails.price, 1041 // 'items': [{ 1042 // 'id': productDetails.id, 1043 // 'google_business_vertical': 'retail' 1044 // }] 1045 // }); 1046 1047 } 1048 } 1049 /* 1050 * End of Measuring Views of Product Details 1051 */ 1052 1053 /* 1054 * Measuring Product Clicks 1055 * https://developers.google.com/tag-manager/enhanced-ecommerce#product-clicks 1056 */ 1057 $(document).on('click', '.product-container a:not(.quick-view):not(.ajax_add_to_cart_button)', function (e) { 1058 1059 e.preventDefault(); 1060 1061 // give half second for script to push event and redirect 1062 setTimeout(function () { 1063 document.location = productUrl; 1064 }, 500); 1065
1066 var productContainer = $(this).closest('.product-container'); 1067 if (!productContainer.length) { 1068 productContainer = $('#main[itemtype="https://schema.org/Product"]'); 1069 } 1070 if (!productContainer.length) { 1071 productContainer = $('#main[itemtype="http://schema.org/Product"]'); 1072 } 1073 if (!productContainer.length) { 1074 productContainer = $('[itemtype="https://schema.org/Product"]:first'); 1075 } 1076 if (!productContainer.length) { 1077 productContainer = $('[itemtype="http://schema.org/Product"]:first'); 1078 } 1079 1080 var productUrl = $(this).attr('href').trim(); 1081 1082 if (productContainer.find('h1[itemprop="name"]').length) { 1083 productName = productContainer.find('h1[itemprop="name"]:first').text().trim(); 1084 } else if (productContainer.find('[itemprop="name"]').length) { 1085 productName = productContainer.find('[itemprop="name"]:first').text().trim(); 1086 } else { 1087 return; 1088 } 1089 1090 // find position of the clicked item 1091 var position = parseInt(productContainer.index('.product-container')) + 1; 1092 position += PShowConversionJS_base.dataLayer.currentPage * PShowConversionJS_base.dataLayer.ps_products_per_page; 1093 1094 // prepare product details 1095 var productDetails = { 1096 'name': productName, 1097 'id': productUrl.replace(/.*id_product=([0-9]+).*/, '$1'), 1098 'price': productContainer.find('[itemprop="price"]').text().trim() 1099 .replace(/([^0-9\.\,]+)/g, '').replace(',', '.'), 1100 'position': position, 1101 }; 1102 if (isNaN(productDetails.id)) { 1103 productDetails.id = productUrl.replace(/.*([0-9]+).*\.html/, '$1'); 1104 } 1105 1106 if (PShowConversionJS_base.dataLayer.debug) { 1107 PShowConversionJS_base.dataLayer.log("clicked on product " + productDetails.name); 1108 PShowConversionJS_base.dataLayer.log(productDetails, true); 1109 } 1110 1111 var fullData = { 1112 'event': 'productClick', 1113 'ecommerce': {'click': {'products': [productDetails]}}, 1114 'eventCallback': function () { 1115 // redirect to the product page 1116 document.location = productUrl; 1117 } 1118 }; 1119 1120 // push event 1121 PShowConversionJS_base.dataLayer.push(fullData); 1122 1123 return false; 1124 }); 1125 /* 1126 * End of Measuring Product Clicks 1127 */ 1128 1129 /* 1130 * Measuring Additions to a Shopping Cart 1131 * https://developers.google.com/tag-manager/enhanced-ecommerce#add 1132 */ 1133 $(document).on('click', '.ajax_add_to_cart_button', function (e) { 1134 1135 // var productContainer = $(this).closest('.product-container'); 1136 var productContainer = $('#main[itemtype="https://schema.org/Product"]'); 1137 if (!productContainer.length) { 1138 productContainer = $('#main[itemtype="http://schema.org/Product"]'); 1139 } 1140 if (!productContainer.length) { 1141 productContainer = $('[itemtype="https://schema.org/Product"]:first'); 1142 } 1143 if (!productContainer.length) { 1144 productContainer = $('[itemtype="http://schema.org/Product"]:first'); 1145 } 1146
1147 var productUrl = productContainer.find(".lnk_view").attr('href').trim(); 1148 1149 if (productContainer.find('h1[itemprop="name"]').length) { 1150 productName = productContainer.find('h1[itemprop="name"]:first').text().trim(); 1151 } else if (productContainer.find('[itemprop="name"]').length) { 1152 productName = productContainer.find('[itemprop="name"]:first').text().trim(); 1153 } else { 1154 return; 1155 } 1156 1157 // prepare product details 1158 var productDetails = { 1159 'name': productName, 1160 'id': productUrl.replace(/.*id_product=([0-9]+).*/, '$1'), 1161 'price': productContainer.find('[itemprop="price"]').text().trim() 1162 .replace(/([^0-9\.\,]+)/, '').replace(',', '.'), 1163 'quantity': 1 1164 }; 1165 if (isNaN(productDetails.id)) { 1166 productDetails.id = productUrl.replace(/.*([0-9]+).*\.html/, '$1'); 1167 } 1168 1169 if (PShowConversionJS_base.dataLayer.debug) { 1170 PShowConversionJS_base.dataLayer.log("added product to cart " + productDetails.id); 1171 } 1172 1173 var fullData = { 1174 'event': 'addToCart', 1175 'ecommerce': {'add': {'products': [productDetails]}} 1176 }; 1177 1178 // push event 1179 PShowConversionJS_base.dataLayer.push(fullData); 1180 1181 // ads - dynamic remarketing 1182 // PShowConversionJS_base.dataLayer.push({ 1183 // 'event': 'add_to_cart', 1184 // 'value': productDetails.price, 1185 // 'items': [{ 1186 // 'id': productDetails.id, 1187 // 'google_business_vertical': 'custom' 1188 // }] 1189 // }); 1190 1191 }); 1192 $(document).on('click', '#add_to_cart input, #add_to_cart button', function (e) { 1193 1194 // prepare product details 1195 var productDetails = { 1196 'name': $("[itemprop=\"name\"]").eq(0).text().trim(), 1197 'id': $('#product_page_product_id').val(), 1198 'price': $("[itemprop=\"price\"]").eq(0).text().trim() 1199 .replace(/([^0-9\.\,]+)/, '').replace(',', '.'), 1200 'quantity': $('#quantity_wanted').val() 1201 }; 1202 1203 if (PShowConversionJS_base.dataLayer.debug) { 1204 PShowConversionJS_base.dataLayer.log("added product to cart " + productDetails.id); 1205 } 1206 1207 // find selected combination and 1208 // prepare variant string (selected attributes separated by comma and space) 1209 var idCombination = parseInt($('#idCombination').val()); 1210 if (!isNaN(idCombination) && idCombination && 1211 (typeof combinations !== 'undefined' && 1212 typeof attributesCombinations !== 'undefined')) { 1213 1214 // find id's of the selected attributes 1215 var idsAttributes = []; 1216 for (var x in combinations) { 1217 if (parseInt(combinations[x].idCombination) === idCombination) { 1218 idsAttributes = combinations[x].idsAttributes; 1219 break; 1220 } 1221 } 1222 1223 if (idsAttributes.length) { 1224 productDetails.variant = ''; 1225 1226 for (var x in idsAttributes) { 1227 for (var y in attributesCombinations) { 1228 if (parseInt(idsAttributes[x]) === parseInt(attributesCombinations[y].id_attribute)) { 1229 productDetails.variant += attributesCombinations[y].attribute.ucfirst() + ', '; 1230 break; 1231 } 1232 } 1233 } 1234 1235 productDetails.variant = productDetails.variant.trim(); 1236 productDetails.variant = productDetails.variant.substr(0, (productDetails.variant.length - 1)); 1237 } 1238 } 1239 1240 var fullData = { 1241 'event': 'addToCart', 1242 'ecommerce': {'add': {'products': [productDetails]}} 1243 }; 1244 1245 // push event 1246 PShowConversionJS_base.dataLayer.push(fullData); 1247 1248 // ads - dynamic remarketing 1249 // PShowConversionJS_base.dataLayer.push({ 1250 // 'event': 'add_to_cart', 1251 // 'value': productDetails.price, 1252 // 'items': [{ 1253 // 'id': productDetails.id, 1254 // 'google_business_vertical': 'custom' 1255 // }] 1256 // }); 1257 1258 }); 1259 $(document).on('click', '.cart_quantity_up', function (e) { 1260 1261 // find product id 1262 var productId = parseInt($(this).attr('id').replace('cart_quantity_up_', '')); 1263 1264 if (PShowConversionJS_base.dataLayer.debug) { 1265 PShowConversionJS_base.dataLayer.log("changed quantity (+1) for product " + productId); 1266 } 1267 1268 // prepare product details 1269 var productDetails = { 1270 'id': productId, 1271 'quantity': 1 1272 }; 1273 1274 var fullData = { 1275 'event': 'addToCart', 1276 'ecommerce': {'add': {'products': [productDetails]}} 1277 }; 1278 1279 // push event 1280 PShowConversionJS_base.dataLayer.push(fullData); 1281 1282 // ads - dynamic remarketing 1283 // PShowConversionJS_base.dataLayer.push({ 1284 // 'event': 'add_to_cart', 1285 // 'value': productDetails.price, 1286 // 'items': [{ 1287 // 'id': productDetails.id, 1288 // 'google_business_vertical': 'custom' 1289 // }] 1290 // }); 1291 1292 }); 1293 /* 1294 * End of Measuring Additions to a Shopping Cart 1295 */ 1296 1297 /* 1298 * Measuring Removals from a Shopping Cart 1299 * https://developers.google.com/tag-manager/enhanced-ecommerce#add 1300 */ 1301 $(document).on('click', '.ajax_cart_block_remove_link', function (e) { 1302 1303 // customized product management 1304 var customizationId = 0; 1305 var productId = 0; 1306 var customizableProductDiv = $($(this).parent().parent()) 1307 .find("div[id^=devareCustomizableProduct_]"); 1308 1309 if (customizableProductDiv && $(customizableProductDiv).length) { 1310 $(customizableProductDiv).each(function () { 1311 var ids = $(this).attr('id').split('_'); 1312 if (typeof (ids[1]) !== 'undefined') { 1313 customizationId = parseInt(ids[1]); 1314 productId = parseInt(ids[2]); 1315 return false;
1316 } 1317 }); 1318 } 1319 1320 // common product management 1321 if (!customizationId) { 1322 try { 1323 // retrieve idProduct and idCombination from the displayed product in the block cart 1324 var firstCut = $(this).parent().parent() 1325 .attr('id').replace('cart_block_product_', ''); 1326 firstCut = firstCut.replace('devareCustomizableProduct_', ''); 1327 ids = firstCut.split('_'); 1328 productId = parseInt(ids[0]); 1329 } catch (e) { 1330 PShowConversionJS_base.dataLayer.error(e); 1331 } 1332 } 1333 1334 if (PShowConversionJS_base.dataLayer.debug) { 1335 PShowConversionJS_base.dataLayer.log("removed product from cart " + productId); 1336 } 1337 1338 // prepare product details 1339 var productDetails = { 1340 'id': productId 1341 }; 1342 1343 var productQty = parseInt($($(this).parent().parent()) 1344 .find(".quantity").text()); 1345 if (!isNaN(productQty) && productQty > 0) { 1346 productDetails.quantity = productQty; 1347 } 1348 1349 productDetails.variant = $($(this).parent().parent()).find(".product-atributes").text().trim(); 1350 1351 var fullData = { 1352 'event': 'removeFromCart', 1353 'ecommerce': {'remove': {'products': [productDetails]}} 1354 }; 1355 1356 // push event 1357 PShowConversionJS_base.dataLayer.push(fullData); 1358 1359 }); 1360 $(document).on('click', '.cart_quantity_devare', function (e) { 1361 1362 // find product id 1363 var productId = parseInt($(this).attr('id')); 1364 1365 if (PShowConversionJS_base.dataLayer.debug) { 1366 PShowConversionJS_base.dataLayer.log("removed product from cart " + productId); 1367 } 1368 1369 // prepare product details 1370 var productDetails = { 1371 'id': productId 1372 }; 1373 1374 var fullData = { 1375 'event': 'removeFromCart', 1376 'ecommerce': {'remove': {'products': [productDetails]}} 1377 }; 1378 1379 // push event 1380 PShowConversionJS_base.dataLayer.push(fullData); 1381 1382 }); 1383 $(document).on('click', '.cart_quantity_down', function (e) { 1384 1385 // find product id 1386 var productId = parseInt($(this).attr('id').replace('cart_quantity_down_', '')); 1387 1388 if (PShowConversionJS_base.dataLayer.debug) { 1389 PShowConversionJS_base.dataLayer.log("changed quantity (-1) for product " + productId); 1390 } 1391 1392 // prepare product details 1393 var productDetails = { 1394 'id': productId, 1395 'quantity': 1 1396 }; 1397 1398 var fullData = { 1399 'event': 'removeFromCart', 1400 'ecommerce': {'remove': {'products': [productDetails]}} 1401 }; 1402 1403 // push event 1404 PShowConversionJS_base.dataLayer.push(fullData); 1405 1406 }); 1407 /* 1408 * End of Measuring Removals from a Shopping Cart 1409 */ 1410 1411 /* 1412 * Measuring Additions and Removals from a Shopping Cart 1413 * https://developers.google.com/tag-manager/enhanced-ecommerce#add 1414 */ 1415 $(document).on('focusin', '.cart_quantity_input', function (e) { 1416 // save current value 1417 $(this).data('val', $(this).val()); 1418 1419 if (PShowConversionJS_base.dataLayer.debug) { 1420 PShowConversionJS_base.dataLayer.log("saved current quantity: " + $(this).val()); 1421 } 1422 }); 1423 $(document).on('change', '.cart_quantity_input', function (e) { 1424 1425 if (PShowConversionJS_base.dataLayer.debug) { 1426 PShowConversionJS_base.dataLayer.log("changed quantity to: " + $(this).val()); 1427 } 1428 1429 // find product id 1430 var productId = parseInt($(this).attr('name').replace('quantity_', '')); 1431 1432 // find quantities 1433 var newQty = parseInt($(this).val()); 1434 var oldQty = parseInt($(this).data('val')); 1435 var difference = Math.abs(newQty - oldQty); 1436 if (!difference) { 1437 return; 1438 } 1439 1440 // prepare product details 1441 var productDetails = { 1442 'id': productId, 1443 'quantity': difference 1444 }; 1445 1446 var fullData = { 1447 'event': ((newQty > oldQty) ? 'addToCart' : 'removeFromCart'), 1448 'ecommerce': ((newQty > oldQty) ? 1449 {'add': {'products': [productDetails]}} : 1450 {'remove': {'products': [productDetails]}} 1451 ) 1452 }; 1453 1454 // push event 1455 PShowConversionJS_base.dataLayer.push(fullData); 1456 1457 }); 1458 /* 1459 * End of Measuring Removals from a Shopping Cart 1460 */ 1461 1462 /** 1463 * Measuring Checkout Options 1464 * https://developers.google.com/tag-manager/enhanced-ecommerce#checkout_option 1465 */ 1466 $(document).on('change', 'input.delivery_option_radio', function () { 1467 1468 if (PShowConversionJS_base.dataLayer.debug) { 1469 PShowConversionJS_base.dataLayer.log("changed shipping method"); 1470 } 1471 1472 var optionValue = $(this).val(); 1473 if ((temp = $(this).closest('tr')) && temp.length && 1474 (temp = temp.find('td.delivery_option_logo')) && temp.length && 1475 (temp = temp.next('td')) && temp.length && 1476 (temp = temp.find('strong')) && temp.length) { 1477 optionValue = temp.text().trim(); 1478 } 1479 1480 var checkoutOption = { 1481 'event': 'checkoutOption', 1482 'ecommerce': { 1483 'checkoutOption': { 1484 'actionField': { 1485 'step': (PShowConversionJS_base.dataLayer.orderStep ? PShowConversionJS_base.dataLayer.orderStep : 0), 1486 'option': optionValue 1487 } 1488 } 1489 } 1490 }; 1491 1492 PShowConversionJS_base.dataLayer.push(checkoutOption); 1493 }); 1494 1495 $(document).on('click', '.payment_module a', function (e) { 1496 1497 // give half second for script to push event and redirect 1498 setTimeout(function () { 1499 document.location = anchor.attr('href'); 1500 }, 500); 1501 1502 e.preventDefault(); 1503 1504 if (PShowConversionJS_base.dataLayer.debug) { 1505 PShowConversionJS_base.dataLayer.log("selected payment method"); 1506 } 1507 1508 var anchor = $(this); 1509 1510 var checkoutOption = { 1511 'event': 'checkoutOption', 1512 'ecommerce': { 1513 'checkoutOption': { 1514 'actionField': { 1515 'step': (PShowConversionJS_base.dataLayer.orderStep ? PShowConversionJS_base.dataLayer.orderStep : 0), 1516 'option': anchor.attr('title').trim() 1517 } 1518 } 1519 }, 1520 'eventCallback': function () { 1521 document.location = anchor.attr('href'); 1522 } 1523 1524 }; 1525 1526 PShowConversionJS_base.dataLayer.push(checkoutOption); 1527 1528 return false;
1529 }); 1530 /** 1531 * End of Measuring Checkout Options 1532 */ 1533 1534 /** 1535 * Measuring Checkout Steps 1536 * https://developers.google.com/tag-manager/enhanced-ecommerce#checkout_option 1537 */ 1538 if (typeof PShowConversionJS_base.dataLayer.orderOpc !== 'undefined') { 1539 1540 if ($('.delivery_options').length && PShowConversionJS_base.dataLayer.orderOpc === 0) { 1541 PShowConversionJS_base.dataLayer.orderStep = 3; 1542 } 1543 1544 if ($('.payment_module').length && PShowConversionJS_base.dataLayer.orderOpc === 0) { 1545 PShowConversionJS_base.dataLayer.orderStep = 4; 1546 } 1547 1548 if (PShowConversionJS_base.dataLayer.controller === 'orderconfirmation') { 1549 PShowConversionJS_base.dataLayer.orderStep = 5; 1550 } 1551 1552 if (PShowConversionJS_base.dataLayer.orderOpc === 0 && PShowConversionJS_base.dataLayer.orderStep === null) { 1553 PShowConversionJS_base.dataLayer.orderStep = 1; 1554 } 1555 1556 var fullData = {'event': 'checkout', 'ecommerce': {'checkout': {}}}; 1557 1558 if (PShowConversionJS_base.dataLayer.orderStep > 0) { 1559 if (PShowConversionJS_base.dataLayer.debug) { 1560 PShowConversionJS_base.dataLayer.log("order step: " + PShowConversionJS_base.dataLayer.orderStep); 1561 } 1562 1563 fullData.ecommerce.checkout.actionField = {'step': PShowConversionJS_base.dataLayer.orderStep}; 1564 } else { 1565 if (PShowConversionJS_base.dataLayer.debug) { 1566 PShowConversionJS_base.dataLayer.log("order opc"); 1567 } 1568 } 1569 1570 if ($('#cart_summary').length) { 1571 var products = []; 1572 1573 $('#cart_summary .cart_item').each(function () { 1574 var productDetails = { 1575 'id': parseInt($(this).attr('id').replace('product_', '')), 1576 'name': $(this).find('.product-name').text().trim(), 1577 'quantity': parseInt($(this).find('.cart_quantity_input').val()) 1578 }; 1579 1580 var variantElement = $(this).find('.cart_ref').next('small'); 1581 if (variantElement.length) { 1582 items = variantElement.text().split(','); 1583 productDetails.variant = ''; 1584 for (var i in items) { 1585 productDetails.variant += ' ' + items[i].replace(/.*\: (.*)/, '$1'); 1586 } 1587 productDetails.variant = productDetails.variant.trim(); 1588 } 1589 1590 products.push(productDetails); 1591 }); 1592 1593 if (products.length) { 1594 fullData.ecommerce.checkout.products = products; 1595 } 1596 } 1597 1598 PShowConversionJS_base.dataLayer.push(fullData); 1599 } 1600 /** 1601 * End of Measuring Checkout Steps 1602 */ 1603 1604 /** 1605 * Measuring Purchases 1606 * https://developers.google.com/tag-manager/enhanced-ecommerce#purchases 1607 */ 1608 if (PShowConversionJS_base.dataLayer.controller === 'orderconfirmation' && 1609 PShowConversionJS_base.dataLayer.order !== null) { 1610 1611 var fullData = { 1612 'event': 'purchase', 'ecommerce': { 1613 'purchase': PShowConversionJS_base.dataLayer.order 1614 } 1615 }; 1616 PShowConversionJS_base.dataLayer.push(fullData); 1617 1618 if (typeof trackingAdsConversionId !== 'undefined' && typeof trackingAdsConversionLabel !== 'undefined') { 1619 PShowConversionJS_base.dataLayer.push( 1620 'event', 1621 'conversion', 1622 { 1623 'send_to': trackingAdsConversionId + '/' + trackingAdsConversionLabel, 1624 'value': PShowConversionJS_base.dataLayer.order['actionField']['revenue'], 1625 'currency': 'PLN', 1626 'transaction_id': PShowConversionJS_base.dataLayer.order['actionField']['id'] 1627 } 1628 ); 1629 } 1630 } 1631 /** 1632 * End of Measuring Purchases 1633 */ 1634 1635 }; 1636 1637 } 1638 1639 PShowConversionJS_base.dataLayer.push(fullData); 1640 } 1641 /** 1642 * End of Measuring Checkout Steps 1643 */ 1644 1645 /** 1646 * Measuring Purchases 1647 * https://developers.google.com/tag-manager/enhanced-ecommerce#purchases 1648 */ 1649 if (PShowConversionJS_base.dataLayer.controller === 'orderconfirmation' && 1650 PShowConversionJS_base.dataLayer.order !== null) { 1651 1652 var fullData = { 1653 'event': 'purchase', 'ecommerce': { 1654 'purchase': PShowConversionJS_base.dataLayer.order 1655 } 1656 }; 1657 PShowConversionJS_base.dataLayer.push(fullData); 1658 1659 if (typeof trackingAdsConversionId !== 'undefined' && typeof trackingAdsConversionLabel !== 'undefined') { 1660 PShowConversionJS_base.dataLayer.push( 1661 'event', 1662 'conversion', 1663 { 1664 'send_to': trackingAdsConversionId + '/' + trackingAdsConversionLabel, 1665 'value': PShowConversionJS_base.dataLayer.order['actionField']['revenue'], 1666 'currency': 'PLN', 1667 'transaction_id': PShowConversionJS_base.dataLayer.order['actionField']['id'] 1668 } 1669 ); 1670 } 1671 } 1672 /** 1673 * End of Measuring Purchases 1674 */ 1675 1676};
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.