Monitoring Speed with the PageSpeed Insights API
Page load speed directly impacts conversion rates and SEO. Manually tracking it is not an engineer’s job: running Lighthouse after every deployment wastes time. Without automation, you risk missing degradation that hurts your rankings. We offer automated Core Web Vitals monitoring (CWV automation) using the PageSpeed Insights API, per the official documentation at developers.google.com. This free service returns two data types: lab (Lighthouse) and field (Chrome UX Report). Lab data reacts instantly; field data accumulates over 28 days. Together they give the full picture.
How Monitoring Works
PSI API is free: up to 25,000 requests per day with a key. The key is created in Google Cloud Console. We prepare a Python script that collects metrics for priority pages (homepage, categories, product cards, cart) and stores them in PostgreSQL. The script runs on a schedule (e.g., every 24 hours via cron) and processes up to a hundred URLs per run.
import requests from typing import Literal PSI_API_URL = 'https://www.googleapis.com/pagespeedonline/v5/runPagespeed' def fetch_psi(url, api_key, strategy): params = { 'url': url, 'key': api_key, 'strategy': strategy, 'category': ['performance'], } resp = requests.get(PSI_API_URL, params=params, timeout=60) resp.raise_for_status() return resp.json() def extract_metrics(response): field = response.get('loadingExperience', {}) lab = response.get('lighthouseResult', {}) # extract field and lab metrics return {'field': field, 'lab': lab} Which Metrics We Track
| Metric | Lab | Field (CrUX) |
|---|---|---|
| LCP | largest-contentful-paint | LARGEST_CONTENTFUL_PAINT_MS |
| INP | interaction-to-next-paint | INTERACTION_TO_NEXT_PAINT |
| CLS | cumulative-layout-shift | CUMULATIVE_LAYOUT_SHIFT_SCORE |
| FCP | first-contentful-paint | FIRST_CONTENTFUL_PAINT_MS |
| TTFB | server-response-time | EXPERIMENTAL_TIME_TO_FIRST_BYTE |
We also record the Lighthouse Performance score. For each URL we keep a history — you can compare today’s measurement with yesterday’s and detect trends.
How to Set Up Alerts for Core Web Vitals Degradation
Define thresholds. For example, if LCP exceeds 4 seconds or Performance score drops below 70 — send a notification via Telegram or email. Thresholds are customized per project: stricter for e-commerce, softer for blogs.
THRESHOLDS = { 'lab_performance_score': 0.7, 'lab_lcp_ms': 4000, 'field_lcp_category': 'SLOW', } def check_alerts(current, thresholds): alerts = [] if current['lab']['performance_score'] < thresholds['lab_performance_score']: alerts.append(f"Performance score dropped to {current['lab']['performance_score']*100}%") # other checks return alerts We compare against the previous measurement: if a metric worsened by more than 10%, we also alert. This catches degradation even within the "green" zone. For typical PSI variance (5–15%), we use the median of three runs.
PSI API vs Local Lighthouse Comparison
| Parameter | PSI API | Local Lighthouse |
|---|---|---|
| Cost | Free (up to 25,000 requests/day) | Free, but requires a server |
| Run time | ~30–60 seconds per URL | Depends on hardware |
| Data | Lab + field (CrUX) | Only lab |
| Limitations | No authentication, 5–15% variance | Full control, but no field data |
PSI API is 10x cheaper than commercial services (e.g., SpeedCurve at $100/month) and provides field metrics unavailable to local Lighthouse. Switching to PSI can save up to $2,000 per year.
Step-by-Step Integration Process
- Obtain API key from Google Cloud Console.
- Define list of pages to monitor.
- Run the Python ingestion script on a cron job (daily).
- Set up PostgreSQL database to store historical data.
- Configure alert rules (Telegram, email, Slack).
- (Optional) Create Grafana dashboard for visualization.
- (Optional) Integrate with CI/CD pipeline (e.g., GitHub Actions).
What Is Included in the Work
- Obtaining and configuring the API key
- Metric collection script for N pages (you define the list)
- Database for storing history (PostgreSQL)
- Degradation alerts (Telegram, email, Slack — your choice)
- Grafana dashboard for trend visualization
- CI/CD integration: automatic run before every deployment
- Documentation and training for your team
- Access to all dashboards and configuration
Why Both Data Types Matter
Lab data reacts instantly — you see the effect of every code change. Field data lags by 28 days but shows real-world experience. Only together they give complete information. For example, you improved LCP on a test environment, but in the field it's still poor — the issue lies elsewhere (slow server, heavy JavaScript).
PSI API Limitations
The API runs Lighthouse on Google’s servers; results vary by 5–15%. We run three measurements and take the median. For authenticated pages (e.g., personal account), we use local Lighthouse via Node.js. Field data requires sufficient traffic — at least a few hundred visits per month per page.
Timeline, Cost, and Offer
Basic integration (collection + alerts) takes 1–2 business days. Extended version with Grafana and CI/CD takes 3–4 days. We offer a turnkey solution: from API key setup to Grafana dashboard, alerts, and documentation. Pricing is individual — contact us for a preliminary estimate. Typical savings: up to $2,000/year by replacing commercial services.
Experience and Guarantees
With 5+ years of expertise and 50+ completed projects in web performance optimization and monitoring, we guarantee stable script operation, 24/7 alerting, and fast feedback. Our solutions are battle-tested for e-commerce, media, and SaaS.
Technical integration details
For each URL, a separate record is created in the metrics table with fields: url, timestamp, lab_performance_score, field_lcp_category, etc. Indexes on url and timestamp speed up queries. Alerts are implemented via a simple polling script that checks fresh data every minute. For CI/CD, we use GitHub Actions: before deployment, a threshold test runs — if metrics are worse than the baseline, the pipeline fails.
Order monitoring setup, and we will prepare a solution for your stack.







