1if ("undefined" === typeof(_etmc)) { 2 var _etmc = []; 3} 4 5if (!Array.isArray) { 6 Array.isArray = function(arg) { 7 return Object.prototype.toString.call(arg) === '[object Array]'; 8 }; 9} 10 11var _etmc_temp = _etmc; 12var _etmc = { 13 14 debug: false, 15 16 setup: function(array) { 17 var l = array.length; 18 for (var i = 0; i < l; i++) { 19 this.callFunc(array[i]); 20 } 21 }, 22 23 push: function(item) { 24 if (this.tracking_disabled) return; 25 this.callFunc(item); 26 }, 27 28 callFunc: function(array) { 29 func_name = array[0]; 30 args = array.slice(1,3); 31 this[func_name](args); 32 }, 33 34 setOrgId: function(args) { 35 if(Array.isArray(args[0]) === true) { 36 this.org_id = args[0]; 37 } else { 38 this.org_id = [ args[0] ]; 39 } 40 }, 41 42 setUserInfo: function(args) { 43 var user_info = args[0]; 44 if(this.user_info && this.user_info.email) { 45 user_info.email = this.user_info.email; 46 } 47 this.user_info = user_info; 48 }, 49 50 setFirstParty: function(args) { 51 this.first_party = args[0]; 52 }, 53 54 setInsecure: function(args) { 55 this.insecure = args[0]; 56 }, 57 58 doNotTrack: function() { 59 this.tracking_disabled = true; 60 }, 61 62 setConversionTrackingInfoFromUrl: function() { 63 this.email_job_id = this.getURLParameter("sfmc_j") || this.getURLParameter("j"); 64 this.email = this.getURLParameter("sfmc_e") || this.getURLParameter("e"); 65 if (this.email != null) { 66 if (this.user_info) { 67 this.user_info.email = this.email; 68 } else { 69 this.user_info = { "email" : this.email }; 70 } 71 } 72 this.email_list_id = this.getURLParameter("sfmc_l") || this.getURLParameter("l"); 73 this.email_landing_url_id = this.getURLParameter("sfmc_u") || this.getURLParameter("u"); 74 this.email_job_batch_id = this.getURLParameter("sfmc_jb") || this.getURLParameter("jb"); 75 this.email_subscriber_id = this.getURLParameter("sfmc_s") || this.getURLParameter("s") || this.getURLParameter("sfmc_sub"); 76 this.mid = this.getURLParameter("sfmc_mid") || this.getURLParameter("mid"); 77 }, 78 79 isEtConversionTracking: function() { 80 return ( 81 this.email_job_id != null && 82 (this.email != null || this.email_subscriber_id != null) && 83 this.email_list_id != null && 84 this.email_landing_url_id != null && 85 this.email_job_batch_id != null && 86 this.mid != null 87 ); 88 }, 89 90 getCurrentLocation: function() { 91 return window.location.href; 92 }, 93 94 trackPageView: function(args) { 95 this.setConversionTrackingInfoFromUrl(); 96 var pageView = args[0] || {}; 97 if (this.org_id) { 98 pageView.title = pageView.title || document.title; 99 pageView.url = pageView.url || this.getCurrentLocation(); 100 pageView.referrer = document.referrer; 101 if (this.isEtConversionTracking()) { 102 pageView.et_email = {}; 103 pageView.et_email.job_id = this.email_job_id; 104 pageView.et_email.list_id = this.email_list_id.replace(/\D+/, ''); 105 pageView.et_email.landing_url_id = this.email_landing_url_id; 106 pageView.et_email.job_batch_id = this.email_job_batch_id; 107 pageView.et_email.subscriber_id = this.email_subscriber_id; 108 pageView.et_email.mid = this.mid; 109 } 110 this.sendDataWithImage("track_page_view", pageView); 111 } 112 }, 113 114 trackCart: function(args) { 115 var cart = args[0] || {}; 116 if (this.org_id) { 117 var cartInfo = this.standardizeCart(cart); 118 if ("clear_cart" in cart) { 119 cartInfo.clear_cart = cart.clear_cart; 120 } 121 cartInfo.url = this.getCurrentLocation(); 122 this.sendDataWithImage("track_cart", cartInfo); 123 } 124 }, 125 126 trackConversion: function(args) { 127 var cart = args[0] || []; 128 var opts = args[1]; 129 if (this.org_id) { 130 var cartInfo = this.standardizeCart(cart); 131 if (cart["details"]) { 132 cartInfo.details = cart["details"]; 133 } else if (opts) { 134 if ("details" in opts) { 135 cartInfo.details = opts.details; 136 } 137 if ("currency_code" in opts) { 138 cartInfo.currency_code = opts.currency_code; 139 } 140 } 141 cartInfo.url = this.getCurrentLocation(); 142 this.sendDataWithImage("track_conversion", cartInfo); 143 } 144 }, 145 146 trackEvent: function(args) {}, 147 148 trackWishlist: function(args) { 149 var wishlist = args[0] || []; 150 if (this.org_id) { 151 if (wishlist != []) { 152 this.sendDataWithImage("track_wishlist", wishlist); 153 } 154 } 155 }, 156 157 trackRating: function(args){ 158 var rating = args[0] || {}; 159 if (this.org_id){ 160 if (rating.rating != null) { 161 this.sendDataWithImage("track_rating", rating); 162 } 163 } 164 }, 165
166 sendDataWithImage: function(endpoint, args) { 167 if (this.user_info) { 168 args.user_info = this.user_info; 169 } 170 if (this.org_id.length > 1) { 171 temp_org_id = [this.org_id.shift()]; 172 args.child_ids = this.org_id; 173 this.org_id = temp_org_id; 174 } 175 176 var collectData = encodeURIComponent(JSON.stringify(args)); 177 var protocolPrepend = 'https'; 178 if (this.insecure === true && document.location.protocol === 'http:') protocolPrepend = 'http'; 179 if (this.first_party) { 180 collect_url = this.first_party; 181 } else { 182 collect_url = 'nova.collect.igodigital.com'; 183 } 184 185 var image_src = protocolPrepend + '://' + collect_url + '/c2/' + this.org_id + '/' + endpoint +'?payload=' + collectData; 186 var image_tag = document.createElement('img'); 187 image_tag.src = image_src; 188 image_tag.style.display = 'none'; 189 image_tag.width = '0'; 190 image_tag.height = '0'; 191 image_tag.title = 'blank image'; 192 image_tag.alt = ''; 193 image_tag.setAttribute('aria-hidden', 'true'); 194 195 if (this.debug) { 196 console.log(args); 197 console.log(image_tag.outerHTML); 198 } else { 199 var etmc_element = document.createElement('div'); 200 etmc_element.style.display = "none"; 201 etmc_element.innerHTML = image_tag.outerHTML; 202 document.body.appendChild(etmc_element); 203 } 204 }, 205 206 standardizeCart: function(cart){ 207 var cartInfo = {}; 208 if (Array.isArray(cart) === true) { 209 cartInfo = { "cart": cart }; 210 } else if ("cart" in cart) { 211 cartInfo = cart; 212 } else if ("item" in cart) { 213 cartInfo = { "cart": [cart] }; 214 } 215 return cartInfo; 216 }, 217 218 updateItem: function(args) { 219 var rec_items = args[0]; 220 if (rec_items !== null) { 221 var items_to_update = null; 222 223 if (!Array.isArray(rec_items)) { 224 rec_items = [rec_items]; 225 } 226 227 var valid_items = []; 228 229 for (var i in rec_items) { 230 if (rec_items.hasOwnProperty(i)) { 231 this.setDefaultItemValues(rec_items[i]); 232 if (this.hasRequiredFields(rec_items[i])) { 233 valid_items.push(rec_items[i]); 234 } else { 235 console.log("ETMC update_rec_item error: required fields were missing from " + JSON.stringify(rec_items[i])); 236 } 237 } 238 } 239 240 if (valid_items.length > 0) { 241 items_to_update = valid_items; 242 } 243 244 if (items_to_update !== null) { 245 this.sendDataWithImage("update_item", items_to_update); 246 } 247 } 248 }, 249 250 getURLParameter: function(paramName) { 251 var regex = new RegExp('[?|&]' + paramName + '=' + '([^&;]+?)(&|#|;|$)'); 252 var matches = regex.exec(window.location.search) || [,""]; 253 var parameterValue = matches[1].replace(/\+/g, '%20'); 254 return decodeURIComponent(parameterValue) || null; 255 }, 256 257 hasRequiredFields: function(item) { 258 var isValid = item["item"] !== undefined && item["url"] !== undefined; 259 260 if (isValid) { 261 var item_type = item["item_type"]; 262 if (this.shouldValidateName(item_type)) { 263 isValid = item["name"] != undefined; 264 } else if (item_type === "banner") { 265 isValid = item["image_url"] !== undefined && 266 (item["banner_size"] !== undefined || item["location_size"] !== undefined); 267 } 268 } 269 return isValid; 270 }, 271 272 shouldValidateName: function(item_type) { 273 return item_type == undefined || item_type === "product" || item_type === "content" || item_type === "asset"; 274 }, 275 276 setDefaultItemValues: function(item) { 277 if (item["item_type"] == undefined){ 278 item["item_type"] = "content"; 279 } 280 if (item["url"] == undefined) { 281 item["url"] = window.location.href; 282 } 283 if (item["item_type"] !== "banner" && item["item_type"] !== "asset" && item["name"] == undefined) { 284 item["name"] = document.title; 285 } 286 } 287}; 288 289_etmc.setup(_etmc_temp);
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.