Skip to content

Analytics

Emit analytics only when the page is visible and the user is active.

Implementation

ts
function track(name: string, payload: Record<string, unknown>) {
  const snapshot = lifecycle.getSnapshot();
  if (snapshot.page.visibility !== "visible") return;
  if (snapshot.session.activity === "idle") return;
  analytics.track(name, payload);
}

Playground

Visibility Playground · Idle Playground

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