6 min read

How to Set Up Alerts for Pages Per Session in Google Analytics 4

Pages Per Session tells you how engaged your users are—if it drops suddenly, something's wrong. GA4 doesn't send automatic alerts, but you can set them up in minutes using custom alerts or the Reporting API.

Find Pages Per Session in Your GA4 Dashboard

First, you need to know where this metric lives and what you're looking at.

Navigate to Engagement Reports

In your GA4 property, go to Reports in the left sidebar, then click Engagement. You'll see Pages and screens as one of the pre-built report cards. Click it.

Understand What You're Measuring

Pages Per Session is screenPageViews / sessions. If your average is 3.5 and it drops to 1.8, users are bouncing earlier. High values mean engagement; low values mean friction.

javascript
// Fetch Pages Per Session via GA4 Reporting API
const {BetaAnalyticsDataClient} = require('@google-analytics/data');

const client = new BetaAnalyticsDataClient();

async function getPagesPerSession(propertyId) {
  const response = await client.runReport({
    property: `properties/${propertyId}`,
    dateRanges: [{ startDate: '30daysAgo', endDate: 'today' }],
    dimensions: [{ name: 'date' }],
    metrics: [
      { name: 'screenPageViews' },
      { name: 'sessions' }
    ]
  });
  
  response.rows.forEach(row => {
    const views = parseInt(row.metricValues[0].value);
    const sessions = parseInt(row.metricValues[1].value);
    const pagesPerSession = views / sessions;
    console.log(`Date: ${row.dimensionValues[0].value}, Pages/Session: ${pagesPerSession.toFixed(2)}`);
  });
}

getPagesPerSession('YOUR_GA4_PROPERTY_ID');
This fetches the raw metrics you'll be monitoring
Tip: Add Pages Per Session as a custom metric in any report by clicking Add metric and searching for it.

Create a Custom Alert in GA4

GA4's built-in alerts notify you when metrics shift beyond normal ranges.

Access the Alerts Section

Click the Admin gear icon at the bottom left. Under your property, find Alerts. Click Create alert.

Configure Your Alert Thresholds

Name your alert (e.g., "Pages Per Session Drop"). In Alert type, choose Anomaly detection or Threshold-based. For threshold-based, set Metric to Pages / session, then specify your threshold (e.g., alert if it drops below 2.5).

javascript
// Check if Pages Per Session is below threshold
async function checkThreshold(propertyId, threshold) {
  const response = await client.runReport({
    property: `properties/${propertyId}`,
    dateRanges: [{ startDate: 'yesterday', endDate: 'yesterday' }],
    metrics: [{ name: 'screenPageViews' }, { name: 'sessions' }]
  });
  
  if (!response.rows.length) return;
  
  const views = parseInt(response.rows[0].metricValues[0].value);
  const sessions = parseInt(response.rows[0].metricValues[1].value);
  const pagesPerSession = sessions > 0 ? views / sessions : 0;
  
  if (pagesPerSession < threshold) {
    console.log(`ALERT: Pages Per Session is ${pagesPerSession.toFixed(2)}, below threshold ${threshold}`);
  }
}

checkThreshold('YOUR_GA4_PROPERTY_ID', 2.5);
Build custom alerting logic on top of the Reporting API

Set Notification Channels

Choose how you want to be notified: Email (sends to your Google account) or Slack (if connected). Select multiple channels if needed. Save the alert.

Watch out: Anomaly detection requires 2 weeks of historical data. Don't set thresholds too tight—normal daily variance will trigger false alarms.

Monitor Programmatically with the Reporting API

For production monitoring, query the API directly and build custom alerting logic.

Set Up Service Account Authentication

Create a Google Cloud service account with Viewer access to your GA4 property. Download the JSON key file. Use it to initialize the BetaAnalyticsDataClient.

Build a Deviation-Based Alert Script

Query Pages Per Session daily and compare it to a 7-day rolling average. If today's value deviates by more than 20%, trigger an alert. Store historical values so you can track trends over weeks.

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

const client = new BetaAnalyticsDataClient({
  projectId: 'YOUR_GCP_PROJECT',
  keyFilename: '/path/to/service-account.json'
});

async function monitorPagesPerSession(propertyId) {
  const response = await client.runReport({
    property: `properties/${propertyId}`,
    dateRanges: [{ startDate: '7daysAgo', endDate: 'today' }],
    dimensions: [{ name: 'date' }],
    metrics: [{ name: 'screenPageViews' }, { name: 'sessions' }]
  });
  
  const values = response.rows.map(row => {
    const views = parseInt(row.metricValues[0].value);
    const sessions = parseInt(row.metricValues[1].value);
    return sessions > 0 ? views / sessions : 0;
  });
  
  const avgPagesPerSession = values.reduce((a, b) => a + b) / values.length;
  const today = values[values.length - 1];
  const deviation = Math.abs((today - avgPagesPerSession) / avgPagesPerSession * 100);
  
  if (deviation > 20) {
    console.log(`ALERT: Deviation of ${deviation.toFixed(1)}%. Avg: ${avgPagesPerSession.toFixed(2)}, Today: ${today.toFixed(2)}`);
  }
}

monitorPagesPerSession('YOUR_GA4_PROPERTY_ID');
Deploy as a Cloud Function or Cron job for continuous monitoring
Tip: Store historical values in BigQuery so you can track patterns over months and adjust thresholds as your site grows.

Common Pitfalls

  • GA4's anomaly detection requires 2 weeks of baseline data. You can't use it the day after you set up GA4.
  • Pages Per Session needs both screenPageViews and sessions. If you query it with zero sessions, your script will crash on division—always check for zero values first.
  • Alert thresholds are site-specific. A drop from 4 to 3 pages per session might be normal variance for a blog but catastrophic for an e-commerce product. Calibrate based on your baseline, not industry averages.
  • GA4's Slack alerts are delayed—sometimes by hours. For real-time critical monitoring, query the API directly instead of relying on built-in notifications.

Wrapping Up

You've got Pages Per Session alerts running—now you'll catch engagement drops before customers do. The built-in alerts are fine for most cases, but if you need real-time tracking across multiple metrics and properties, the Reporting API gives you full control. 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