|
37 | 37 | var doc = window.document; |
38 | 38 | var userAgent = nav.userAgent; |
39 | 39 | var notSending = "Not sending request "; |
| 40 | + var notSendingWhen = notSending + "when "; |
40 | 41 | var fetchedHighEntropyValues = falseVar; |
41 | 42 | var encodeURIComponentFunc = encodeURIComponent; |
42 | 43 | var decodeURIComponentFunc = decodeURIComponent; |
|
85 | 86 | return typeof string == "string"; |
86 | 87 | }; |
87 | 88 |
|
| 89 | + var filterRegex = function (item) { |
| 90 | + return item.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); |
| 91 | + }; |
| 92 | + |
88 | 93 | var attr = function (scriptElement, attribute) { |
89 | 94 | return scriptElement && scriptElement.getAttribute("data-" + attribute); |
90 | 95 | }; |
|
208 | 213 | var ignore = ignoreSource || !collectMetricByString("ut"); |
209 | 214 |
|
210 | 215 | /** if allowparams **/ |
211 | | - var paramsRegexList = allowParams.join("|"); |
| 216 | + var paramsRegexList = allowParams.map(filterRegex).join("|"); |
212 | 217 | var regex = ignore |
213 | 218 | ? "^(" + paramsRegexList + ")=" |
214 | 219 | : "^((utm_)" + |
|
225 | 230 | "^((utm_)" + |
226 | 231 | (strictUtm ? "" : "?") + |
227 | 232 | "(source|medium|content|term|campaign)" + |
228 | | - (strictUtm ? "" : "|ref"); |
229 | | - (")="); |
| 233 | + (strictUtm ? "" : "|ref") + |
| 234 | + ")="; |
230 | 235 | /** endif **/ |
231 | 236 |
|
232 | 237 | // The prefix "utm_" is optional with "strictUtm" disabled |
|
251 | 256 | try { |
252 | 257 | if ( |
253 | 258 | ignorePage === path || |
254 | | - new RegExp(ignorePage.replace(/\*/gi, "(.*)"), "gi").test(path) |
| 259 | + new RegExp( |
| 260 | + "^" + filterRegex(ignorePage).replace(/\\\*/gi, "(.*)") + "$", |
| 261 | + "i" |
| 262 | + ).test(path) |
255 | 263 | ) |
256 | 264 | return trueVar; |
257 | 265 | } catch (error) { |
|
279 | 287 |
|
280 | 288 | // Send data via image |
281 | 289 | var sendData = function (data, callback, onlyThisData) { |
282 | | - return braveCallback(function (isBrave) { |
283 | | - data = onlyThisData ? data : assign(payload, page, data); |
| 290 | + data = onlyThisData ? data : assign(payload, page, data); |
284 | 291 |
|
285 | | - if (isBrave && !onlyThisData) data.brave = trueVar; |
| 292 | + if (nav.brave && !onlyThisData) data.brave = trueVar; |
286 | 293 |
|
287 | | - /** if dev **/ |
288 | | - data.dev = trueVar; |
289 | | - /** endif **/ |
| 294 | + /** if dev **/ |
| 295 | + data.dev = trueVar; |
| 296 | + /** endif **/ |
290 | 297 |
|
291 | | - var image = new Image(); |
292 | | - /** if events **/ |
293 | | - if (callback) { |
294 | | - image.onerror = callback; |
295 | | - image.onload = callback; |
296 | | - } |
297 | | - /** endif **/ |
298 | | - image.src = |
299 | | - fullApiUrl + |
300 | | - "/simple.gif?" + |
301 | | - Object.keys(data) |
302 | | - .filter(function (key) { |
303 | | - return data[key] != undefinedVar; |
304 | | - }) |
305 | | - .map(function (key) { |
306 | | - return ( |
307 | | - encodeURIComponentFunc(key) + |
308 | | - "=" + |
309 | | - encodeURIComponentFunc(data[key]) |
310 | | - ); |
311 | | - }) |
312 | | - .join("&") + |
313 | | - "&time=" + |
314 | | - Date.now(); |
315 | | - }); |
| 298 | + var image = new Image(); |
| 299 | + /** if events **/ |
| 300 | + if (callback) { |
| 301 | + image.onerror = callback; |
| 302 | + image.onload = callback; |
| 303 | + } |
| 304 | + /** endif **/ |
| 305 | + image.src = |
| 306 | + fullApiUrl + |
| 307 | + "/simple.gif?" + |
| 308 | + Object.keys(data) |
| 309 | + .filter(function (key) { |
| 310 | + return data[key] != undefinedVar; |
| 311 | + }) |
| 312 | + .map(function (key) { |
| 313 | + return ( |
| 314 | + encodeURIComponentFunc(key) + |
| 315 | + "=" + |
| 316 | + encodeURIComponentFunc(data[key]) |
| 317 | + ); |
| 318 | + }) |
| 319 | + .join("&") + |
| 320 | + "&time=" + |
| 321 | + Date.now(); |
316 | 322 | }; |
317 | 323 |
|
318 | 324 | /** if errorhandling **/ |
|
350 | 356 | // |
351 | 357 |
|
352 | 358 | /** if duration **/ |
353 | | - var duration = "duration"; |
354 | 359 | var start = now(); |
355 | 360 | /** endif **/ |
356 | 361 |
|
|
397 | 402 |
|
398 | 403 | /** if ignorepages **/ |
399 | 404 | // Customers can ignore certain pages |
400 | | - var ignorePages = convertCommaSeparatedToArray( |
401 | | - overwriteOptions.ignorePages || attr(scriptElement, "ignore-pages") |
402 | | - ); |
| 405 | + var ignorePages = |
| 406 | + ["/path*lala"] || |
| 407 | + convertCommaSeparatedToArray( |
| 408 | + overwriteOptions.ignorePages || attr(scriptElement, "ignore-pages") |
| 409 | + ); |
403 | 410 | /** endif **/ |
404 | 411 |
|
405 | 412 | /** if allowparams **/ |
|
430 | 437 | attr(scriptElement, "metadata-collector"); |
431 | 438 | /** endif **/ |
432 | 439 |
|
433 | | - var braveCallback = function (callback) { |
434 | | - if (!nav.brave) callback(falseVar); |
435 | | - else |
436 | | - nav.brave |
437 | | - .isBrave() |
438 | | - .then(function () { |
439 | | - callback(trueVar); |
440 | | - }) |
441 | | - .catch(function () { |
442 | | - callback(falseVar); |
443 | | - }); |
444 | | - }; |
445 | | - |
446 | 440 | // This code could error on (incomplete) implementations, that's why we use try...catch |
447 | 441 | var timezone; |
448 | 442 | try { |
|
530 | 524 | /** if ignorednt **/ |
531 | 525 | if (!collectDnt && doNotTrack in nav && nav[doNotTrack] == "1") |
532 | 526 | return warn( |
533 | | - notSending + |
534 | | - "when " + |
535 | | - doNotTrack + |
536 | | - " is enabled. See " + |
537 | | - docsUrl + |
538 | | - "/dnt" |
| 527 | + notSendingWhen + doNotTrack + " is enabled. See " + docsUrl + "/dnt" |
539 | 528 | ); |
540 | 529 | /** else **/ |
541 | 530 | if (doNotTrack in nav && nav[doNotTrack] == "1") |
542 | 531 | return warn( |
543 | | - notSending + |
544 | | - "when " + |
545 | | - doNotTrack + |
546 | | - " is enabled. See " + |
547 | | - docsUrl + |
548 | | - "/dnt" |
| 532 | + notSendingWhen + doNotTrack + " is enabled. See " + docsUrl + "/dnt" |
549 | 533 | ); |
550 | 534 | /** endif **/ |
551 | 535 |
|
|
595 | 579 | /** if duration **/ |
596 | 580 | // t = timeonpage |
597 | 581 | if (collectMetricByString("t")) { |
598 | | - append[duration] = Math.round((now() - start - msHidden) / thousand); |
| 582 | + append.duration = Math.round((now() - start - msHidden) / thousand); |
599 | 583 | } |
600 | 584 | msHidden = 0; |
601 | 585 | start = now(); |
|
694 | 678 | /** if ignorepages **/ |
695 | 679 | // Ignore pages specified in data-ignore-pages |
696 | 680 | if (shouldIgnore(path)) { |
697 | | - warn(notSending + ", ignored " + path); |
| 681 | + warn(notSendingWhen + "ignoring " + path); |
698 | 682 | return; |
699 | 683 | } |
700 | 684 | /** endif **/ |
|
0 commit comments