For conceptual overviews of user and session scopes, including how
Google Analytics defines and strictly bounds sessions by inactivity, refer to the
[Dimensions and metrics: About Analytics sessions](https://support.google.com/analytics/answer/9191807) and the guide to [Scopes
of traffic-source dimensions](https://support.google.com/analytics/answer/11080067).

This guide covers developer-specific challenges and best practices to manage
session configurations and passive tracking.

## Pair page-level dimensions with session metrics

One of the most common reporting nuances occurs when you pair page-scoped
dimensions (for example, page path and screen class) with the session-level
Sessions metric.

### Session and view definitions

- **Sessions** counts the unique periods of time during which a given page
  path was loaded at least once.

- **Views** (pageviews) counts the total cumulative number of times the page
  path was loaded.

### Example

Consider a single session with the following user navigation path: `/home` →
`/products` → `/home` → Exit

If this is the only session, a report configured with
**Page path and screen class** and **Sessions** or **Views** metrics displays:

| Page path | Sessions | Views |
|---|---|---|
| `/home` | 1 | 2 |
| `/products` | 1 | 1 |
| **Total (Google Analytics deduplicated)** | **1** | **3** |

*If you sum the rows, it yields 2 sessions, but the true property total is
deduplicated to 1.*

### Customization rules

- **Sessions with page path** refers to unique sessions that *visit* the path at least once.
- **Sessions with landing page** refers to unique sessions *starting* on the path. To see landing traffic, always use **Landing page + query string** rather than **Sessions with page path**.
- **Views** always counts total load frequency.

## Best practices for developers and analysts

- **Keep scopes consistent** : Do not mix user-scoped traffic dimensions (for example, **First user default channel group** ) with session-scoped metrics (for example, **Average session duration**) if your goal is to understand session performance.
- **Validate `session_start` in DebugView** : During the QA and verification phase, use standard debugging tools like the Google Analytics DebugView to confirm that `session_start` fires correctly upon session initiation.

## Best practices to manage session timeouts

A Google Analytics session default duration is **30 minutes**.

We don't recommend implementing custom code to periodically "ping" Google Analytics
to prevent inactivity timeouts. If you artificially inflate session
metrics, it distorts user behavior data. Instead, utilize built-in Google Analytics
features or target meaningful engagement events to offer a cleaner
solution.

### Why generic "keep-alive" pings are bad practice

- **Distorted core metrics:** If a user walks away from their tab, they are genuinely inactive. If you force the session to stay open, it creates "zombie sessions" and falsely inflates your **Average Session Duration**. This masks the true point at which users lose interest or abandon your site.
- **Impact on engaged sessions:** Google Analytics defines an engaged session as one that lasts longer than 10 seconds, features 2 or more page views, *or* triggers a key event (formerly conversion event). If you artificially keep a session open, it makes the session appear engaged, which inflates your engagement rate.
- **Data bloat and costs:** If you constantly fire blank background ping events, it increases event count noise and raises data warehouse costs if you export Google Analytics data to BigQuery.

### When to track passive engagement (and how to do it)

There are legitimate scenarios where a user is actively engaged with content but
does not trigger standard Google Analytics interaction events (like clicks or
page changes). In these cases, instead of a generic keep-alive ping, capture
**meaningful, user-initiated progress events**:

- **Long-form video content:** A user who watches an embedded 45-minute video will remain passive for over 30 minutes, and risk session expiration.
- **Deep-dive articles:** A user may spend 40 minutes to absorb a technical guide, and scroll slowly but trigger no navigation actions.
- **Interactive web applications:** Users who monitor live feeds, stock tickers, or data dashboards consume information passively without clicks.

> [!IMPORTANT]
> **Important:** When you implement custom measurement timers on web applications, always combine your events with the built-in browser [Page Visibility API](https://developer.mozilla.org/docs/Web/API/Page_Visibility_API).

If the user minimizes the browser window or switches tabs, the background pings
must stop.

#### Code example: Visibility-aware event ping

The following JavaScript pattern demonstrates how to track passive engagement
and respect tab visibility. Adjust the tracking interval and parameter
value (for example, 5 minutes or 300,000 ms) based on your specific use case,
such as the typical duration of your videos or long-form articles:

    const TRACKING_INTERVAL_MILLIS = 5 * 60 * 1000;

    let engagementInterval;

    function startEngagementTracking() {
      // Prevent duplicate intervals if tab becomes visible
      if (engagementInterval) return;

      engagementInterval = setInterval(() => {
        gtag('event', 'passive_engagement', {
          'engagement_time_msec': TRACKING_INTERVAL_MILLIS
        });
      }, TRACKING_INTERVAL_MILLIS);
    }

    function stopEngagementTracking() {
      if (engagementInterval) {
        clearInterval(engagementInterval);
        engagementInterval = null;
      }
    }

    // Start tracking initially if the page is visible
    if (!document.hidden) {
      startEngagementTracking();
    }

    // Stop tracking when tab is hidden, resume when visible
    document.addEventListener('visibilitychange', () => {
      if (document.hidden) {
        stopEngagementTracking();
      } else {
        startEngagementTracking();
      }
    });

### Google Analytics enhanced measurement versus custom tracking

Google Analytics features **Enhanced Measurement**, which automatically handles
some passive tracking scenarios out of the box, though it has specific
limitations.

| Interaction type | Handled by enhanced measurement? | Requirements / action items |
|---|---|---|
| **YouTube video embeds** | **Yes** | Fires `video_start`, `video_complete`, and `video_progress` milestones automatically at **10%, 25%, 50%, and 75%** (requires JS API support enabled). |
| **Non-YouTube videos** *(HTML5, Vimeo)* | **No** | Requires custom implementation. Fire events programmatically using `gtag.js` or manage triggers using Google Tag Manager (GTM). |
| **Standard page scrolling** | **Partial** | Fires a single `scroll` event **only when the user hits the 90% mark** of a page. |
| **Incremental reading progress** | **No** | Disable default Google Analytics scroll tracking and implement custom scroll thresholds (for example, 25%, 50%, 75%) programmatically or in GTM. |

### The cleanest alternative: Adjust the Google Analytics session timeout limit

If your website naturally centers around long-form content, video courses, or
continuous app usage, you don't need to inject custom script hacks. You can
adjust the default 30-minute threshold inside the Google Analytics interface up
to a maximum of **7 hours and 55 minutes** . For instructions, see
[Adjust session timeout](https://support.google.com/analytics/answer/9191807#session-counts&zippy=%2Cadjust-session-timeout).