strictly respect do not track

This commit is contained in:
Cadey Ratio 2019-08-19 16:53:28 +00:00
parent e4768b4073
commit 815638b2ed
2 changed files with 26 additions and 16 deletions

View File

@ -22,6 +22,11 @@ func init() {
} }
func handlePageViewTimer(w http.ResponseWriter, r *http.Request) { func handlePageViewTimer(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("DNT") == "1" {
http.NotFound(w, r)
return
}
data, err := ioutil.ReadAll(r.Body) data, err := ioutil.ReadAll(r.Body)
if err != nil { if err != nil {
ln.Error(r.Context(), err, ln.Info("while reading data")) ln.Error(r.Context(), err, ln.Info("while reading data"))

View File

@ -10,21 +10,26 @@
be ineffectual. be ineffectual.
*/ */
let startTime = new Date(); (function() {
let dnt = navigator.doNotTrack;
function logTime() { if (dnt == "1") {
let stopTime = new Date(); return;
let message = JSON.stringify(
{
"path": window.location.pathname,
"start_time": startTime.toISOString(),
"end_time": stopTime.toISOString(),
}
);
if (!window.navigator.sendBeacon("/api/pageview-timer", message)) {
alert("wtf");
} }
}
window.addEventListener("pagehide", logTime, false); let startTime = new Date();
function logTime() {
let stopTime = new Date();
let message = JSON.stringify(
{
"path": window.location.pathname,
"start_time": startTime.toISOString(),
"end_time": stopTime.toISOString(),
}
);
window.navigator.sendBeacon("/api/pageview-timer", message);
}
window.addEventListener("pagehide", logTime, false);
})();