Is there any native functionality to do this, or any libraries that would be easy to import in order to log data on how long a user spends on an app/page?
Hey @PAllred! Thanks for reaching out.
Retool does provide some built-in tools for tracking user activity - namely audit logs and user analytics - but I don't think either specifically tracks time. The latter is also only available on an Enterprise plan.
When building an integrated solution, the complexity can vary drastically depending on what you're trying to accomplish. The simplest implementation I can think of wouldn't even require a library, just a custom component and some JavaScript:
// Initialize start time
let startTime = Date.now();
// Track time on page unload
window.addEventListener("click", () => {
let timeSpent = Date.now() - startTime;
console.log("Time spent on page:", timeSpent, "ms");
});
Something like Google Analytics is often overkill and actually doesn't play very nicely with Retool, given the fact that most JS is executed in a sandbox environment and doesn't have access to the top-level document. Does the simple solution above suffice or are you looking for slightly more complex functionality?