Skip to content

Commit 7d0b3ed

Browse files
Merge pull request #34 from simpleanalytics/v11
V11
2 parents b0b6b59 + f6f636e commit 7d0b3ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+378
-224
lines changed

.github/workflows/browserstack.yml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
push:
77
branches:
88
- master
9+
- main
910

1011
jobs:
1112
build:
@@ -29,26 +30,16 @@ jobs:
2930
local-logging-level: "all-logs"
3031
local-identifier: "random"
3132

32-
- uses: actions/checkout@v2
33+
- uses: actions/checkout@v3
34+
with:
35+
ref: ${{ github.head_ref }}
36+
set-safe-directory: "/github/workspace"
3337

3438
- name: Prettier Action on PR
35-
if: github.event_name == 'pull_request'
36-
uses: creyD/prettier_action@v1.0
39+
uses: creyD/prettier_action@v4.3
3740
with:
3841
prettier_options: "--write {**/*,*}.{js,hbs,html,json,md,yml,css,scss} !.github/workflows/**/* !dist/**/*"
3942
commit_message: "Run prettier via GitHub Action"
40-
branch: ${{ github.head_ref }}
41-
file_pattern: "."
42-
env:
43-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44-
45-
- name: Prettier Action on master
46-
if: github.ref == 'refs/heads/master'
47-
uses: creyD/prettier_action@v1.0
48-
with:
49-
prettier_options: "--write {**/*,*}.{js,html,json,md,yml,css,scss} !.github/workflows/**/* !dist/**/*"
50-
commit_message: "Run prettier via GitHub Action"
51-
branch: master
5243
file_pattern: "."
5344
env:
5445
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

compile.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const GREEN = "\x1b[32m%s\x1b[0m";
88
const YELLOW = "\x1b[33m%s\x1b[0m";
99
const RED = "\x1b[31m%s\x1b[0m";
1010

11-
const VERSION = 10;
11+
const VERSION = 11;
1212

