diff options
| author | Christine Dodrill <me@christine.website> | 2019-08-19 13:48:21 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-19 13:48:21 -0400 |
| commit | a6c66568c8b59563b64f3ad3d2d4f4a36ec53004 (patch) | |
| tree | f4cc2f5094b21ba38df370f1d598c3cfd62f6671 /static/js | |
| parent | eaca47ba372cd933d273fe277f724e64580e0cd7 (diff) | |
| download | xesite-a6c66568c8b59563b64f3ad3d2d4f4a36ec53004.tar.xz xesite-a6c66568c8b59563b64f3ad3d2d4f4a36ec53004.zip | |
Pageview times experiment (#69)
* experiment: track pageview times
* strictly respect do not track
* oops
* asdfasdfasdf
* add blogpost
* fix typos oops
Diffstat (limited to 'static/js')
| -rw-r--r-- | static/js/pageview_timer.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/static/js/pageview_timer.js b/static/js/pageview_timer.js new file mode 100644 index 0000000..2761396 --- /dev/null +++ b/static/js/pageview_timer.js @@ -0,0 +1,31 @@ +/* + Hi, + + If you are reading this, you have found this script in the referenced scripts + for pages on this site. I know you're gonna have to take me at my word on this, + but I'm literally using this to collect how much time people spend reading my + webpages. See metrics here: https://christine.website/metrics + + If you have the "do not track" setting enabled in your browser, this code will + be ineffectual. +*/ + +(function() { + let dnt = navigator.doNotTrack; + if (dnt === "1") { + return; + } + + let startTime = new Date(); + + function logTime() { + let stopTime = new Date(); + window.navigator.sendBeacon("/api/pageview-timer", JSON.stringify({ + "path": window.location.pathname, + "start_time": startTime.toISOString(), + "end_time": stopTime.toISOString() + })); + } + + window.addEventListener("pagehide", logTime, false); +})(); |
