This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function instertDataToSheet(deviceInfo, deviceType){ | |
| sheet.appendRow([ | |
| // GMT+8:00 is for singapore | |
| Utilities.formatDate(new Date(), "GMT+8:00", "yyyy-MM-dd'T'HH:mm:ss"), | |
| deviceType, | |
| deviceInfo.lighthouseResult.categories.performance.score * 100, | |
| deviceInfo.lighthouseResult.audits['first-contentful-paint'].numericValue, | |
| deviceInfo.lighthouseResult.audits['largest-contentful-paint'].numericValue, | |
| deviceInfo.lighthouseResult.audits['cumulative-layout-shift'].numericValue, | |
| deviceInfo.lighthouseResult.audits['interactive'].numericValue, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getPageSpeedInfo(strategy) { | |
| var pageSpeedUrl = 'https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=' + urlToMonitor + '&key=' + pageSpeedApiKey + '&strategy=' + strategy; | |
| var response = UrlFetchApp.fetch(pageSpeedUrl); | |
| var json = response.getContentText(); | |
| return JSON.parse(json); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function monitor() { | |
| var desktopInfo = getPageSpeedInfo('desktop'); | |
| var mobileInfo = getPageSpeedInfo('mobile'); | |
| instertDataToSheet(desktopInfo, 'desktop'); | |
| instertDataToSheet(mobileInfo, 'mobile'); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); | |
| var sheet = spreadsheet.getSheetByName('results'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function createHeaders() { | |
| //Freezes the first row | |
| sheet.setFrozenRows(1); | |
| // Set the values we want for headers | |
| var values = [["Timestamp", "Device","Performance Score","LAB FCP", "LAB LCP", "LAB CLS", "LAB Interactive", "LAB Total Blocking Time", "LAB Speed Index"]]; | |
| // Set the range of cells | |
| var range = sheet.getRange(1, 1, 1, 9); | |
| //Call the setValues method on range and pass in our values | |
| range.setValues(values); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var pageSpeedApiKey = 'PAGESPEED_API_KEY'; // use your api key here | |
| var urlToMonitor = 'YOUR_WEBSITE'; //replace with website you want to monitor | |
| var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); | |
| var sheet = spreadsheet.getSheetByName('results'); | |
| function createHeaders() { | |
| //Freezes the first row | |
| sheet.setFrozenRows(1); | |
| // Set the values we want for headers | |
| var values = [["Timestamp", "Device","Performance Score","LAB FCP", "LAB LCP", "LAB CLS", "LAB Interactive", "LAB Total Blocking Time", "LAB Speed Index"]]; |
NewerOlder