1if ('undefined' !== typeof AEC && 'undefined' !== typeof AEC.EventDispatcher) 2{ 3 AEC.GA4 = (() => 4 { 5 return { 6 enabled: false, 7 transformCategories: function(category) 8 { 9 if (null === category) 10 { 11 return {}; 12 } 13 14 let map = {}, categories = category.toString().split('/'); 15 16 if (categories) 17 { 18 map['item_category'] = categories.shift(); 19 20 if (categories.length) 21 { 22 let index = 1; 23 24 categories.forEach(category => 25 { 26 map['item_category' + (++index)] = category; 27 }); 28 } 29 } 30 31 return map; 32 }, 33 augmentCategories: function(product) 34 { 35 if (product.hasOwnProperty('category')) 36 { 37 AEC.Cookie.augment([product]); 38 } 39 40 return this.transformCategories(product.category); 41 }, 42 augmentItem: function(product) 43 { 44 let map = {}; 45 46 map['google_business_vertical'] = 'retail'; 47 48 Object.entries(product).forEach(([key, value]) => 49 { 50 if (-1 === ['id','name','price','category','currency','variant','brand'].indexOf(key)) 51 { 52 map[key] = value; 53 } 54 }); 55 56 return map; 57 } 58 59 } 60 })(); 61 62 /** 63 * Modify checkout step option payloasd 64 */ 65 AEC.EventDispatcher.on('ec.checkout.step.option.data', data => 66 { 67 if (!AEC.GA4.enabled) 68 { 69 return true; 70 } 71
72 switch(parseInt(data.ecommerce.checkout_option.actionField.step)) 73 { 74 case AEC.Const.CHECKOUT_STEP_SHIPPING: 75 76 data['event'] = 'add_shipping_info'; 77 78 if (AEC.GA4.quote.hasOwnProperty('coupon')) 79 { 80 data.ecommerce['coupon'] = AEC.GA4.quote.coupon; 81 } 82 83 data.ecommerce['currency'] = AEC.GA4.currency; 84 85 data.ecommerce['items'] = AEC.Checkout.getPayload().ecommerce.items; 86 87 data.ecommerce['shipping_tier'] = data.ecommerce.checkout_option.actionField.option; 88 89 (data => 90 { 91 let value = 0; 92 93 data.ecommerce['items'].forEach(item => 94 { 95 value += Number(item.price) * Number(item.quantity); 96 }); 97 98 data.ecommerce['value'] = value; 99 100 })(data); 101 102 103 104 105 delete data.ecommerce.checkout_option; 106 107 break; 108 109 case AEC.Const.CHECKOUT_STEP_PAYMENT: 110 111 data['event'] = 'add_payment_info'; 112 113 if (AEC.GA4.quote.hasOwnProperty('coupon')) 114 { 115 data.ecommerce['coupon'] = AEC.GA4.quote.coupon; 116 } 117 118 data.ecommerce['currency'] = AEC.GA4.currency; 119 120 data.ecommerce['items'] = AEC.Checkout.getPayload().ecommerce.items; 121 122 data.ecommerce['payment_type'] = data.ecommerce.checkout_option.actionField.option; 123 124 (data => 125 { 126 let value = 0; 127 128 data.ecommerce['items'].forEach(item => 129 { 130 value += Number(item.price) * Number(item.quantity); 131 }); 132 133 data.ecommerce['value'] = value; 134 135 })(data); 136 137 138 139 delete data.ecommerce.checkout_option; 140 141 break; 142 } 143 }); 144}
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.