Facebook
From Gökhan ERCAN, 3 Years ago, written in JavaScript.
This paste is a reply to Apps Script PSI Source Code from Gökhan ERCAN - view diff
Embed
Download Paste or View Raw
Hits: 185
  1. var pageSpeedApiKey = "psi api key";
  2.  
  3. function psimobile(URL) {
  4.     var mobile = callPageSpeed(URL, 'desktop');
  5.     return mobile.lighthouseResult.categories.performance.score * 100
  6. };
  7.  
  8. function psidesktop(URL) {
  9.     var desktop = callPageSpeed(URL, 'desktop');
  10.     return desktop.lighthouseResult.categories.performance.score * 100
  11. };
  12.  
  13. function callPageSpeed(URL, strategy) {
  14.     var pageSpeedUrl = 'https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=' + URL + '&key=' + pageSpeedApiKey + '&strategy=' + strategy;
  15.     var response = UrlFetchApp.fetch(pageSpeedUrl);
  16.     var json = response.getContentText();
  17.     return JSON.parse(json);
  18. };

Replies to Re: Apps Script PSI Source Code rss

Title Name Language When
Re: Re: Apps Script PSI Source Code Scanty Motmot javascript 3 Years ago.