Check Website Details Using Google Apps Scripts

Would you like to receive instant alerts as soon as your website goes down or is inaccessible to users? Would you like to receive these downtime alerts as an email message or text on your mobile phone or both?

Most of the services like Jetpack and Optimonster are Premium and not everyone can Purchase it. That’s why i created this script that works on Google Sheets and can fetch your website Details and Update.

Website UPTIME MONITOR WITH GOOGLE

From now on you can create your own website monitor that runs on Google servers and sends email alerts or SMS when your website goes down or is up again. Isnt it good yeah i knwo. It logs everything in a Google Spreadsheet or you can even store the downtime activity inside Google Analytics.

HOW TO SETUP WEBSITE MONITOR

It is very simple to use a Website Monitor. I’m sharing few steps that can lead you to the Script.

  1. Click here and make a copy of the website monitoring Google sheet into your Google Drive. You may either use your Gmail or Google Apps account to sign-in.
  2. Now see Website Monitor menu (near Help) and choose Configure. You may have to authorize the sheet the first time you configure the monitor the app is not verified because your not a G Suite member so click here to see how to approve it,
  3. Specify your website URL and the email address where you wish to be notified. If you want to see the status of multiple websites then, You can simply  put multiple addresses separated by commas.
  4. [Optional] Enter the Google Analytics Id (e.g., UA-123456-78) and the site monitor will log downtime / uptime events in  your Analytics account.
  5. You can turn on “Get text messages” to receive download alerts by SMS* on the mobile phone connected to your Google account. (Premium Feature free for 1st year)

Click the Start button and the Google sheet will start monitoring your website in the background. You can close the sheet and App will fetch details every hour. you can see them by opening the sheet when ever you want.

website checker google adds

 

How to Accept Unverified Google App Script

Some times we are not GSuite member and Google says that You are Installing UnVerified App Script. To Install that Unverfieied app or If you created your own app using Gmail so Click Here to See that how to accept unverified App.

You can Watch Video Tutorial to See how you can use it.

/**   Monitor your Site's Uptime by Sarmad Gardezi **/

function isMySiteDown()
{

// Get the URL of the Website to monitor
  var url = SpreadsheetApp.getActiveSheet().getRange("E3").getValue();
  
// HTTP Response Code of the last server request
  if (!ScriptProperties.getProperty("status")) {
    ScriptProperties.setProperty("status", 200);
  }
  
  var response, error; 

  try {    

// Fetch the web page using UrlFetchApp
    response = UrlFetchApp.fetch(url);

  } catch(error) 
  {   
    insertData(error, -1, "Website down");
    return;
  }
  
  var code = response.getResponseCode();
  
// code = 200 means the fetch request was successful
  if (code == 200) 
    insertData("Up", code, "Website up"); 
  else
    insertData(response.getContent()[0], code, "Website down");
}

function insertData(error, code, msg) {  

// Ignore if the error message is logged already
  if (ScriptProperties.getProperty("status") == code)
    return;
    
// Log the server error in a Google Sheet

  var sheet = SpreadsheetApp.getActiveSheet();
  var email = sheet.getRange("E5").getValue();
  var row   = sheet.getLastRow() + 1;
  
  sheet.getRange(row,1).setValue(new Date());
  sheet.getRange(row,2).setValue(error);
  sheet.getRange(row,3).setValue(code);

// Send an email alert for the downtime  

  ScriptProperties.setProperty("status", code);
  MailApp.sendEmail(email, msg, error);
}

Written By:

Sarmad Gardezi A blog scientist by Mind and a Passionate Blogger by heart. Sarmad is Freelancer, Entrepreneur and Google Apps Scripts Developer from Islamabad, Pakistan.

Subscribe to Email Newsletter