1let shippingInfoTracked = false, paymentInfoTracked = false; 2let analytics = { 3 arrival: false, 4 departure: false, 5 range: false, 6 nights: false, 7 value: false, 8 units: [] 9}; 10(function ($, global, undefined) { 11 $(function () { 12 // Get details about their search/selection 13 var arrival = $('#arrival').val(); 14 var departure = $('#depart').val(); 15 if (typeof arrival == 'string' && arrival.length) { 16 analytics.arrival = arrival; 17 if (departure.length) { 18 analytics.departure = departure; 19 var arrivalDate = new Date(arrival); 20 var departureDate = new Date(departure); 21 var range = arrivalDate.toISOString().split('T')[0] + ':' + departureDate.toISOString().split('T')[0]; 22 analytics.range = range; 23 var oneDay = 1000 * 60 * 60 * 24; 24 var nights = Math.abs(Math.ceil((arrivalDate.getTime() - departureDate.getTime()) / oneDay)); 25 analytics.nights = nights; 26 } 27 } else { 28 // unit scope 29 var arrival = $('#check-availability-arrival-date').val(); 30 var departure = $('#check-availability-departure-date').val(); 31 if (typeof arrival == 'string' && arrival.length) { 32 analytics.arrival = arrival; 33 if (departure.length) { 34 analytics.departure = departure; 35 var arrivalDate = new Date(arrival); 36 var departureDate = new Date(departure); 37 var range = arrivalDate.toISOString().split('T')[0] + ':' + departureDate.toISOString().split('T')[0]; 38 analytics.range = range; 39 var oneDay = 1000 * 60 * 60 * 24; 40 var nights = Math.abs(Math.ceil((arrivalDate.getTime() - departureDate.getTime()) / oneDay)); 41 analytics.nights = nights; 42 } 43 } else { 44 // booking scope 45 var arrival = $('input[name="booking[arrival]"]').val(); 46 var departure = $('input[name="booking[depart]"]').val(); 47 if (typeof arrival == 'string' && arrival.length) { 48 analytics.arrival = arrival; 49 if (departure.length) { 50 analytics.departure = departure; 51 var arrivalDate = new Date(arrival); 52 var departureDate = new Date(departure); 53 var range = arrivalDate.toISOString().split('T')[0] + ':' + departureDate.toISOString().split('T')[0]; 54 analytics.range = range; 55 var oneDay = 1000 * 60 * 60 * 24; 56 var nights = Math.abs(Math.ceil((arrivalDate.getTime() - departureDate.getTime()) / oneDay)); 57 analytics.nights = nights; 58 } 59 } 60 } 61 } 62 if ($('.abe-results .abe-item').length > 0) { 63 // view_item_list 64 analytics.units = []; 65 $('.abe-results .abe-item').each(function (i, item) { 66 var unit = $(item); 67 analytics.units.push({ 68 item_id: unit.data('vrp-property-code'), 69 item_name: unit.data('vrp-name'), 70 affiliation: 'Reservations', 71 index: unit.data('vrp-index'), 72 item_brand: unit.data('vrp-type'), 73 item_category: unit.data('vrp-beds') + ' Bedrooms', 74 item_category2: unit.data('vrp-baths') + ' Bathrooms', 75 item_category3: 'Sleeps ' + unit.data('vrp-sleeps'), 76 item_category4: analytics.range, 77 item_category5: analytics.nights ? (analytics.nights + ' Nights') : false 78 }); 79 }); 80 updateDataLayer('view_item_list'); 81 $('.abe-results .abe-item a').click(function (e) { 82 //select_item 83 var unit = $(this).closest('.abe-item'); 84 analytics.units = []; 85 analytics.units.push({ 86 item_id: unit.data('vrp-property-code'), 87 item_name: unit.data('vrp-name'), 88 affiliation: 'Reservations', 89 index: unit.data('vrp-index'), 90 item_brand: unit.data('vrp-type'), 91 item_category: unit.data('vrp-beds') + ' Bedrooms', 92 item_category2: unit.data('vrp-baths') + ' Bathrooms', 93 item_category3: 'Sleeps ' + unit.data('vrp-sleeps'), 94 item_category4: analytics.range, 95 item_category5: analytics.nights ? (analytics.nights + ' Nights') : false 96 }); 97 updateDataLayer('select_item'); 98 }); 99 } 100 if ($('.abe.abe-unit').length > 0) { 101 var unit = $('.abe.abe-unit .abe-unit-info'); 102 analytics.units = []; 103 analytics.units.push({ 104 item_id: unit.data('unit-property-code'), 105 item_name: unit.data('unit-name'), 106 affiliation: 'Reservations', 107 index: unit.data('unit-index'),
108 item_brand: unit.data('unit-type'), 109 item_category: unit.data('unit-beds') + ' Bedrooms', 110 item_category2: unit.data('unit-baths') + ' Bathrooms', 111 item_category3: 'Sleeps ' + unit.data('unit-sleeps'), 112 item_category4: analytics.range, 113 item_category5: analytics.nights ? (analytics.nights + ' Nights') : false 114 }); 115 updateDataLayer('view_item'); 116 $('*#booklink').click(function (e) { 117 var price = parseFloat($('#ratebreakdown .double .rate-breakdown-value').html().replace(new RegExp(/[^0-9.]/g), '')); 118 analytics.units[0].currency = 'USD'; 119 analytics.units[0].price = Math.round((price + Number.EPSILON) * 100) / 100; 120 analytics.units[0].quantity = 1; 121 updateDataLayer('add_to_cart'); 122 }); 123 } 124 $('.abe-favorite:not(.active)').click(function () { 125 // double check .active 126 if (!$(this).hasClass('active')) { 127 // todo 128 } 129 }); 130 if ($('#vrpbookform').length > 0) { 131 analytics.units = []; 132 var unit = $('#vrpbookform'); 133 var price = parseFloat($('input[name="booking[TotalCost]"]').val()); 134 analytics.units.push({ 135 item_id: unit.data('unit-property-code'), 136 item_name: unit.data('unit-name'), 137 affiliation: 'Reservations', 138 item_brand: unit.data('unit-type'), 139 item_category: unit.data('unit-beds') + ' Bedrooms', 140 item_category2: unit.data('unit-baths') + ' Bathrooms', 141 item_category3: 'Sleeps ' + unit.data('unit-sleeps'), 142 item_category4: analytics.range, 143 item_category5: analytics.nights ? (analytics.nights + ' Nights') : false, 144 currency: 'USD', 145 price: Math.round((price + Number.EPSILON) * 100) / 100, 146 quantity: 1 147 }); 148 updateDataLayer('begin_checkout'); 149 // shipping info (personal information) 150 $('#vrpbookform input, #vrpbookform select').change(function () { 151 var requiredFields = { 152 'fname': 'input', 153 'lname': 'input', 154 'address': 'input', 155 'city': 'input', 156 'state': 'select', 157 'zip': 'input', 158 'country': 'select', 159 'phone': 'input', 160 'email': 'input' 161 }; 162 var valid = 0; 163 for (name in requiredFields) { 164 var field = $(requiredFields[name] + '[name="booking[' + name + ']"]'); 165 if (field.val().replace(new RegExp(/[\s\r\t\n]+/g)).length > 0) valid++; 166 } 167 if (Object.keys(requiredFields).length == valid && !shippingInfoTracked) { 168 shippingInfoTracked = true; 169 analytics.value = parseFloat($('input[name="booking[TotalCost]"]').val()); 170 updateDataLayer('add_shipping_info'); 171 } 172 }); 173 } 174 function updateDataLayer(event) { 175 dataLayer.push({ ecommerce: null }); // Clear the previous ecommerce object. 176 switch (event) { 177 case 'view_item_list': 178 dataLayer.push({ 179 event: event, 180 ecommerce: { 181 items: analytics.units 182 } 183 }); 184 break; 185 case 'select_item': 186 dataLayer.push({ 187 event: event, 188 ecommerce: { 189 items: analytics.units 190 } 191 }); 192 break; 193 case 'view_item': 194 delete analytics.units[0].index; 195 dataLayer.push({ 196 event: event, 197 ecommerce: { 198 items: analytics.units 199 } 200 }); 201 break; 202 case 'add_to_cart': 203 delete analytics.units[0].index; 204 dataLayer.push({ 205 event: event, 206 ecommerce: { 207 items: analytics.units 208 } 209 }); 210 break; 211 case 'begin_checkout': 212 delete analytics.units[0].index; 213 dataLayer.push({ 214 event: event, 215 ecommerce: { 216 items: analytics.units 217 } 218 }); 219 break; 220 case 'add_shipping_info': 221 delete analytics.units[0].index; 222 dataLayer.push({ 223 event: event, 224 ecommerce: { 225 items: analytics.units 226 } 227 }); 228 break; 229 } 230 } 231 }); 232}(jQuery, window));
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.