aboutsummaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
Diffstat (limited to 'static')
-rw-r--r--static/img/pageview_flowchart.pngbin0 -> 39421 bytes
-rw-r--r--static/js/pageview_timer.js31
2 files changed, 31 insertions, 0 deletions
diff --git a/static/img/pageview_flowchart.png b/static/img/pageview_flowchart.png
new file mode 100644
index 0000000..99b1ee0
--- /dev/null
+++ b/static/img/pageview_flowchart.png
Binary files differ
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);
+})();