Skip to content

Commit

Permalink
expire client-side session at midnight UTC, for now
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvankooten committed Jun 13, 2018
1 parent e795eb1 commit 70d97b0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion assets/src/js/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as util from './lib/util.js';

let queue = window.fathom.q || [];
let trackerUrl = '';

const commands = {
"trackPageview": trackPageview,
"setTrackerUrl": setTrackerUrl,
Expand Down Expand Up @@ -98,11 +99,14 @@ function trackPageview() {
let i = document.createElement('img');
i.src = trackerUrl + util.stringifyObject(d);
i.addEventListener('load', function() {
let now = new Date();
let midnight = new Date(Date.UTC(now.getFullYear(), now.getMonth(), now.getDate(), 24, 0, 0));
let expires = Math.round((midnight - now) / 1000);
data.pagesViewed.push(path);
data.isNewVisitor = false;
data.isNewSession = false;
data.lastSeen = +new Date();
cookies.set('_fathom', JSON.stringify(data), { expires: 60 * 60 * 24});
cookies.set('_fathom', JSON.stringify(data), { 'expires': expires });
});
document.body.appendChild(i);
window.setTimeout(() => { document.body.removeChild(i)}, 1000);
Expand Down

0 comments on commit 70d97b0

Please sign in to comment.