Skip to content

Commit 01d8d05

Browse files
committed
Run build
1 parent af8bf4a commit 01d8d05

33 files changed

Lines changed: 252 additions & 267 deletions

dist/latest/auto-events.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/latest/cloudflare.js

Lines changed: 69 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Simple Analytics - Privacy friendly analytics (docs.simpleanalytics.com/script; 2022-07-23; d79b; v9) */
1+
/* Simple Analytics - Privacy friendly analytics (docs.simpleanalytics.com/script; 2022-07-25; 72db; v9) */
22
/* eslint-env browser */
33

44
(function (
@@ -36,6 +36,7 @@
3636
var doc = window.document;
3737
var userAgent = nav.userAgent;
3838
var notSending = "Not sending request ";
39+
var notSendingWhen = notSending + "when ";
3940
var fetchedHighEntropyValues = falseVar;
4041
var encodeURIComponentFunc = encodeURIComponent;
4142
var decodeURIComponentFunc = decodeURIComponent;
@@ -82,6 +83,10 @@
8283
return typeof string == "string";
8384
};
8485

86+
var filterRegex = function (item) {
87+
return item.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
88+
};
89+
8590
var attr = function (scriptElement, attribute) {
8691
return scriptElement && scriptElement.getAttribute("data-" + attribute);
8792
};
@@ -196,7 +201,7 @@
196201
.filter(function (keyValue) {
197202
var ignore = ignoreSource || !collectMetricByString("ut");
198203

199-
var paramsRegexList = allowParams.join("|");
204+
var paramsRegexList = allowParams.map(filterRegex).join("|");
200205
var regex = ignore
201206
? "^(" + paramsRegexList + ")="
202207
: "^((utm_)" +
@@ -229,7 +234,10 @@
229234
try {
230235
if (
231236
ignorePage === path ||
232-
new RegExp(ignorePage.replace(/\*/gi, "(.*)"), "gi").test(path)
237+
new RegExp(
238+
"^" + filterRegex(ignorePage).replace(/\\\*/gi, "(.*)") + "$",
239+
"i"
240+
).test(path)
233241
)
234242
return trueVar;
235243
} catch (error) {
@@ -256,35 +264,33 @@
256264

257265
// Send data via image
258266
var sendData = function (data, callback, onlyThisData) {
259-
return braveCallback(function (isBrave) {
260-
data = onlyThisData ? data : assign(payload, page, data);
267+
data = onlyThisData ? data : assign(payload, page, data);
261268

262-
if (isBrave && !onlyThisData) data.brave = trueVar;
269+
if (nav.brave && !onlyThisData) data.brave = trueVar;
263270

264271

265-
var image = new Image();
266-
if (callback) {
267-
image.onerror = callback;
268-
image.onload = callback;
269-
}
270-
image.src =
271-
fullApiUrl +
272-
"/simple.gif?" +
273-
Object.keys(data)
274-
.filter(function (key) {
275-
return data[key] != undefinedVar;
276-
})
277-
.map(function (key) {
278-
return (
279-
encodeURIComponentFunc(key) +
280-
"=" +
281-
encodeURIComponentFunc(data[key])
282-
);
283-
})
284-
.join("&") +
285-
"&time=" +
286-
Date.now();
287-
});
272+
var image = new Image();
273+
if (callback) {
274+
image.onerror = callback;
275+
image.onload = callback;
276+
}
277+
image.src =
278+
fullApiUrl +
279+
"/simple.gif?" +
280+
Object.keys(data)
281+
.filter(function (key) {
282+
return data[key] != undefinedVar;
283+
})
284+
.map(function (key) {
285+
return (
286+
encodeURIComponentFunc(key) +
287+
"=" +
288+
encodeURIComponentFunc(data[key])
289+
);
290+
})
291+
.join("&") +
292+
"&time=" +
293+
Date.now();
288294
};
289295

290296
/////////////////////
@@ -319,7 +325,6 @@
319325
// INITIALIZE VALUES
320326
//
321327

322-
var duration = "duration";
323328
var start = now();
324329

325330
var scrolled = 0;
@@ -356,9 +361,11 @@
356361
namespace + "_" + eventText;
357362

358363
// Customers can ignore certain pages
359-
var ignorePages = convertCommaSeparatedToArray(
360-
overwriteOptions.ignorePages || attr(scriptElement, "ignore-pages")
361-
);
364+
var ignorePages =
365+
["/path*lala"] ||
366+
convertCommaSeparatedToArray(
367+
overwriteOptions.ignorePages || attr(scriptElement, "ignore-pages")
368+
);
362369

363370
// Customers can allow params
364371
var allowParams = convertCommaSeparatedToArray(
@@ -380,19 +387,6 @@
380387
overwriteOptions.metadataCollector ||
381388
attr(scriptElement, "metadata-collector");
382389

383-
var braveCallback = function (callback) {
384-
if (!nav.brave) callback(falseVar);
385-
else
386-
nav.brave
387-
.isBrave()
388-
.then(function () {
389-
callback(trueVar);
390-
})
391-
.catch(function () {
392-
callback(falseVar);
393-
});
394-
};
395-
396390
// This code could error on (incomplete) implementations, that's why we use try...catch
397391
var timezone;
398392
try {
@@ -422,18 +416,24 @@
422416
var collectDataOnLeave =
423417
collectMetricByString("t") || collectMetricByString("scro");
424418

425-
var payload = {
419+
var basePayload = {
426420
version: version,
421+
hostname: definedHostname,
422+
};
423+
424+
if (bot) basePayload.bot = trueVar;
425+
426+
var payload = assign(basePayload, {
427427
// us = useragent
428428
ua: collectMetricByString("us") ? userAgent : undefinedVar,
429+
429430
https: loc.protocol == https,
430431
timezone: timezone,
431-
hostname: definedHostname,
432432
page_id: collectDataOnLeave ? uuid() : undefinedVar,
433+
433434
// se = sessions
434435
session_id: collectMetricByString("se") ? uuid() : undefinedVar,
435-
};
436-
if (bot) payload.bot = trueVar;
436+
});
437437

438438
payload.sri = falseVar;
439439

@@ -460,12 +460,7 @@
460460
// Don't track when Do Not Track is set to true
461461
if (!collectDnt && doNotTrack in nav && nav[doNotTrack] == "1")
462462
return warn(
463-
notSending +
464-
"when " +
465-
doNotTrack +
466-
" is enabled. See " +
467-
docsUrl +
468-
"/dnt"
463+
notSendingWhen + doNotTrack + " is enabled. See " + docsUrl + "/dnt"
469464
);
470465

471466
// Warn when sending from localhost and not having a hostname set
@@ -506,15 +501,14 @@
506501
var sendOnLeave = function (id, push) {
507502
if (!collectDataOnLeave) return;
508503

509-
var append = {
504+
var append = assign(basePayload, {
510505
type: "append",
511-
hostname: definedHostname,
512506
original_id: push ? id : payload.page_id,
513-
};
507+
});
514508

515509
// t = timeonpage
516510
if (collectMetricByString("t")) {
517-
append[duration] = Math.round((now() - start - msHidden) / thousand);
511+
append.duration = Math.round((now() - start - msHidden) / thousand);
518512
}
519513
msHidden = 0;
520514
start = now();
@@ -603,7 +597,7 @@
603597

604598
// Ignore pages specified in data-ignore-pages
605599
if (shouldIgnore(path)) {
606-
warn(notSending + ", ignored " + path);
600+
warn(notSendingWhen + "ignoring " + path);
607601
return;
608602
}
609603

@@ -675,19 +669,20 @@
675669
var navigationText = "navigation";
676670

677671
// Check if back, forward or reload buttons are being used in modern browsers
678-
var userNavigated =
679-
perf &&
680-
perf.getEntriesByType &&
681-
perf.getEntriesByType(navigationText)[0] &&
682-
perf.getEntriesByType(navigationText)[0].type
683-
? ["reload", "back_forward"].indexOf(
684-
perf.getEntriesByType(navigationText)[0].type
685-
) > -1
686-
: // Check if back, forward or reload buttons are being use in older browsers
687-
// 1: TYPE_RELOAD, 2: TYPE_BACK_FORWARD
688-
perf &&
689-
perf[navigationText] &&
690-
[1, 2].indexOf(perf[navigationText].type) > -1;
672+
var performaceEntryType;
673+
try {
674+
performaceEntryType = perf.getEntriesByType(navigationText)[0].type;
675+
} catch (error) {
676+
// Do nothing
677+
}
678+
679+
var userNavigated = performaceEntryType
680+
? ["reload", "back_forward"].indexOf(performaceEntryType) > -1
681+
: // Check if back, forward or reload buttons are being use in older browsers
682+
// 1: TYPE_RELOAD, 2: TYPE_BACK_FORWARD
683+
perf &&
684+
perf[navigationText] &&
685+
[1, 2].indexOf(perf[navigationText].type) > -1;
691686

692687
// Check if referrer is the same as current real hostname (not the defined hostname!)
693688
var currentReferrerHostname = doc.referrer.split(slash)[2];

0 commit comments

Comments
 (0)