How To Use the PageSpeed Insights API to Track Web page Efficiency

by | Mar 8, 2023 | Etcetera | 0 comments

There are tools to have the same opinion track web page efficiency and assess your improvements. Probably the most perfect is PageSpeed Insights. It’s available as a internet software and as the Lighthouse tab in Chrome’s DevTools (the equivalent DevTools are also available in Edge, Opera, Brave, and Vivaldi).

Web internet web page potency is further crucial than ever. Shoppers expect a slick and responsive experience that competition desktop systems. In addition to, Google’s Core Internet Vitals measure internet web page potency – it influences PageRank and your Seek Engine Optimization efforts.

WordPress runs more than a third of all web websites on the other hand efficiency is affected by the use of pointless web hosting, gradual problems, and an over-reliance on plugins. You’ll repair maximum issues by the use of switching to a just right internet host and using ideal follow efficiency tactics.

Having access to Lighthouse

Get began Lighthouse by the use of opening the internet web page you need to check up on and pressing Ctrl/Cmd + Shift + I or choosing Developer Equipment from Additional tools throughout the menu. Switch to the Lighthouse tab and click on at the Analyse Internet web page Load button. Results are confirmed after a few seconds:

Example Lighthouse report
Example Lighthouse report

You’ll drill down into the top-level percentages to seek out further wisdom and hints which handle recognized problems. The instrument is worth it on the other hand there are downsides:

  • You will have to manually get began a run for each internet web page you’re checking out.
  • It isn’t easy to record how components have complex or worsened through the years.
  • There could also be a lot of knowledge to check and it’s simple to get one thing improper.
  • The technical details are equipped for developers. It’s most likely overwhelming for consumers and executives who want a speedy overview of construction.
  • Lighthouse runs can also be influenced by the use of local tool and group speeds which may lead to false assumptions.

The PageSpeed Insights API provides a solution to get to the bottom of the ones issues so assessments can also be computerized, recorded, and in comparison.

What Is the PageSpeed Insights API?

Google provides a free PageSpeed Insights REST API which returns knowledge in JSON structure containing all the Lighthouse metrics and additional. It means that you can automate internet web page runs, store the following knowledge, analysis changes through the years, and display the fitting wisdom you need.

The PageSpeed Insights API emulates how Google sees your internet website online. That you must run a report each few days or each time you liberate a potency exchange.

The consequences are helpful on the other hand not necessarily indicative of actual shopper experience. The browser Efficiency API is a better option when you need to watch real-world potency right through all your shopper’s devices and networks.

WordPress web site now not on top of things? Deficient webhosting, issues, and plugins may well be the culprits! 😩 Optimize your web site with PageSpeed Insights and take your site to the following point! 🚀Click on to Tweet

PageSpeed Insights API Quickstart

Replica the following handle for your web browser and edit the url to guage the potency of your internet web page:

Firefox is highest because it has a built-in JSON viewer even though Chrome has extensions that provide the equivalent capacity. The whole Lighthouse Potency score is highlighted beneath:

PageSpeed Insights API result JSON (Firefox)
PageSpeed Insights API result JSON (Firefox)

You’ll change the API URL question string for your non-public pages and preferences. The only required parameter is url, e.g.


A desktop test is run by the use of default on the other hand you’ll be capable of explicitly request it with:

See also  13 Very best WordPress Footer Design Examples (+ Very best Practices)


or switch to mobile with:


Most straightforward potency assessments are run except for you specify quite a lot of categories of interest:

magnificence=web page positioning

A specific language can also be defined by the use of surroundings a locale – very similar to French:


and Google Analytics advertising and marketing marketing campaign details can also be set with:


The provider is free for infrequent requests on the other hand you will need to sign-up for a Google API key if you intend to run many assessments from the equivalent IP handle in a short lived period. The hot button is added to the URL with:


You’ll assemble the URL’s query string by the use of specifying your decided on parameters separated with ampersand (&) characters. The following API URL assessments the internet web page at using a mobile tool to guage potency and accessibility requirements:

You’ll compile your individual URLs or use the Google PageSpeed API URL builder software should you require further lend a hand.

PageSpeed Insights API JSON Results

Tests will normally return spherical 600Kb of JSON knowledge depending in your decided on categories, the collection of property throughout the internet web page, and the complexity of screenshots (embedded in base64 structure).

The quantity of data is daunting, there’s some duplication, and the effects documentation isn’t always clear. The JSON is split into 4 sections as described beneath.


The ones are metrics calculated for the end shopper’s internet web page loading experience. It accommodates wisdom such since the Core Web Vitals CUMULATIVE_LAYOUT_SHIFT_SCORE, FIRST_CONTENTFUL_PAINT_MS, and FIRST_INPUT_DELAY_MS. Details and a “magnificence” value returns FAST, AVERAGE, SLOW, or NONE if no measurement was taken. Example:

