1//keep these global 2matchedSource = f_getSessionStorage('matchedSource'); 3matchedSourceId = f_getSessionStorage('matchedSourceId'); 4referralPhoneNum = f_getSessionStorage('referralPhoneNum'); 5trackingNumber = ""; 6 7function tryMatchingSourceFromReferrerUrl(document, sourcesList) { 8 9 if(document == null || document == undefined) 10 { 11 throw new Error("tryMatchingSourceFromReferrerUrl: document must not be null"); 12 } 13 if(sourcesList == null || sourcesList == undefined) 14 { 15 throw new Error("tryMatchingSourceFromReferrerUrl: sourcesList must not be null"); 16 } 17 18 if (!matchedSource || !firstTouchEnabled) { 19 var referrerUrl = f_getSessionStorage('referrerUrl'); 20 if (!referrerUrl && document.referrer && document.referrer.indexOf(document.domain) == -1) { 21 referrerUrl = document.referrer; 22 f_setSessionStorage('referrerUrl', referrerUrl); 23 } 24 25 if (referrerUrl) { 26 hostname = (new URL(referrerUrl)).hostname; 27 28 var referralFound = false; 29 30 $(sourcesList).each(function () { 31 if (hostname && hostname.match(/[^.]+.[^.]+(?=\.*$)/) && this.DisplayName.toLowerCase().indexOf(hostname.match(/[^.]+.[^.]+(?=\.*$)/).toString().toLowerCase()) > -1) { 32 matchedSource = encodeURIComponent(this.DisplayName); 33 matchedSourceId = this.PmSourceId; 34 f_setSessionStorage('matchedSource', matchedSource); 35 f_setSessionStorage('matchedSourceId', matchedSourceId); 36 referralFound = true; 37 } 38 }); 39 if (referralFound == false){ 40 $(sourcesList).each(function () { 41 //the regex will strip down to words so www.google.com -> google 42 if (hostname && this.DisplayName.toLowerCase().indexOf(hostname.match(/\w+(?=\.[^.]*$)/).toString().toLowerCase()) > -1) { 43 matchedSource = encodeURIComponent(this.DisplayName); 44 matchedSourceId = this.PmSourceId; 45 f_setSessionStorage('matchedSource', matchedSource); 46 f_setSessionStorage('matchedSourceId', matchedSourceId); 47 } 48 }); 49 } 50 } 51 } 52} 53 54function commonDataOnReady(document, sourcesList) { 55 var referrerUrl = f_getSessionStorage('referrerUrl'); 56 var domainUrl = document.location.host.match(/[^.]+.[^.]+(?=\.*$)/).toString(); 57 58 validateReferralUrl(document, referrerUrl, domainUrl); 59 60 var ilm = checkForIlm(sourcesList); 61 var utmKnock = false; 62 var utm = false; 63 var cid = false; 64 65 if (!ilm) { 66 utmKnock = checkForUtmKnock(sourcesList); 67 } 68 69 if (!ilm && !utmKnock) { 70 utm = checkForUtm(sourcesList, utmConfigInfo, utm); 71 } 72 73 if (!ilm && !utmKnock && !utm) { 74 cid = checkForCid(sourcesList, cid); 75 } 76 77 if (!ilm && !utmKnock) { 78 setDynamicPhoneNumber(document, referrerUrl, cid, utm); 79 } 80} 81 82function validateReferralUrl(document, referrerUrl, domainUrl) { 83 if (!referrerUrl && document.referrer) { 84 f_setSessionStorage('referrerUrl', document.referrer); 85 referrerUrl = document.referrer; 86 } else if (referrerUrl && referrerUrl.indexOf(domainUrl) == -1 && document.referrer && document.referrer.indexOf(domainUrl) == -1 && referrerUrl != document.referrer) { 87 f_setSessionStorage('referrerUrl', document.referrer); 88 referrerUrl = document.referrer; 89 } 90} 91 92function checkForIlm(sourcesList) { 93 var ilmValue = f_getAnalyticsUserValueFromCookie('RP_LSWS_ILM'); 94 ilmValue = ilmValue ? ilmValue.replace(' ', '').toLowerCase() : "";
95 let containsApartments = false; 96 let apartmentsDisplayName = ''; 97 let apartmentsSourceId = ''; 98 99 if (ilmValue != "") { 100 var ilmSourceSet = false; 101 let sourceVal = ''; 102 $(sourcesList).each(function () { 103 sourceVal = this && this.DisplayName ? this.DisplayName.replace(' ', '').toLowerCase() : ''; 104 105 //Keep track of Apartments.com if it's in the sources list' 106 if (sourceVal.indexOf('apartments.com') > -1) { 107 containsApartments = true; 108 apartmentsDisplayName = this.DisplayName; 109 apartmentsSourceId = this.PmSourceId; 110 } 111 112 if (sourceVal.indexOf(ilmValue) > -1) { 113 matchedSource = encodeURIComponent(this.DisplayName); 114 f_setSessionStorage('matchedSource', encodeURIComponent(this.DisplayName)); 115 matchedSourceId = this.PmSourceId; 116 f_setSessionStorage('matchedSourceId', this.PmSourceId); 117 ilmSourceSet = true; 118 return; 119 } 120 }); 121 122 //If we didn't find a matched source for the ILM parameter and the ILM value is Costar, then set to Apartments.com if it is in the source list' 123 if (!ilmSourceSet && ilmValue.indexOf('costar') > -1 && containsApartments) { 124 matchedSource = encodeURIComponent(apartmentsDisplayName); 125 f_setSessionStorage('matchedSource', encodeURIComponent(apartmentsDisplayName)); 126 matchedSourceId = apartmentsSourceId; 127 f_setSessionStorage('matchedSourceId', apartmentsSourceId); 128 ilmSourceSet = true; 129 } 130 131 if (ilmSourceSet) { 132 iml = true; 133 return true; 134 } else { 135 return false; 136 } 137 } else { 138 return false; 139 } 140} 141 142function checkForUtmKnock(sourcesList) { 143 var knockValue = f_getAnalyticsUserValueFromCookie('RP_LSWS_UTM_KNOCK'); 144 knockValue = knockValue ? knockValue : ""; 145 if (knockValue != "") { 146 var knockSourceSet = false; 147 $(sourcesList).each(function () { 148 if (this && this.PmSourceId == knockValue) { 149 matchedSource = encodeURIComponent(this.DisplayName); 150 f_setSessionStorage('matchedSource', encodeURIComponent(this.DisplayName)); 151 matchedSourceId = this.PmSourceId; 152 f_setSessionStorage('matchedSourceId', this.PmSourceId); 153 knockSourceSet = true; 154 return; 155 } 156 }); 157 if (knockSourceSet) { 158 utmKnock = true; 159 return true; 160 } else { 161 return false; 162 } 163 } else { 164 return false; 165 } 166} 167 168function checkForUtm(sourcesList, utmConfigInfo, utm) { 169 var utmValue = f_getAnalyticsUserValueFromCookie('RP_LSWS_UTM'); 170 171 utmValue = utmValue ? utmValue : ""; 172 if (utmValue != "") { 173 utm = true; 174 var utmValueArray = utmValue.split("&"); 175 var utmSource; 176 var utmMedium; 177 var utmCampaign; 178 utmValueArray.forEach(function(value) { 179 if (value.indexOf("Source=") > -1) { 180 utmSource = value.substring(value.indexOf("Source=") + 7, value.length); 181 } 182 else if (value.indexOf("Medium=") > -1) { 183 utmMedium = value.substring(value.indexOf("Medium=") + 7, value.length); 184 } 185 else if (value.indexOf("Campaign=") > -1) { 186 utmCampaign = value.substring(value.indexOf("Campaign=") + 9, value.length); 187 } 188 }); 189 } 190 191 if (utm) { 192 var utmSourceSet = false; 193 $(sourcesList).each(function () { 194 if (this && this.DisplayName && this.DisplayName.replace(' ', '').toLowerCase().indexOf(utmSource.replace(' ', '').toLowerCase()) > -1) { 195 matchedSource = encodeURIComponent(this.DisplayName); 196 f_setSessionStorage('matchedSource', encodeURIComponent(this.DisplayName)); 197 matchedSourceId = this.PmSourceId;
198 f_setSessionStorage('matchedSourceId', this.PmSourceId); 199 return; 200 } 201 }); 202 try { 203 if (utmConfigInfo.indexOf("Error") == 0) { 204 console.error('Error getting UTM config from API: ', utmConfigInfo); 205 } 206 else { 207 if (utmConfigInfo != "") { 208 var utmConfigurations = JSON.parse(utmConfigInfo); 209 $(utmConfigurations.response.utmConfigurations).each(function () { 210 if (this.utmSource.toLowerCase() == utmSource.toLowerCase() && 211 this.utmMedium.toLowerCase() == utmMedium.toLowerCase() && 212 this.utmCampaign.toLowerCase() == utmCampaign.toLowerCase()) { 213 trackingNumber = this.inboundLeadConfig.trackingNumber; 214 setUtmPhoneNumber(trackingNumber); 215 utmSourceSet = true; 216 return; 217 } 218 }); 219 } 220 } 221 } 222 catch(e){ 223 console.error("Error parsing the UTM config object. ", e.Message); 224 } 225 if (utmSourceSet) { 226 return true; 227 } else { 228 return false; 229 } 230 } else { 231 return false; 232 } 233} 234 235function setUtmPhoneNumber(trackingNumber) { 236 if (trackingNumber != "") { 237 if (trackingNumber.length == 10) { 238 trackingNumber = trackingNumber.replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3'); 239 } 240 if (trackingNumber.length == 11) { 241 trackingNumber = trackingNumber.replace(/(\d{3})(\d{4})(\d{4})/, '$1 $2 $3'); 242 } 243 setSEONumber(trackingNumber); 244 } 245} 246 247function checkForCid(sourcesList, cid) { 248 var cidValue = f_getAnalyticsUserValueFromCookie('RP_LSWS_SEM'); 249 cidValue = cidValue ? cidValue : ""; 250 if (cidValue != "") 251 cid = true; 252 253 var cidSourceSet = false; 254 if (cid) { 255 $(sourcesList).each(function () { 256 if (this && this.DisplayName && this.DisplayName.replace(' ', '').toLowerCase().indexOf(cidValue.replace(' ', '').toLowerCase()) > -1) { 257 matchedSource = encodeURIComponent(this.DisplayName); 258 f_setSessionStorage('matchedSource', encodeURIComponent(this.DisplayName)); 259 matchedSourceId = this.PmSourceId; 260 f_setSessionStorage('matchedSourceId', this.PmSourceId); 261 cidSourceSet = true; 262 return; 263 } 264 }); 265 266 if (!cidSourceSet) { 267 $(sourcesList).each(function () { 268 if (this && this.DisplayName && this.DisplayName.replace(' ', '').toLowerCase().indexOf('propertywebsite') > -1) { 269 matchedSource = encodeURIComponent(this.DisplayName); 270 f_setSessionStorage('matchedSource', encodeURIComponent(this.DisplayName)); 271 matchedSourceId = this.PmSourceId; 272 f_setSessionStorage('matchedSourceId', this.PmSourceId); 273 cidSourceSet = true; 274 return; 275 } 276 }); 277 } 278 } 279 if (cidSourceSet) { 280 return true; 281 } else { 282 return false; 283 } 284} 285 286function setDynamicPhoneNumber(document, referrerUrl, cid, utm, jsrxEnabled) { 287 var changePhoneNum = false; 288 if (!cid && !googleCallTrackingEnabled && !jsrxEnabled) { 289 changePhoneNum = true; 290 console.log('set changePhoneNum to ' + changePhoneNum) 291 } 292 if (!utm || trackingNumber == "") { 293 if (changePhoneNum && ((referrerUrl && referrerUrl.indexOf('http') > -1) || referralPhoneNum)) { 294 var a = document.createElement('a'); 295 a.setAttribute('href', referrerUrl); 296 var referrerHostname = a.hostname.match(/[^.]+.[^.]+(?=\.*$)/).toString(); 297 var phoneNumberList = []; 298 if (referralPhoneNum) 299 phoneNumberList.push(referralPhoneNum); 300 else if (leadObj) { 301 $(leadList).each(function(i, v) { 302 if (v.Domain.toLowerCase().indexOf(referrerHostname.toLowerCase()) > -1) { 303 $(leadObj).each(function() { 304 if (this.LeadChannelName && this.LeadChannelName.toLowerCase().indexOf(v.hcLeadChannelName.toLowerCase()) > -1) { 305 phoneNumberList.push(this.PhoneNumber); 306 f_setSessionStorage('referralPhoneNum', this.PhoneNumber); 307 } 308 }); 309 } 310 }); 311 } 312 313 if (phoneNumberList.length == 1) { 314 setSEONumber(phoneNumberList[0]); 315 } else if (phoneNumberList.length == 0) { 316 if (referrerHostname.indexOf('.') > -1) 317 referrerHostname = referrerHostname.substring(0, referrerHostname.indexOf('.')); 318 319 $(leadObj).each(function (i, v) { 320 if (v.LeadChannelName && v.LeadChannelName.toLowerCase().indexOf(referrerHostname.toLowerCase()) > -1 && v.PhoneNumber != null) { 321 phoneNumberList.push(this.PhoneNumber); 322 f_setSessionStorage('referralPhoneNum', this.PhoneNumber); 323 } 324 }); 325 326 if (phoneNumberList.length == 1) { 327 setSEONumber(phoneNumberList[0]); 328 } 329 } 330 } 331 } 332} 333 334 335 336try{ 337 module.exports.tryMatchingSourceFromReferrerUrl = tryMatchingSourceFromReferrerUrl; 338 module.exports.commonDataOnReady = commonDataOnReady; 339 module.exports.validateReferralUrl = validateReferralUrl; 340 module.exports.checkForUtm = checkForUtm; 341 module.exports.setUtmPhoneNumber = setUtmPhoneNumber; 342 module.exports.checkForCid = checkForCid; 343 module.exports.setDynamicPhoneNumber = setDynamicPhoneNumber; 344 module.exports.checkForIlm = checkForIlm; 345 module.exports.checkForUtmKnock = checkForUtmKnock; 346}catch(e){/*shhh ignore errors*/}
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.