jasonzissman / timeme.js Goto Github PK
View Code? Open in Web Editor NEWA JavaScript library to accurately time how long a user views a web page, disregarding idle time and time when the tab or window is minimized.
License: MIT License
A JavaScript library to accurately time how long a user views a web page, disregarding idle time and time when the tab or window is minimized.
License: MIT License
Firefox version 68.0.2 (64-bit)
Platform OSX High Sierra 0.13.6
How to reproduce
The most logical place for timing data to go might be existing analytics tools, such as Google Analytics.
Is it possible to use an existing session or custom dimension to send the websocket output (time on page) to GA for better analysis, in combination with all other site metrics?
very nice work, it helped me too much.
I'm trying to send the time spent to the server through the web socket protocol but I don't know what is the app id that I must provide it with the websocketOptions
how to get it ?
I save time the user spends working on a project on my page. Because saving to my database isn't that reliable just on unload, I also save the time spent every time the user saves their project.
So, after a user saves their project, I send that time to be saved to my database, and want to reset the timer to zero.
I thought that's what ResetRecordedPageTime(my page name) would do. What it actually seemed to do is remove the timer altogether - if I reset the page time, then wait, then try to retrieve time spent, I get NaN.
What I'm doing is calling ResetRecordedPageTime(mypage), then re-initializing the timer (same page name every time). This seems to work and have the behavior I want.
Should ResetRecordedPageTime destroy the timer? The docs should indicate this, if so. And it would be nice to have a function that lets you set a timer value to whatever you want so you can zero it out after saving the time saved.
If a user is scrolling inside an iframe, TimeMe doesn't recognize that they are still interacting with the page.
Nvm: realized it was an iframe issue.
downloaded js files from master and included them in my project. Trying to use this function but keeps saying it's not a function. Am I missing something?
clear_
to reset_
inside the README.mdThanks
At several points the library adds focus and blur handlers to the window. However, there is no explicit unloading of these events.
Even after calling stopTimer or stopAllTimers events handlers are still registered and continued to fire. Because the event handlers are anonymous functions there is no explicit way to removing those specific handlers. Removing all handlers from the window could have unintended side effects on the client application.
I run startTimer from a setInterval(); This is not detected, so it still starts counting while the page is not visible.
I think it would be best to immediately stop the timer when a startTimer() is triggered while being invisible. This will create an duration of '0', as would probably be sensible:
startTimer: function () {
var pageName = TimeMe.currentPageName;
if (TimeMe.startStopTimes[pageName] === undefined) {
TimeMe.startStopTimes[pageName] = [];
} else {
var arrayOfTimes = TimeMe.startStopTimes[pageName];
var latestStartStopEntry = arrayOfTimes[arrayOfTimes.length - 1];
if (latestStartStopEntry !== undefined && latestStartStopEntry.stopTime === undefined) {
// Can't start new timer until previous finishes.
return;
}
}
TimeMe.startStopTimes[pageName].push({
"startTime": new Date(),
"stopTime": undefined
});
// immediately stop timer, if start is requested while page is out of focus:
if(TimeMe.getIfVisibleHandle().now() == false)
{
TimeMe.stopTimer();
}
},
Hi.
first of all, really nice job!
I have a situation where i need to save the time in database, then reset the value to 0
this is my code
` setInterval(function () {
var currentTime = TimeMe.getTimeOnCurrentPageInSeconds().toFixed(2);
$.post("/admin/user_times", {time: currentTime, user_id: user_id}, function(data, status){
TimeMe.resetRecordedPageTime('home-page');
console.log('aici:' + currentTime);
});
}, 5);
}, 5000);`
But after saving the time, i get undefined and "Uncaught TypeError: Cannot read property 'toFixed' of undefined"
What i'm doing wrong?
Thanks!
What are the implications of this for the user? What will they see?
Some times the time that outputs the module is incredibly high.
I'm using this module on a tracking system and some times the time that i received from the module is really high.
Any ideas on what can be causing this?. I think it might be a browser incompatibility. But sadly i haven't been able to track the bug down
When a user is watching a video e.g. YouTube embedded on the page, he fastly goes idle with your script (not accounting the view time of a video).
It would be good, if you could implement a beacon function which could be triggered manually in order to let the script continue measuring time.
You accidently pushed the bower_components folder, I suggest to remove it and add .gitignore...
If a user switches from the browser window by alt-tabbing out, the user is still considered as active. The demo provided also show this behavior!
Hello,
Is there any way to auto save time spent on the page to database table (because i need to add some other data like usename) ?
Good job by the way !
TimeMe works beautifully and we're using as directed to measure the amount of time people are using our site. We set a timer on page load and on various page events we post this back to the server and record it in a database.
Very occasionally, we see enormous times in these logs, like on the order of 7 million seconds, which is about 2 months. Since the activity timeout is 5 seconds, I don't think there's any way that this could be a true time spent on the page. Even if you left the page up and never timed out, it's hard to imagine a page staying alive for that amount of time.
And sometimes we'll see a time like 700,000 seconds, and then subsequent activity a minute later of 700,060 seconds, so it seems like TimeMe is somehow being initialized to this extreme value, and working correctly thereafter.
It's always probable that this is a bug in my code, but so far I don't see it.
Is it posible to tack an element by passing the element it self instead of it's ID ?
This would be specially useful for Apps developed in Polymer/WebComponents
Bit confused about the license you've chosen to publish this under.
Is it Apache License, as the attached license file, or is it MIT as the bower.json file claims?
You can view the error here
https://my.trackjs.com/shared/NmI1YThiYzcxYzM3NDIwMzk0NWY2YjJkMTUxMDNjMjk#telemetry
Click on Stack Trace for more information
Please confirm that ifvisible.js was loaded before you using it. Maby you pass it via the closure:
(function (ifvisible) { if (typeof ifvisible === 'object') { } })(this.ifvisible);
If you do not need websocket time tracking
and the element time tracking
, I have written a library in TypeScript with a different API and architecture that does kind of the same.
https://github.com/atlassian/browser-interaction-time
https://atlassian.github.io/browser-interaction-time/
This package looks like it will definitely fit my needs! Quick question, though. Can anyone suggest some approaches for utilizing Pusher as the websocket receiver for the timing data? I'd rather not have to roll something just for this, since we already use Pusher on our pages.
Thanks for any guidance or suggestions!
First of all, fantastic work on the library. I am looking to measure 2 things
Suggestions are super appreciated
Demo link http://timemejs.com/ README.md is broken.
Try this:
TimeMe.setCurrentPageName('test'); TimeMe.initialize(); TimeMe.resetRecordedPageTime('test'); TimeMe.setCurrentPageName('test'); TimeMe.initialize();
is causing a type error:
TypeError: arrayOfTimes[(arrayOfTimes.length - 1)] is undefined
I'm building and embeddable JS widget which has a requirement not to inject any new global variable to the page. I'm using requireJS to do this and importing TimeMe as a module. The import works, but because TimeMe expects ifvisible to be available in the global scope, and it's isn't via RequireJS, it can't initialize properly.
I've made a couple of changes that I'd like to get your opinion on as I'm not that familiar with AMD modules and requireJS.
I've added ifvisible as a dependent module in define
and set it as a property (which I don't think I like):
if (typeof define === "function" && define.amd) {
define(['ifvisible'], function(ifvisible) {
TimeMe.ifvisible = ifvisible;
return TimeMe;
});
} else {
window.TimeMe = TimeMe;
}
and then detected this.ifvisible
in getIfVisibleHandle
to set the handle correctly.
getIfVisibleHandle: function(){
if (typeof ifvisible === 'object') {
return ifvisible;
else if (typeof this.ifvisible === 'object') {
return this.ifvisible;
} else {
if (typeof console !== "undefined") {
console.log("Required dependency (ifvisible.js) not found. Make sure it has been included.");
}
throw {
name: "MissingDependencyException",
message: "Required dependency (ifvisible.js) not found. Make sure it has been included."
};
}
},
I think ideally i'd rewrite the class to have a constructor function and pass in the dependency but it's a lot of changes. Interested to hear your thoughts on this!
Hi,
Thanks for this great plugin. as I can see when page is reloaded, time counter is set to '0'. I have below query
i.e. instead of tracking time spent on page I would like to see total time spent on website when user visited different pages
Thanks
Pravin
Hello,
I have tested to send a time to database with AJAX script with the event onbeforeunload and it seems to not working.
Someone has the same issue ?
I tried with onunload and it seems to work, any problem to use this function instead onbeforeunload ?
Regards
On version 2, Argument should be called websocketOptions instead of websocktOptions
2.1 would break the API but fix this, along with other 23 commits pending.
I want to just know the time a user completely spends on the site even if the user is afk or not...
i found this and tried configuring it so i could get the time a user has my site up for.
When i ran it with the trackWhenUserGoesIdle
and trackWhenUserLeavesPage
set to false, it continued to stop the timer...
Pls tell me if theres a way i can fix it in my code or if this is a problem from the developers...
heres the code:
<script src="../timeme.min.js"></script>
<script type="text/javascript">
TimeMe.initialize({
trackWhenUserGoesIdle: false,
trackWhenUserLeavesPage: false,
});
I have the 'idleTimeoutInSeconds' set to -1, however this doesn't seem to have an effect.
TimeMe.initialize({
currentPageName: "live.php", // current page
idleTimeoutInSeconds: -1 // seconds
});
setInterval(function(){
var timeSpentOnPage = TimeMe.getTimeOnCurrentPageInSeconds();
console.log(timeSpentOnPage);
$.post( "record.php", { uuid: "<?php echo $uuid; ?>", time: timeSpentOnPage, page: 'live.php' } );
}, 1000);
Otherwise, script runs fine.
Hello, when the user click on an iframe on a page TimeMe.js considers that the user has left the page because a click on an iframe triggers 'blur' on the window.
Do you have an idea to solve this issue ?
I have a page with embedded videos (not iframes). Short of writing a function to monitor the video embed pause/start times, can TimeMe be adjusted to factor in these elements?
Thanks
Recently, I started using TimeMe for tracking the time. But when I leave the session for long hours and resume the work, it seems it is not accurate. It is adding hours to the actual time I spent on . Any idea why this is happening?
I've been playing around with TimeMe.js today, however it seems there is no way to disable a timeout. By default, the timeout appears to be 60 seconds, and any other numbers (0, -1, infinity) all seem to change the timeout to 0. I've also tried 2678400 seconds as well, although it seems to default to the 0 timeout.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.