"loadingExperience": {
"metrics": {
"percentile": 0,
"distributions": [
"min": 0,
"max": 10,
"proportion": 0.970
"min": 10,
"max": 25,
"proportion": 0.017
"min": 25,
"proportion": 0.012
"magnificence": "FAST"


The ones are aggregated metrics calculated for all consumers’ internet web page loading experiences. The sections are very similar to loadingExperience above and internet sites with a lot much less guests aren’t going to show any difference in figures.


That’s the greatest phase and accommodates all Lighthouse metrics. It provides information about the test:

  • requestedUrl – the URL you requested
  • finalUrl – the actual internet web page tested after following all redirects
  • lighthouseVersion – the tool type
  • fetchTime – the time the test was run
  • userAgent – the patron agent string of the browser used for the test
  • atmosphere – extended shopper agent wisdom
  • configSettings – the settings passed to the API

This is followed by the use of an “audits” phase with many sections at the side of unused-javascript, unused-css-rules, total-byte-weight, redirects, dom-size, largest-contentful-paint-element, server-response-time, network-requests, cumulative-layout-shift, first-meaningful-paint, screenshot-thumbnails, and full-page-screenshot.

Most audit metrics provide a “details” phase which accommodates components very similar to “overallSavingsBytes” and “overallSavingsMs” which estimates the advantages of implementing a potency expansion.

The entire internet web page and thumbnail “screenshot” sections include embedded base64 image knowledge.

A  “metrics” phase provides a summary of all metrics in an “items” array, e.g.

"metrics": {
"identification": "metrics",
"determine": "Metrics",
"description": "Collects all available metrics.",
"score": null,
"scoreDisplayMode": "informative",
"details": {
"sort": "debugdata",
"items": [{
"observedFirstVisualChange": 234,
"observedFirstContentfulPaint": 284,
"interactive": 278,
"observedFirstPaintTs": 1579728174422,
"observedDomContentLoaded": 314,
// ... etc ...
"numericValue": 278,
"numericUnit": "millisecond"

The “audits” phase is followed by the use of “categories” which gives complete Lighthouse scores for the chosen categories passed on the API URL:

"categories": {
"potency": {
"identification": "potency",
"determine": "Potency",
"score": 0.97,
"auditRefs": [

The “ranking” is a bunch between 0 and 1 which is in most cases proven as a proportion on Lighthouse stories. Generally, a ranking of:

  • 0.9 to one.0 is just right
  • 0.5 to below 0.9 signifies growth is vital
  • below 0.5 is deficient and calls for extra pressing consideration
See also  Easy methods to Create a Shopper Portal in WordPress

The “auditRefs” segment supplies a listing of all metrics and the weightings used to calculate every ranking.


After all, the research time is reported. This must be similar to the time proven in lighthouseResult.fetchTime.

Helpful JSON Consequence Metrics

I like to recommend you save and read about the JSON lead to a textual content editor. Some have JSON formatters integrated or to be had as plugins. Then again, you’ll be able to use loose on-line gear similar to:

The next metrics usually are helpful. Consider to set the related class choices at the URL as vital.

Abstract Metrics

Total ratings from 0 to one:

Efficiency lighthouseResult.classes.efficiency.ranking
Accessibility lighthouseResult.classes.accessibility.ranking
search engine marketing positioning.ranking
Innovative Internet App (PWA) lighthouseResult.classes.pwa.ranking

Efficiency Metrics

Those come with Core Internet Vitals ratings from 0 to one:

First Contentful Paint lighthouseResult.audits.first-contentful-paint.ranking
First Significant Paint lighthouseResult.audits.first-meaningful-paint.ranking
Greatest Contentful Paint lighthouseResult.audits.largest-contentful-paint.ranking
Pace Index lighthouseResult.audits.speed-index.ranking
Cumulative Format Shift lighthouseResult.audits.cumulative-layout-shift.ranking

Different helpful efficiency ratings come with:

Server reaction time lighthouseResult.audits.server-response-time.ranking
Is crawlable
Console mistakes lighthouseResult.audits.errors-in-console.ranking
Overall byte weight
DOM length ranking lighthouseResult.audits.dom-size.ranking

You’ll most often download precise figures and gadgets similar to:

  • –
    the overall web page length, e.g. 450123
  • –
    the gadgets used for the overall web page length, e.g. “byte”

Then again, “displayValue” most often incorporates a readable message with each the determine and unit:

  • lighthouseResult.audits.server-response-time.displayValue –
    a message in regards to the reaction time, e.g. “Root report took 170 ms”
  • lighthouseResult.audits.dom-size.displayValue –
    a message about choice of parts within the DOM, e.g. “543 parts”

Create a No-Code Efficiency Dashboard

Are living API feeds will also be learn and processed in lots of programs together with Microsoft Excel. (Moderately bizarrely, Google Sheets does now not enhance JSON feeds with out additional plugins or macro code. It does enhance XML.)

To import the reside total efficiency ranking into Excel, get started a brand new spreadsheet, transfer to the Knowledge tab, and click on From Internet. Input your PageSpeed Insights API URL and hit OK:

Excel From Web data import
Excel From Internet information import

Click on Attach within the subsequent conversation and stay the default (Nameless) atmosphere. You are going to continue to the Question Settings software:

Excel Query Settings Tool
Excel Question Settings Software

Click on Document at the appropriate of the lighthouse consequence metric. Then click on the similar on classes and efficiency to drill down the JSON object hierarchy:

Excel JSON object drill-down
Excel JSON object drill-down

Click on the Into Desk icon on the peak from the right-click menu choices.

You’ll then click on the clear out arrow within the desk heading to take away the whole thing rather than the ranking prior to clicking OK:

Excel imported table filtering
Excel imported desk filtering

After all, click on Shut & Load to turn the reside efficiency ranking for your spreadsheet:

Excel live data
Excel reside information

You’ll practice the similar procedure for different metrics of passion.

Create a Internet Efficiency Dashboard

This Codepen demonstration supplies a kind the place you’ll be able to input a URL and make a selection desktop or cell research to procure effects.

The code creates a PageSpeed Insights URL, calls the API, then renders more than a few effects right into a abstract desk which is faster to view than a typical Lighthouse record:

Example test result from PageSpeed API
Instance check consequence

The asynchronous startCheck() serve as is known as when the shape is submitted. It cancels the put up match and hides earlier effects:

// make API request
async serve as startCheck(e) {
display(resultTable, false);
display(error, false);

It then constructs apiURL from the shape information and disables the fields:

shape = e.goal,
fields = shape.firstElementChild,
information = new FormData(shape),
qs = decodeURIComponent( new URLSearchParams(information).toString() ),
apiURL = shape.motion + '?' + qs;
fields.disabled = true;

The Fetch API is used to name the PageSpeed URL, get the reaction, and parse the JSON string right into a usable JavaScript object. A check out/catch block guarantees disasters are captured:

  check out {
// name API and get consequence
reaction = look forward to fetch(apiURL),
consequence = look forward to reaction.json();

The end result object is handed to a showResult() serve as. This extracts houses and puts them into the end result desk or every other HTML detail which has data-point characteristic set to a PageSpeed API belongings, e.g.

See also  Is Dropshipping Nonetheless a Legitimate eCommerce Industry Technique?

The tip of the check out block:

    // output consequence
display(standing, false);

After all, a catch block handles mistakes and the shape fields are re-enabled so additional exams will also be run:

  catch(err) {
// API error
display(standing, false);
fields.disabled = false;

Additional Building Choices

The instance code above fetches a consequence from the PageSpeed Insights API while you request it. The record is extra configurable than Lighthouse however execution stays a guide procedure.

For those who intend to increase your personal dashboard, it can be sensible to create a small software that calls the PageSpeed Insights API and retail outlets the ensuing JSON in a brand new database report towards the examined URL and the present date/time. Maximum databases have JSON enhance even if MongoDB is preferably fitted to the duty. A cron task can name your software on a timed foundation – in all probability as soon as in line with day right through the early hours of the morning.

A server-side software can then put in force its personal REST API in your reporting necessities, e.g. go back the adjustments in explicit efficiency metrics between two dates. It may be referred to as by means of client-side JavaScript to show tables or charts that illustrate efficiency enhancements over the years.

If you wish to create advanced stories with vital amounts of knowledge, it’s preferable to pre-calculate the figures as soon as in line with day on the level new PageSpeed information is to be had. In spite of everything, you don’t wish to display how efficiency is bettering on a record which takes mins to generate!

Wish to spice up your site’s ratings and consumer revel in? See your web site via Google’s eyes with PageSpeed Insights API! Discover ways to track and optimize your web page’s efficiency like a professional 👀Click on to Tweet


Chrome’s Lighthouse software is fabulous however it’s a chore to regularly assessment many pages. The PageSpeed Insights API permits you to assess web site efficiency the usage of programmatic tactics. The advantages:

The submit How To Use the PageSpeed Insights API to Track Web page Efficiency gave the impression first on Kinsta®.

WP Hosting

[ continue ]

WordPress Maintenance Plans | WordPress Hosting

read more


Submit a Comment

Your email address will not be published. Required fields are marked *