Skip to content

Instantly share code, notes, and snippets.

View arijitMondal's full-sized avatar

Arijit arijitMondal

View GitHub Profile
@arijitMondal
arijitMondal / Code.gs
Last active April 22, 2022 15:03
Google Apps Script code to fetch pagespeed data and save to google sheet
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"]];
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);
}
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName('results');
function monitor() {
var desktopInfo = getPageSpeedInfo('desktop');
var mobileInfo = getPageSpeedInfo('mobile');
instertDataToSheet(desktopInfo, 'desktop');
instertDataToSheet(mobileInfo, 'mobile');
}
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);
}
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,
const DuplicatePackageCheckerPlugin = require('duplicate-package-checker-webpack-plugin')
module.exports = {
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
config.plugins.push(new DuplicatePackageCheckerPlugin())
return config
},
}
handleScrollToTop() {
import('react-scroll').then(scroll => {
scroll.animateScroll.scrollToTop({
})
})
}
const DuplicatePackageCheckerPlugin = require('duplicate-package-checker-webpack-plugin')
module.exports = {
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
config.plugins.push(new DuplicatePackageCheckerPlugin())
config.resolve.alias['fast-deep-equal'] = path.resolve(
__dirname,
'node_modules',
'fast-deep-equal'
)
if (
typeof window !== 'undefined' &&
'IntersectionObserver' in window &&
'IntersectionObserverEntry' in window &&
'intersectionRatio' in window.IntersectionObserverEntry.prototype
) {
let observer = new IntersectionObserver()
//rest of the code
} else {
import('intersection-observer').then(() => {