5 min read

How to Set Up Alerts for User Acquisition in Google Analytics 4

GA4 doesn't send you a notification when new user growth drops. If you're shipping a marketing campaign or tracking sign-up performance, you need alerts to catch problems before your team does. Here's how to build them using GA4's Data API and Google Apps Script.

Fetch User Acquisition Data from the GA4 Data API

The GA4 Data API lets you pull metrics on-demand. We'll use it to check your daily new users and compare against a baseline.

Set up a service account for API access

Go to Google Cloud Console > APIs & Services > Credentials. Create a Service Account and download the JSON key. Share your GA4 property with the service account email via Admin > Property Access Management. The service account needs Viewer or Editor role.

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

const serviceAccountKey = JSON.parse(fs.readFileSync('./service-account-key.json', 'utf8'));
const analyticsDataClient = new BetaAnalyticsDataClient({
  projectId: serviceAccountKey.project_id,
  credentials: {
    client_email: serviceAccountKey.client_email,
    private_key: serviceAccountKey.private_key,
  },
});
Authenticate the Data API client with your service account credentials

Create a Data API request for new users

Call the `runReport` method with the newUsers metric and date dimension. This returns daily new user counts. Set your date range to the last 7 days to get a trend and a baseline.

javascript
async function getNewUserMetrics(propertyId) {
  const request = {
    property: `properties/${propertyId}`,
    dateRanges: [
      {
        startDate: '7daysAgo',
        endDate: 'today',
      },
    ],
    dimensions: [{name: 'date'}],
    metrics: [{name: 'newUsers'}, {name: 'activeUsers'}],
  };

  const response = await analyticsDataClient.runReport(request);
  return response.rows;
}

const rows = await getNewUserMetrics('123456789'); // Your GA4 property ID
console.log(rows); // [{values: ['20250325', '1240', '5600']}, ...]
Fetches daily new user counts for the last 7 days

Compare today's new users against a threshold

Extract today's newUsers value and compare it to yesterday's or a 7-day rolling average. If the drop is larger than your threshold (e.g., 20%), flag it for an alert.

javascript
function checkNewUserAlert(rows) {
  const today = rows[rows.length - 1];
  const yesterday = rows[rows.length - 2];
  
  const todayNewUsers = parseInt(today.metricValues[0].value);
  const yesterdayNewUsers = parseInt(yesterday.metricValues[0].value);
  
  const percentChange = ((todayNewUsers - yesterdayNewUsers) / yesterdayNewUsers) * 100;
  const threshold = -20; // Alert if down 20% or more
  
  if (percentChange < threshold) {
    return {
      shouldAlert: true,
      message: `New users dropped ${Math.abs(percentChange).toFixed(1)}% today (${todayNewUsers} vs ${yesterdayNewUsers})`
    };
  }
  return {shouldAlert: false};
}
Triggers an alert if new user count drops more than 20%

Automate Alerts with Google Apps Script

Google Apps Script runs scheduled tasks on Google's servers for free. Pair it with Gmail to send yourself alerts when thresholds are breached.

Create a Google Apps Script project

Go to script.google.com and create a new project. Name it something like "GA4 User Acquisition Monitor". In Project Settings, enable the Google Analytics Data API under APIs & Services.

javascript
// In Google Apps Script, the AnalyticsData service is built-in
// No npm install needed—just use it directly

function queryGA4UserAcquisition() {
  const propertyId = '123456789'; // Your GA4 property ID
  const request = {
    dateRanges: [
      {
        startDate: '2daysAgo',
        endDate: 'today',
      },
    ],
    dimensions: [{name: 'date'}],
    metrics: [{name: 'newUsers'}],
  };

  const response = AnalyticsData.Properties.runReport(request, `properties/${propertyId}`);
  return response.rows;
}
Apps Script wrapper for the GA4 Data API—no authentication code needed

Write the alert logic and send an email

Check if new users fell below your threshold. Use the `GmailApp.sendEmail()` method to notify yourself. Include the actual metric values in the email so you don't have to log into GA4 to diagnose.

javascript
function monitorUserAcquisition() {
  const rows = queryGA4UserAcquisition();
  const today = rows[rows.length - 1];
  const yesterday = rows[rows.length - 2];
  
  const todayNewUsers = parseInt(today.metricValues[0].value);
  const yesterdayNewUsers = parseInt(yesterday.metricValues[0].value);
  const percentChange = ((todayNewUsers - yesterdayNewUsers) / yesterdayNewUsers) * 100;
  
  if (percentChange < -20) {
    const emailBody = `GA4 Alert: New user acquisition dropped ${Math.abs(percentChange).toFixed(1)}%\n\nToday: ${todayNewUsers} new users\nYesterday: ${yesterdayNewUsers} new users\n\nReview trends: https://analytics.google.com/analytics/web/#/a/...`;
    GmailApp.sendEmail('[email protected]', '🚨 GA4 Alert: User Acquisition Drop', emailBody);
  }
}

// Save and run once to test, then set up a trigger

Schedule the script to run daily

In the Triggers menu (clock icon), create a new trigger. Set it to run the monitorUserAcquisition function every day at 9 AM. Apps Script will execute it on schedule and send you an email only when the alert condition is met.

Optional: Visualize Trends in Looker Studio

If you prefer a dashboard over email alerts, Looker Studio connects directly to GA4 and shows you acquisition trends in real time.

Create a Looker Studio report connected to GA4

Go to Looker Studio and click Create > Report. Add a Data Source and select Google Analytics 4. Choose your GA4 property. Add a Scorecard chart showing newUsers with a date filter for Last 7 Days.

javascript
// Looker Studio uses a visual editor—no code required
// But you can embed the report in a web app:

const reportUrl = 'https://lookerstudio.google.com/reporting/YOUR_REPORT_ID/page/YOUR_PAGE_ID';
// Share this link with your team as a bookmark
// Reports auto-refresh every few hours

// To embed in an app:
// <iframe src={reportUrl} width="100%" height="800"></iframe>

Add a trend comparison and source breakdown

In the Scorecard properties, enable Show Comparison and set it to Previous 7 Days. This shows at a glance if acquisition is trending up or down. Add a Table below showing newUsers by Source to see which channels are driving growth.

Common Pitfalls

  • GA4 new user counts can lag by 24-48 hours, especially for some dimensions like source and device. Don't alert on same-day data alone—compare rolling 2-3 day averages instead to avoid noise.
  • The newUsers metric in GA4 is event-based, not session-based like Universal Analytics. If your SDK doesn't fire events consistently or there's a client-side implementation bug, counts will be unexpectedly low.
  • Service account credentials are sensitive—don't hardcode them or commit them to GitHub. Use environment variables or Google Cloud Secret Manager in production.
  • When parsing API responses, the row order matters. The last row is always today, but if your date range includes a partial day (e.g., if you query at 3 PM), today's count is incomplete.

Wrapping Up

You now have three ways to monitor user acquisition in GA4: real-time Data API queries, automated email alerts with Google Apps Script, and a Looker Studio dashboard for your team. Pick the method that fits your workflow—Script for speed, Looker Studio for team visibility. If you want to track alerts across multiple tools and automate response actions, Product Analyst can help you centralize that monitoring.

Track these metrics automatically

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

Try Product Analyst — Free