6 min read

How to Visualize Pages Per Session in Google Analytics 4

Pages Per Session tells you how many pages users browse during a single visit—it's one of the clearest signals of engagement. If your pages per session is dropping, users are bouncing faster, which means your content or navigation needs work. GA4 makes this metric accessible through its UI and APIs, so you can monitor trends, dig into audience segments, and pull the data into your own dashboards.

View Pages Per Session in the GA4 Dashboard

The quickest way to see this metric is through GA4's standard reports.

Step 1: Open the Engagement Report

In GA4, navigate to Reports on the left sidebar, then click Engagement. You'll see a section labeled Engagement Overview which includes a card for Pages per session. This gives you a snapshot of the current value and how it's trending.

javascript
// GA4 tracks pages per session automatically
// Access via the Realtime or Reports API
// No manual configuration needed—gtag.js sends page_view events by default
gtag('config', 'GA_MEASUREMENT_ID', {
  page_path: window.location.pathname,
  page_title: document.title
});
Pages Per Session is calculated from page_view events. Ensure gtag.js is installed correctly.

Step 2: Filter by Date Range and Audience

At the top of the report, use the date picker to select your time window. If you want to see pages per session for a specific audience, click on the Audience tab and drill into a segment. GA4 automatically calculates the metric for whatever filters you apply.

Step 3: Create a Custom Exploration to Segment the Data

For deeper analysis, go to Explore in the left menu and select Blank exploration. Drag Pages per session to the Metrics column, and drag dimensions like Device category, Traffic source, or Page title to the Rows section. This lets you see which pages, devices, or traffic sources have the highest engagement.

Watch out: GA4 rounds Pages Per Session to two decimal places in the UI. For precise values, export the data or use the Data API.

Export Pages Per Session Data with the Google Analytics Data API

If you're building dashboards or custom reports, pull data from GA4 programmatically using the Data API.

Step 1: Enable the Google Analytics Data API

Go to the Google Cloud Console, search for Google Analytics Data API v1, and click Enable. This API lets you query GA4 reports without touching the UI.

javascript
// Install the client library
// npm install @google-analytics/data

const { BetaAnalyticsDataClient } = require('@google-analytics/data');
const client = new BetaAnalyticsDataClient();

// Set your property ID (found in GA4 Admin settings)
const propertyId = 'YOUR_GA4_PROPERTY_ID';

Step 2: Run a Report Query

Use the runReport() method to fetch Pages Per Session data. Request screenPageViews and sessions metrics, then divide them to calculate the ratio.

javascript
async function getPagesPerSession(propertyId, startDate, endDate) {
  const request = {
    property: `properties/${propertyId}`,
    dateRanges: [{
      startDate: startDate,
      endDate: endDate,
    }],
    metrics: [
      { name: 'screenPageViews' },
      { name: 'sessions' },
    ],
    dimensions: [{ name: 'date' }],
  };

  const response = await client.runReport(request);
  response.rows.forEach(row => {
    const pageViews = parseInt(row.metricValues[0].value);
    const sessions = parseInt(row.metricValues[1].value);
    const pagesPerSession = (pageViews / sessions).toFixed(2);
    console.log(`${row.dimensionValues[0].value}: ${pagesPerSession}`);
  });
}

getPagesPerSession('123456789', '2024-01-01', '2024-03-26');
GA4 doesn't have a direct pagesPerSession metric. Calculate it by dividing screenPageViews by sessions.

Step 3: Add Dimensions to Break Down the Data

Expand the dimensions array to segment by device, traffic source, or page title. Add { name: 'deviceCategory' } to see how mobile vs. desktop users compare in pages per session.

javascript
const request = {
  property: `properties/${propertyId}`,
  dateRanges: [{ startDate: '2024-01-01', endDate: '2024-03-26' }],
  metrics: [
    { name: 'screenPageViews' },
    { name: 'sessions' },
  ],
  dimensions: [
    { name: 'deviceCategory' },
    { name: 'firstUserSourceMedium' },
  ],
  limit: 250,
};

const response = await client.runReport(request);
Tip: GA4's Data API caps queries at 100k rows. For large datasets, paginate using offset or set up a scheduled export to Google Cloud Storage.

Track Pages Per Session with Custom Events

If the built-in metric isn't granular enough, create custom events to track navigation depth.

Step 1: Add a Page Counter to Your Site

Use sessionStorage to track how many pages a user has viewed in the current session. On each page load, increment the counter and send it as a custom event parameter to GA4.

javascript
// Track pages viewed per session using sessionStorage
if (!sessionStorage.getItem('pageCount')) {
  sessionStorage.setItem('pageCount', '1');
} else {
  let count = parseInt(sessionStorage.getItem('pageCount')) + 1;
  sessionStorage.setItem('pageCount', count.toString());
}

const pageCount = sessionStorage.getItem('pageCount');

// Send as a custom event
gtag('event', 'page_engagement', {
  pages_viewed: parseInt(pageCount),
  page_title: document.title,
  session_id: performance.getEntriesByType('navigation')[0].name,
});
sessionStorage persists page count across a single session. GA4 automatically resets it when the session expires (30 minutes of inactivity).

Step 2: Create a Custom Metric in GA4

In GA4 Admin settings, go to Custom definitions > Custom metrics. Create a new metric based on your custom event parameter pages_viewed. This lets you filter and segment by pages per session in explorations.

Step 3: Report on the Custom Metric

Once the metric is live (data takes 24 hours to backfill), go to Explore and add your custom metric to the report. Compare it against user segments to see which audience engages deepest.

javascript
// Query the custom metric via the Data API
const customMetricRequest = {
  property: `properties/${propertyId}`,
  dateRanges: [{ startDate: '2024-01-01', endDate: '2024-03-26' }],
  metrics: [{ name: 'customEvent:pages_viewed' }],
  dimensions: [{ name: 'userSegment' }],
};

const response = await client.runReport(customMetricRequest);
Watch out: Custom event parameters have a 100-character limit, and GA4 stores only the top 1000 unique values per parameter. For high-cardinality data, use event parameters sparingly.

Common Pitfalls

  • Assuming Pages Per Session is accurate if you're not firing page_view events. GA4 only counts page_view events. Custom events don't contribute to this metric.
  • Forgetting that GA4 resets sessions every 30 minutes of inactivity. A user who leaves your site and returns after 31 minutes starts a new session, which lowers the pages per session average for the earlier session.
  • Using pageViews instead of screenPageViews in the Data API query. The metric names differ by context—always check the official API documentation for the exact field name.
  • Not filtering out bot traffic. Spam bots can inflate pages per session by crawling multiple pages in a session. Use GA4's Bot traffic filter under Admin > Data filters.

Wrapping Up

Pages Per Session is a straightforward engagement signal, and GA4 surfaces it through the UI, Data API, and custom events. Start with the Engagement report to spot trends, then move to the Data API or Explorations when you need to dig into specific audiences or traffic sources. If you want to track this automatically across tools, Product Analyst can help.

Track these metrics automatically

Product Analyst connects to your stack and surfaces the insights that matter.

Try Product Analyst — Free