📧 How to Get Automated Email Alerts When Your Blog Traffic Drops to Zero 🚨
Stop constantly checking your analytics dashboard! Set up a Google Apps Script that monitors your GA4 property and sends you an email the moment your traffic hits zero – fully automated and free.
Prerequisites 📋
Make sure you have the following ready before diving into the code:
- 📊 A Google Analytics 4 (GA4) property – set up and collecting data for your blog.
- 🆔 Your GA4 Property ID – found under Admin > Property Settings > Property ID in the Google Analytics dashboard. It looks like
123456789. - 📧 A Gmail account – to receive the alerts and run the script.
Create a Google Apps Script Project 📁
- Go to Google Drive.
- Click New > More > Google Apps Script.
- In the script editor, click the + (Plus) icon next to Services on the left sidebar.
- Find Google Analytics Data API in the list, select it, and click Add.
This adds the required API to your project, allowing the script to read real‑time traffic data.
Add the Automation Code ✍️
Copy the entire JavaScript code below and paste it into the Code.gs file in the script editor.
Replace YOUR_PROPERTY_ID_1, YOUR_PROPERTY_ID_2, and your-email@example.com with your actual details. You can monitor a single site by keeping just one object in the sites array.
function checkMultipleSites() {
// Add your blog details here
const sites = [
{ name: "Your First Blog Name", id: "YOUR_PROPERTY_ID_1" },
{ name: "Your Second Blog Name", id: "YOUR_PROPERTY_ID_2" }
];
const recipientEmail = "your-email@example.com"; // Your Email Address
let inactiveSites = [];
sites.forEach(function(site) {
try {
const report = AnalyticsData.Properties.runRealtimeReport(
{
metrics: [{ name: 'activeUsers' }]
},
'properties/' + site.id
);
let activeUsers = 0;
if (report.rows && report.rows.length > 0) {
activeUsers = parseInt(report.rows[0].metricValues[0].value);
}
if (activeUsers === 0) {
inactiveSites.push(site.name);
}
} catch (e) {
Logger.log("Error checking site " + site.name + ": " + e.message);
}
});
if (inactiveSites.length > 0) {
const siteListText = inactiveSites.join(", ");
MailApp.sendEmail({
to: recipientEmail,
subject: "Alert: No Traffic Detected on Your Blog!",
body: "Attention: No active users were detected on the following sites in the last 30 minutes:\n\n" + siteListText + "\n\nPlease check your sites immediately."
});
}
}
Authorize the Script 🔐
You must grant permissions before the script can access your analytics data and send emails.
- Click the Save icon (floppy disk) in the editor.
- Select checkMultipleSites from the dropdown menu at the top.
- Click Run.
- A pop‑up will appear: "Authorization Required." Click Review Permissions.
- Choose your Google account.
- Click Advanced > Go to (Untitled project) (unsafe).
- Click Allow.
Set Up the Trigger (Automation) ⏱️
Now, let the script run automatically every 30 minutes.
- On the left sidebar, click the Triggers (clock icon).
- Click Add Trigger (bottom right).
- Configure the settings as follows:
- Choose which function to run:
checkMultipleSites - Select event source:
Time-driven - Select type of time based trigger:
Minutes timer - Select minute interval:
Every 30 minutes
Click Save. Your traffic monitor is now live!
Conclusion & Final Tips 🎉
You’ve successfully automated your traffic monitoring! Now, whenever your blog traffic hits zero for two consecutive 30‑minute checks, you’ll know instantly. This simple setup saves you from constantly refreshing analytics and helps you react quickly to hosting issues, plugin problems, or unexpected drops.
Here’s a quick recap of what you’ve built:
- Connected Google Apps Script to your GA4 property
- Deployed a script that checks real‑time active users
- Configured automatic email alerts for zero traffic
- Set a time‑driven trigger for 30‑minute checks
Key Takeaways
📧 Ready to Automate Your Blog Monitoring?
Set up your own traffic alert system in the next 10 minutes. Copy the code, follow the steps, and enjoy peace of mind knowing you’ll be alerted the moment something goes wrong.



Join the tech debate...
We love a good discussion, but please keep it respectful and relevant to the topic. Vulgarity, personal attacks, and spam will be removed. Let’s keep the community smart, helpful, and welcoming to all tech fans!