Skip to content

Page Tracking

Measure how long users spend with the page visible.

Implementation

ts
let visibleSince: number | undefined;

lifecycle.on("page:visible", () => {
  visibleSince = Date.now();
});

lifecycle.on("page:hidden", () => {
  if (visibleSince) {
    trackDuration(Date.now() - visibleSince);
    visibleSince = undefined;
  }
});

Playground

Visibility Playground

JOC is a JayOnCode monorepo of @jayoncode/* packages. Docs sync from source via TypeDoc and sync scripts.