Google PageSpeed Insights API for website speed monitoring

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1221
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1163
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    855
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1056
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    828
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    825

Google PageSpeed Insights API for Speed Monitoring

PageSpeed Insights returns two data types: lab (Lighthouse, simulated) and field (Chrome UX Report, real users). Both important but differently. Lab shows current state right after deploy. Field shows real user experience over last 28 days. Monitoring needed for both.

Getting API Key and Basic Request

PSI API is free. Key created in Google Cloud Console → APIs & Services → Credentials. Without key limit is 400 requests/day, with key — 25,000.

import requests
from typing import Literal

PSI_API_URL = 'https://www.googleapis.com/pagespeedonline/v5/runPagespeed'

def fetch_psi(
    url: str,
    api_key: str,
    strategy: Literal['mobile', 'desktop'] = 'mobile',
) -> dict:
    params = {
        'url': url,
        'key': api_key,
        'strategy': strategy,
        'category': ['performance', 'seo', 'accessibility', 'best-practices'],
    }
    resp = requests.get(PSI_API_URL, params=params, timeout=60)
    resp.raise_for_status()
    return resp.json()

Extracting Core Web Vitals

PSI response is multi-level. Field data (CrUX) in loadingExperience, lab in lighthouseResult.audits.

Saving Results

Create PostgreSQL table for storing lab and field metrics over time:

CREATE TABLE psi_results (
    id SERIAL PRIMARY KEY,
    url TEXT NOT NULL,
    strategy VARCHAR(10) NOT NULL,
    measured_at TIMESTAMP DEFAULT NOW(),
    field_lcp_ms INTEGER,
    lab_performance_score NUMERIC(4,2),
    lab_lcp_ms INTEGER
);

Monitoring List of Pages

For site with several priority pages (homepage, top 10 landings, checkout) run on schedule.

Alerts on Degradation

Track Lighthouse score drop and CWV transition from "good" to "needs improvement".

Important Limitations

PSI API runs Lighthouse in Google cloud, not yours. Results vary 5–15% between runs — this is normal. For reliable metrics better run 3 measurements and take median. PSI doesn't support authorized pages — for personal cabinet, cart after login use local Lighthouse via Node.js.

Running via Cron

# Crontab: daily at 6:00
0 6 * * * /usr/bin/python3 /opt/monitoring/psi_monitor.py

Results aggregated weekly — daily lab noise is high, weekly trend much informative.

Timeline

Collection script + PostgreSQL storage + email/Telegram alerts — 1–2 working days. With Grafana dashboard, pre/post deploy comparison, CI/CD pipeline integration — 3–4 days.