1var UtmCookie; 2 3UtmCookie = (function() { 4 function UtmCookie(options) { 5 if (options == null) { 6 options = {}; 7 } 8 this._cookieNamePrefix = '_uc_'; 9 this._domain = options.domain; 10 this._sessionLength = options.sessionLength || 1; 11 this._cookieExpiryDays = options.cookieExpiryDays || 365; 12 this._additionalParams = options.additionalParams || []; 13 this._utmParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content']; 14 this.writeInitialReferrer(); 15 this.writeLastReferrer(); 16 this.writeInitialLandingPageUrl(); 17 this.setCurrentSession(); 18 if (this.additionalParamsPresentInUrl()) { 19 this.writeAdditionalParams(); 20 } 21 if (this.utmPresentInUrl()) { 22 this.writeUtmCookieFromParams(); 23 } 24 return; 25 } 26 27 UtmCookie.prototype.createCookie = function(name, value, days, path, domain, secure) { 28 var cookieDomain, cookieExpire, cookiePath, cookieSecure, date, expireDate; 29 expireDate = null; 30 if (days) { 31 date = new Date; 32 date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); 33 expireDate = date; 34 } 35 cookieExpire = expireDate != null ? '; expires=' + expireDate.toGMTString() : ''; 36 cookiePath = path != null ? '; path=' + path : '; path=/'; 37 cookieDomain = domain != null ? '; domain=' + domain : ''; 38 cookieSecure = secure != null ? '; secure' : ''; 39 document.cookie = this._cookieNamePrefix + name + '=' + escape(value) + cookieExpire + cookiePath + cookieDomain + cookieSecure; 40 }; 41 42 UtmCookie.prototype.readCookie = function(name) { 43 var c, ca, i, nameEQ; 44 nameEQ = this._cookieNamePrefix + name + '='; 45 ca = document.cookie.split(';'); 46 i = 0; 47 while (i < ca.length) { 48 c = ca[i]; 49 while (c.charAt(0) === ' ') { 50 c = c.substring(1, c.length); 51 } 52 if (c.indexOf(nameEQ) === 0) { 53 return c.substring(nameEQ.length, c.length); 54 } 55 i++; 56 } 57 return null; 58 }; 59 60 UtmCookie.prototype.eraseCookie = function(name) { 61 this.createCookie(name, '', -1, null, this._domain); 62 }; 63 64 UtmCookie.prototype.getParameterByName = function(name) { 65 var regex, regexS, results; 66 name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); 67 regexS = '[\\?&]' + name + '=([^&#]*)'; 68 regex = new RegExp(regexS); 69 results = regex.exec(window.location.search); 70 if (results) { 71 return decodeURIComponent(results[1].replace(/\+/g, ' ')); 72 } else { 73 return ''; 74 } 75 }; 76 77 UtmCookie.prototype.additionalParamsPresentInUrl = function() { 78 var j, len, param, ref; 79 ref = this._additionalParams; 80 for (j = 0, len = ref.length; j < len; j++) { 81 param = ref[j]; 82 if (this.getParameterByName(param)) { 83 return true; 84 } 85 } 86 return false; 87 }; 88 89 UtmCookie.prototype.utmPresentInUrl = function() { 90 var j, len, param, ref; 91 ref = this._utmParams; 92 for (j = 0, len = ref.length; j < len; j++) { 93 param = ref[j]; 94 if (this.getParameterByName(param)) { 95 return true; 96 } 97 } 98 return false; 99 }; 100 101 UtmCookie.prototype.writeCookie = function(name, value) { 102 this.createCookie(name, value, this._cookieExpiryDays, null, this._domain); 103 }; 104 105 UtmCookie.prototype.writeAdditionalParams = function() { 106 var j, len, param, ref, value; 107 ref = this._additionalParams; 108 for (j = 0, len = ref.length; j < len; j++) { 109 param = ref[j]; 110 value = this.getParameterByName(param); 111 this.writeCookie(param, value); 112 } 113 }; 114 115 UtmCookie.prototype.writeUtmCookieFromParams = function() { 116 var j, len, param, ref, value; 117 ref = this._utmParams; 118 for (j = 0, len = ref.length; j < len; j++) { 119 param = ref[j]; 120 value = this.getParameterByName(param); 121 this.writeCookie(param, value); 122 } 123 }; 124 125 UtmCookie.prototype.writeCookieOnce = function(name, value) { 126 var existingValue; 127 existingValue = this.readCookie(name); 128 if (!existingValue) { 129 this.writeCookie(name, value); 130 } 131 }; 132 133 UtmCookie.prototype._sameDomainReferrer = function(referrer) { 134 var hostname; 135 hostname = document.location.hostname; 136 return referrer.indexOf(this._domain) > -1 || referrer.indexOf(hostname) > -1; 137 }; 138 139 UtmCookie.prototype._isInvalidReferrer = function(referrer) { 140 return referrer === '' || referrer === void 0; 141 }; 142 143 UtmCookie.prototype.writeInitialReferrer = function() { 144 var value; 145 value = document.referrer; 146 if (this._isInvalidReferrer(value)) { 147 value = 'direct'; 148 } 149 this.writeCookieOnce('referrer', value); 150 }; 151 152 UtmCookie.prototype.writeLastReferrer = function() { 153 var value; 154 value = document.referrer; 155 if (!this._sameDomainReferrer(value)) { 156 if (this._isInvalidReferrer(value)) { 157 value = 'direct'; 158 } 159 this.writeCookie('last_referrer', value); 160 } 161 }; 162 163 UtmCookie.prototype.writeInitialLandingPageUrl = function() { 164 var value; 165 value = this.cleanUrl(); 166 if (value) { 167 this.writeCookieOnce('initial_landing_page', value); 168 } 169 }; 170 171 UtmCookie.prototype.initialReferrer = function() { 172 return this.readCookie('referrer'); 173 }; 174 175 UtmCookie.prototype.lastReferrer = function() { 176 return this.readCookie('last_referrer'); 177 }; 178 179 UtmCookie.prototype.initialLandingPageUrl = function() { 180 return this.readCookie('initial_landing_page'); 181 }; 182 183 UtmCookie.prototype.incrementVisitCount = function() {
184 var cookieName, existingValue, newValue; 185 cookieName = 'visits'; 186 existingValue = parseInt(this.readCookie(cookieName), 10); 187 newValue = 1; 188 if (isNaN(existingValue)) { 189 newValue = 1; 190 } else { 191 newValue = existingValue + 1; 192 } 193 this.writeCookie(cookieName, newValue); 194 }; 195 196 UtmCookie.prototype.visits = function() { 197 return this.readCookie('visits'); 198 }; 199 200 UtmCookie.prototype.setCurrentSession = function() { 201 var cookieName, existingValue; 202 cookieName = 'current_session'; 203 existingValue = this.readCookie(cookieName); 204 if (!existingValue) { 205 this.createCookie(cookieName, 'true', this._sessionLength / 24, null, this._domain); 206 this.incrementVisitCount(); 207 } 208 }; 209 210 UtmCookie.prototype.cleanUrl = function() { 211 var cleanSearch; 212 cleanSearch = window.location.search.replace(/utm_[^&]+&?/g, '').replace(/&$/, '').replace(/^\?$/, ''); 213 return window.location; 214 }; 215 216 return UtmCookie; 217 218})(); 219 220var UtmForm, _uf; 221 222UtmForm = (function() { 223 function UtmForm(options) { 224 if (options == null) { 225 options = {}; 226 } 227 this._utmParamsMap = {}; 228 this._utmParamsMap.utm_source = options.utm_source_field || 'USOURCE'; 229 this._utmParamsMap.utm_medium = options.utm_medium_field || 'UMEDIUM'; 230 this._utmParamsMap.utm_campaign = options.utm_campaign_field || 'UCAMPAIGN'; 231 this._utmParamsMap.utm_content = options.utm_content_field || 'UCONTENT'; 232 this._utmParamsMap.utm_term = options.utm_term_field || 'UTERM'; 233 this._additionalParamsMap = options.additional_params_map || {}; 234 this._initialReferrerField = options.initial_referrer_field || 'IREFERRER'; 235 this._lastReferrerField = options.last_referrer_field || 'LREFERRER'; 236 this._initialLandingPageField = options.initial_landing_page_field || 'ILANDPAGE'; 237 this._visitsField = options.visits_field || 'VISITS'; 238 this._addToForm = options.add_to_form || 'all'; 239 this._formQuerySelector = options.form_query_selector || 'form'; 240 this.utmCookie = new UtmCookie({ 241 domain: options.domain, 242 sessionLength: options.sessionLength, 243 cookieExpiryDays: options.cookieExpiryDays, 244 additionalParams: Object.getOwnPropertyNames(this._additionalParamsMap) 245 }); 246 this.addAllFields(); 247 } 248 249 UtmForm.prototype.addAllFields = function() { 250 var allForms, i, len; 251 allForms = document.querySelectorAll(this._formQuerySelector); 252 if (this._addToForm === 'none') { 253 len = 0; 254 } else if (this._addToForm === 'first') { 255 len = Math.min(1, allForms.length); 256 } else { 257 len = allForms.length; 258 } 259 i = 0; 260 while (i < len) { 261 this.addAllFieldsToForm(allForms[i]); 262 i++; 263 } 264 }; 265 266 UtmForm.prototype.addAllFieldsToForm = function(form) { 267 var fieldName, param, ref, ref1; 268 if (form && !form._utm_tagged) { 269 form._utm_tagged = true; 270 ref = this._utmParamsMap; 271 for (param in ref) { 272 fieldName = ref[param]; 273 this.addFormElem(form, fieldName, this.utmCookie.readCookie(param)); 274 } 275 ref1 = this._additionalParamsMap; 276 for (param in ref1) { 277 fieldName = ref1[param]; 278 this.addFormElem(form, fieldName, this.utmCookie.readCookie(param)); 279 } 280 this.addFormElem(form, this._initialReferrerField, this.utmCookie.initialReferrer()); 281 this.addFormElem(form, this._lastReferrerField, this.utmCookie.lastReferrer()); 282 this.addFormElem(form, this._initialLandingPageField, this.utmCookie.initialLandingPageUrl()); 283 this.addFormElem(form, this._visitsField, this.utmCookie.visits()); 284 } 285 }; 286 287 UtmForm.prototype.addFormElem = function(form, fieldName, fieldValue) { 288 this.insertAfter(this.getFieldEl(fieldName, fieldValue), form.lastChild); 289 }; 290 291 UtmForm.prototype.getFieldEl = function(fieldName, fieldValue) { 292 var fieldEl; 293 fieldEl = document.createElement('input'); 294 fieldEl.type = "hidden"; 295 fieldEl.name = fieldName; 296 fieldEl.value = fieldValue; 297 return fieldEl; 298 }; 299 300 UtmForm.prototype.insertAfter = function(newNode, referenceNode) { 301 return referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); 302 }; 303 304 return UtmForm; 305 306})(); 307 308_uf = window._uf || {}; 309 310window.UtmForm = new UtmForm(_uf);
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.