# Member usage analytics

## What is measured

Authenticated Nuxt usage is grouped into OAuth login sessions. The frontend sends a heartbeat every 30 seconds while the site is visible, focused, and the user has interacted within the last five minutes.

The report contains:

- user and member company;
- last login in each month;
- number of logins in each month;
- average active session duration in minutes.

OAuth token refreshes, page reloads, and opening another browser tab do not create another login record. A new record is created after the user logs out and authenticates again. IP addresses, user agents, visited paths, query strings, and page content are not stored.

## Deploy

Run the database migration in the Laravel application:

```bash
php artisan migrate
```

Deploy both applications so the Laravel API and the Nuxt plugin become active at the same time. Existing historical activity cannot be reconstructed; collection begins after deployment.

## Export

In the Laravel backoffice, open **Users**. Choose the start and end dates next to the statistics icon, then click the icon to download the XLSX report.

The endpoint can also be opened directly by an administrator with `users.view` permission:

```text
/admin/member-usage/export?from=2026-08-01&to=2026-08-31
```

Dates use the Laravel application timezone. If omitted, the report covers the last 30 days. The report contains one row per user per month, ordered by month and login count, and can be sorted or filtered further in Excel.

## Accuracy and privacy

- Time from hidden, unfocused, or idle tabs is excluded.
- A failed heartbeat can make active time lower than the real value; it is never extrapolated from OAuth token lifetime.
- Each heartbeat is capped at 60 seconds server-side.
- The export is restricted to authenticated backoffice users with `users.view` permission because it contains personal usage data.
- Define a retention period appropriate to the organization's privacy policy. For example, sessions older than 12 or 24 months can be deleted with a scheduled Laravel command.
