1//site URL: https://aywbxgub.elementor.cloud/ 2// This script tracks key Ecommerce events such as: 3// 1. "add_shipping_info" - Adds shipping info during the checkout 4// 2. "add_payment_info" - Adds payment info during the checkout 5// ============================ 6//File-Location : wp-content/themes/your-theme/js/GTM_shipping_payment.js 7//v1 8//paul john india 9console.log("loaded gtm file "); 10jQuery(document).ready(function ($) { 11 $(document).ajaxComplete(function (event, xhr, settings) { 12 if ( 13 settings.url.includes("checkout") && 14 xhr.responseText.includes('"result":"success"') 15 ) { 16 // Extract billing details 17 var billingDetails = { 18 email: $("#billing_email").val(), 19 phone: $("#billing_phone").val(), 20 first_name: $("#billing_first_name").val(), 21 last_name: $("#billing_last_name").val(), 22 company: $("#billing_company").val(), 23 country: $("#billing_country").val(), 24 address_1: $("#billing_address_1").val(), 25 address_2: $("#billing_address_2").val(), 26 city: $("#billing_city").val(), 27 state: $("#billing_state").val(), 28 postcode: $("#billing_postcode").val(), 29 }; 30 31 // Extract cart items 32 var cartItems = []; 33 $(".cart_item").each(function () { 34 var productName = $(this) 35 .find(".product-name") 36 .contents() 37 .first() 38 .text() 39 .trim(); 40 var quantityText = $(this).find(".product-name h6").text().trim(); 41 var quantity = parseInt(quantityText.replace(/\D/g, ""), 10) || 1; 42 var priceText = $(this).find(".woocommerce-Price-amount").text().trim(); 43 var price = parseFloat(priceText.replace(/[^\d.]/g, "")) || 0; 44 45 cartItems.push({ 46 name: productName, 47 price: price, 48 quantity: quantity, 49 }); 50 }); 51 52 // **Handle Two Types of Shipping Methods** 53 var selectedShippingElement = $("#shipping_method input:checked") 54 .closest("li") 55 .find("label"); 56 57 if (selectedShippingElement.length === 0) { 58 // If no radio button is selected, try the default shipping method (the one without radio buttons) 59 selectedShippingElement = $("#shipping_method") 60 .find("li label") 61 .first(); 62 } 63 64 var selectedShippingFullText = selectedShippingElement 65 .clone() 66 .children() 67 .remove() 68 .end() 69 .text() 70 .trim(); // Clean text 71 var shippingCostText = selectedShippingElement 72 .find(".woocommerce-Price-amount bdi") 73 .text() 74 .trim(); 75 var shippingCost = 76 parseFloat(shippingCostText.replace(/[^\d.]/g, "")) || 0; 77 78 // Extract shipping tier (remove extra text if present) 79 var selectedShipping = 80 selectedShippingFullText.split("(")[0].trim() || "Unknown"; 81 82 console.log("Selected Shipping Tier:", selectedShipping); 83 console.log("Shipping Cost:", shippingCost); 84 85 // Get total order value 86 var orderTotalText = $( 87 ".order-total .total-price .woocommerce-Price-amount" 88 ) 89 .text() 90 .trim(); 91 var orderTotal = parseFloat(orderTotalText.replace(/[^\d.]/g, "")) || 0; 92 93 console.log("Order Total:", orderTotal); 94 95 // **Extract Coupon Details** 96 var appliedCoupon = 97 $(".cart-discount .sub-total-title") 98 .text() 99 .replace("Coupon:", "") 100 .trim() || "None"; 101 var discountText = $( 102 ".cart-discount .sub-total-price .woocommerce-Price-amount" 103 ) 104 .text() 105 .trim(); 106 var discountAmount = parseFloat(discountText.replace(/[^\d.]/g, "")) || 0; 107 108 // Push shipping info to DataLayer 109 window.dataLayer = window.dataLayer || []; 110 window.dataLayer.push({ 111 event: "add_shipping_info", 112 ecommerce: { 113 currency: "INR", 114 value: orderTotal, 115 shipping_tier: selectedShipping, 116 shipping_cost: shippingCost, 117 billing_details: billingDetails, 118 coupon: appliedCoupon, 119 discount: discountAmount, 120 items: cartItems, 121 }, 122 }); 123 124 // Get selected payment method 125 var selectedPayment = 126 $("#payment input[name='payment_method']:checked") 127 .closest("li") 128 .find("label") 129 .text() 130 .trim() || "Unknown"; 131 132 console.log("Selected Payment Method:", selectedPayment); 133 134 // Push payment info to DataLayer 135 window.dataLayer.push({ 136 event: "add_payment_info", 137 payment_method: selectedPayment, 138 }); 139 } 140 }); 141});
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.