smnandre/pagespeed-api

PageSpeed Insight PHP Api Client 🚀 分析网页性能指标,核心网页核心...

v0.9.4 2024-06-22 03:34 UTC

This package is auto-updated.

Last update: 2024-09-13 17:25:32 UTC


README

PHP Version CI Release License Codecov

这个PHP库提供了一种轻松利用Google的PageSpeed Insights API的方式。

分析您的网页性能指标,获取详细报告,轻松优化您的网站。 🚀

安装

composer require smnandre/pagespeed-api

用法

初始化API

use PageSpeed\Api\PageSpeedApi;

$pageSpeedApi = new PageSpeedApi();

// or with API key (optional)
$pageSpeedApi = new PageSpeedApi('YOUR_API_KEY');

运行分析

// Analyze a page
$analysis = $pageSpeedApi->analyse('https://example.com/');

// ...with a specific strategy (mobile or desktop)
$analysis = $pageSpeedApi->analyse('https://example.com/', 'mobile');

// ...with a specific locale (e.g., fr_FR)
$analysis = $pageSpeedApi->analyse('https://example.com/', locale: 'fr_FR');

// ...with a specific category (performance, accessibility, best-practices, seo)
$analysis = $pageSpeedApi->analyse('https://example.com/', categories: 'performance');

参数

审计分数

audit-scores.png

use PageSpeed\Api\PageSpeedApi;

$pageSpeedApi = new PageSpeedApi();
$analysis = $pageSpeedApi->analyse('https://www.example.com');

$scores = $analysis->getAuditScores();

// array (
//   'performance' => 100,
//   'accessibility' => 88,
//   'best-practices' => 100,
//   'seo' => 90,
// )

审计类别

分数评估

核心网页核心

core-web-vitals.png

加载指标

use PageSpeed\Api\PageSpeedApi;

$pageSpeedApi = new PageSpeedApi();
$analysis = $pageSpeedApi->analyse('https://www.example.com');

$metrics = $analysis->getLoadingMetrics();

// array (
//   'CUMULATIVE_LAYOUT_SHIFT_SCORE' => 'FAST',
//   'EXPERIMENTAL_TIME_TO_FIRST_BYTE' => 'AVERAGE',
//   'FIRST_CONTENTFUL_PAINT_MS' => 'FAST',
//   'FIRST_INPUT_DELAY_MS' => 'FAST',
//   'INTERACTION_TO_NEXT_PAINT' => 'FAST',
//   'LARGEST_CONTENTFUL_PAINT_MS' => 'FAST',
// )

主要指标

贡献

欢迎贡献!如果您想贡献,请复制仓库并提交一个pull request。

许可

本项目采用MIT许可证。有关更多信息,请参阅LICENSE文件。