1313
Handlebars.registerHelper("or", function (param1, param2) {
1414
return param1 || param2;
@@ -77,6 +77,7 @@ const DEFAULTS = {
7777
nonuniquehostnames: true,
7878
ignoremetrics: true,
7979
dev: false,
80+
skipnonwindow: false,
8081
};
8182

8283
const LIGHT = {
@@ -161,15 +162,27 @@ const templates = [
161162
output: `cloudflare.js`,
162163
variables: {
163164
...DEFAULTS,
165+
skipnonwindow: true,
164166
minify: false,
165167
version: VERSION,
166168
scriptName: `cloudflare_${VERSION}`,
167169
sri: false,
168170
baseUrl: "{{cloudFlareCustomDomain}}",
169171
overwriteOptions: {
170-
saGlobal: "INSTALL_OPTIONS.sa_global",
171-
mode: "INSTALL_OPTIONS.hash_mode ? 'hash' : null",
172-
collectDnt: "INSTALL_OPTIONS.collect_dnt",
172+
hostname: "INSTALL_OPTIONS.hostname",
173+
collectDnt:
174+
"typeof INSTALL_OPTIONS.collect_dnt === 'boolean' ? INSTALL_OPTIONS.collect_dnt : null",
175+
mode: "INSTALL_OPTIONS.hash_mode ? 'hash' : 'normal'",
176+
strictUtm:
177+
"INSTALL_OPTIONS.advanced_settings_toggle && INSTALL_OPTIONS.strict_utm",
178+
allowParams:
179+
"INSTALL_OPTIONS.advanced_settings_toggle && INSTALL_OPTIONS.allow_url_parameters",
180+
nonUniqueHostnames:
181+
"INSTALL_OPTIONS.advanced_settings_toggle && INSTALL_OPTIONS.non_unique_hostnames",
182+
ignorePages:
183+
"INSTALL_OPTIONS.advanced_settings_toggle && INSTALL_OPTIONS.ignore_pages",
184+
namespace:
185+
"INSTALL_OPTIONS.overwrite_namespace && INSTALL_OPTIONS.namespace",
173186
},
174187
},
175188
},

dist/latest/auto-events.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/latest/auto-events.js.map

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: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Simple Analytics - Privacy friendly analytics (docs.simpleanalytics.com/script; 2022-09-05; 9974; v10) */
1+
/* Simple Analytics - Privacy friendly analytics (docs.simpleanalytics.com/script; 2023-05-03; 0dec; v11) */
22
/* eslint-env browser */
33

44
(function (
@@ -59,10 +59,14 @@
5959
var platformText = "platform";
6060
var platformVersionText = "platformVersion";
6161
var docsUrl = "https://docs.simpleanalytics.com";
62+
var pages = 0;
6263
var isBotAgent =
6364
/(bot|spider|crawl)/i.test(userAgent) && !/(cubot)/i.test(userAgent);
6465
var screen = window.screen;
6566

67+
// Skip server side rendered pages on Cloudflare
68+
if (typeof window == "" + undefinedVar) return;
69+
6670
// Find the script element where options can be set on
6771
var scriptElement =
6872
doc.currentScript || doc.querySelector('script[src*="' + baseUrl + '"]');
@@ -77,12 +81,11 @@
7781
var args = [].slice.call(arguments);
7882

7983
// 2. Prepend log prefix
80-
args.unshift("Simple Analytics: ");
84+
args.unshift("Simple Analytics:");
8185

8286
// 3. Pass along arguments to console.warn
83-
// Function.prototype.bind.call is needed for Internet Explorer
84-
var log = Function.prototype.bind.call(con.warn, con);
85-
log.apply(con, args);
87+
// Function.prototype.apply.call is needed for Internet Explorer
88+
return Function.prototype.apply.call(con.warn, con, args);
8689
};
8790

8891
var warnInFunction = function (name, error) {
@@ -133,8 +136,13 @@
133136
return to;
134137
};
135138

139+
var settings = window.sa_settings;
140+
var logSettings = settings || Object.keys(overwriteOptions).length;
141+
136142
// Merge overwriteOptions with sa_settings
137-
overwriteOptions = assign(overwriteOptions, window.sa_settings);
143+
overwriteOptions = assign(overwriteOptions, settings);
144+
145+
if (logSettings) warn("Settings", overwriteOptions);
138146

139147
// Customers can skip data points
140148
var ignoreMetrics = convertCommaSeparatedToArray(
@@ -280,6 +288,7 @@
280288
data = onlyThisData ? data : assign(payload, page, data);
281289

282290
if (nav.brave && !onlyThisData) data.brave = trueVar;
291+
if (nav._duckduckgoloader_ && !onlyThisData) data.duck = trueVar;
283292

284293

285294
var image = new Image();
@@ -432,7 +441,8 @@
432441
window.phantom ||
433442
window.__polypane ||
434443
window._bot ||
435-
isBotAgent;
444+
isBotAgent ||
445+
Math.random() == Math.random();
436446

437447
// t = timeonpage, scro = scrolled
438448
var collectDataOnLeave =
@@ -501,12 +511,17 @@
501511
var page = {};
502512
var lastSendPath;
503513

514+
var getReferrer = function () {
515+
return (
516+
(doc.referrer || "")
517+
.replace(locationHostname, definedHostname)
518+
.replace(/^https?:\/\/((m|l|w{2,3}([0-9]+)?)\.)?([^?#]+)(.*)$/, "$4")
519+
.replace(/^([^/]+)$/, "$1") || undefinedVar
520+
);
521+
};
522+
504523
// We don't want to end up with sensitive data so we clean the referrer URL
505-
var referrer =
506-
(doc.referrer || "")
507-
.replace(locationHostname, definedHostname)
508-
.replace(/^https?:\/\/((m|l|w{2,3}([0-9]+)?)\.)?([^?#]+)(.*)$/, "$4")
509-
.replace(/^([^/]+)$/, "$1") || undefinedVar;
524+
var referrer = getReferrer();
510525

511526
/////////////////////
512527
// TIME ON PAGE AND SCROLLED LOGIC
@@ -629,6 +644,8 @@
629644
return path;
630645
};
631646

647+
var previousReferrer;
648+
632649
// Send page view and append data to it
633650
var sendPageView = function (
634651
isPushState,
@@ -650,9 +667,14 @@
650667
metadata: stringify(metadata),
651668
});
652669

670+
previousReferrer = referrer;
653671
referrer = currentPage;
672+
673+
pages++;
654674
};
655675

676+
var sameSite, userNavigated;
677+
656678
var pageview = function (isPushState, pathOverwrite, metadata) {
657679
// Obfuscate personal data in URL by dropping the search and hash
658680
var path = getPath(pathOverwrite);
@@ -698,7 +720,7 @@
698720
warn(error);
699721
}
700722

701-
var userNavigated = performaceEntryType
723+
userNavigated = performaceEntryType
702724
? ["reload", "back_forward"].indexOf(performaceEntryType) > -1
703725
: // Check if back, forward or reload buttons are being use in older browsers
704726
// 1: TYPE_RELOAD, 2: TYPE_BACK_FORWARD
@@ -707,8 +729,10 @@
707729
[1, 2].indexOf(perf[navigationText].type) > -1;
708730

709731
// Check if referrer is the same as current real hostname (not the defined hostname!)
710-
var currentReferrerHostname = doc.referrer.split(slash)[2];
711-
var sameSite = referrer
732+
var currentReferrerHostname = referrer
733+
? referrer.split(slash)[0]
734+
: undefinedVar;
735+
sameSite = referrer
712736
? nonUniqueHostnames.indexOf(currentReferrerHostname) > -1 ||
713737
currentReferrerHostname == locationHostname
714738
: falseVar;
@@ -861,13 +885,19 @@
861885
event = ("" + event).replace(/[^a-z0-9]+/gi, "_").replace(/(^_|_$)/g, "");
862886

863887
var eventParams = { type: eventText, event: event };
888+
var firstPage = !userNavigated && pages < 2;
864889

865890
metadata = appendMetadata(metadata, eventParams);
866891

867892
if (event) {
868893
sendData(
869894
assign(eventParams, {
870-
query: getQueryParams(),
895+
id: uuid(),
896+
query: getQueryParams(!firstPage),
897+
referrer:
898+
(firstPage || sameSite) && collectMetricByString("r")
899+
? previousReferrer
900+
: null,
871901

872902
metadata: stringify(metadata),
873903
}),
@@ -905,9 +935,9 @@
905935
}
906936
})(
907937
window,
908-
{"saGlobal":INSTALL_OPTIONS.sa_global,"mode":INSTALL_OPTIONS.hash_mode ? 'hash' : null,"collectDnt":INSTALL_OPTIONS.collect_dnt},
938+
{"hostname":INSTALL_OPTIONS.hostname,"collectDnt":typeof INSTALL_OPTIONS.collect_dnt === 'boolean' ? INSTALL_OPTIONS.collect_dnt : null,"mode":INSTALL_OPTIONS.hash_mode ? 'hash' : 'normal',"strictUtm":INSTALL_OPTIONS.advanced_settings_toggle && INSTALL_OPTIONS.strict_utm,"allowParams":INSTALL_OPTIONS.advanced_settings_toggle && INSTALL_OPTIONS.allow_url_parameters,"nonUniqueHostnames":INSTALL_OPTIONS.advanced_settings_toggle && INSTALL_OPTIONS.non_unique_hostnames,"ignorePages":INSTALL_OPTIONS.advanced_settings_toggle && INSTALL_OPTIONS.ignore_pages,"namespace":INSTALL_OPTIONS.overwrite_namespace && INSTALL_OPTIONS.namespace},
909939
INSTALL_OPTIONS.custom_domain || "queue.simpleanalyticscdn.com",
910940
"",
911-
"cloudflare_10",
941+
"cloudflare_11",
912942
"sa"
913943
);

0 commit comments

Comments
 (0)