Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track site visits and time spent on sites #23

Merged
merged 1 commit into from
Jun 4, 2020

Conversation

sharon-wang
Copy link
Member

@sharon-wang sharon-wang commented Jun 3, 2020

fixes: #3 , fixes: #7

  • track time spent on webpage
    • add time spent on site every 2 seconds
  • track number of visits to webpage
  • store date of first visit to webpage
  • store date of most recent visit to webpage

NOTES

  • may need to keep an eye out for time spent on sites - seems to be working, but setInterval() seems a bit sketchy
  • tested on Firefox and Chrome - both working

@sharon-wang sharon-wang added GftW x DEV Hackathon Part of our hackathon prototype sketchy PR developed and merged without code review labels Jun 3, 2020
Copy link
Member

@vezwork vezwork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

* Get the current time based on the user's timezone.
*/
function getCurrentTime() {
return new Date();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: a more accurate alternative to new Date() for the purposes of timing is performance.now().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note, new Date() and performance.now() have reduced time precision to protect against attacks.

new Date()

In Firefox, the privacy.reduceTimerPrecision preference is enabled by default and defaults to 20µs in Firefox 59; in 60 it will be 2ms.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now#Reduced_time_precision

performance.now()

In Firefox, the privacy.reduceTimerPrecision preference is enabled by default and defaults to 1ms.

https://developer.mozilla.org/en-US/docs/Web/API/Performance/now#Reduced_time_precision


Although performance.now() has more precision than new Date(), it might be less performant as a result - although its performance seems to be highly dependent on browser. As you can see below, the performance is pretty opposite.

Chrome
image

Firefox
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Informative! Nice.

track time spent on webpage
add time spent on site every 2 seconds
track number of visits to webpage
store date of first visit to webpage
store date of most recent visit to webpage

Signed-off-by: sharon-wang <sharon-wang-cpsc@outlook.com>
@sharon-wang sharon-wang merged commit 848d87f into esse-dev:master Jun 4, 2020
@sharon-wang sharon-wang deleted the trackSiteVisits branch June 4, 2020 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GftW x DEV Hackathon Part of our hackathon prototype sketchy PR developed and merged without code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Track # of visits to websites Track time spent on a webpage
2 participants