This PHP library offers an effortless way to leverage Google's PageSpeed Insights API.
Analyze your web pages for performance metrics, get detailed reports, and optimize your site with ease. 🚀
composer require smnandre/pagespeed-api
use PageSpeed\Api\PageSpeedApi;
$analysis = (new PageSpeedApi())->analyse('https://www.example.com');
// or with API key (optional)
$analysis = (new PageSpeedApi('YOUR_API_KEY'))->analyse('https://www.example.com');
use PageSpeed\Api\PageSpeedApi
$analysis = (new PageSpeedApi())->analyse('https://www.example.com');
$scores = $analysis->getAuditScores();
// array (
// 'performance' => 100,
// 'accessibility' => 88,
// 'best-practices' => 100,
// 'seo' => 90,
// )
use PageSpeed\Api\PageSpeedApi
$analysis = (new 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',
// )
// Mobile strategy (default)
$analysis = $api->analyse('https://example.com/', 'mobile');
// Desktop strategy
$analysis = $api->analyse('https://example.com/', 'desktop');
$analysis = $api->analyse('https://example.com/', 'mobile', 'fr');
# | Category | Description |
---|---|---|
⚡ | Performance | Measures how quickly the content on your page loads and becomes interactive. |
🌍 | Accessibility | Evaluates how accessible your page is to users, including those with disabilities. |
🏆 | Best Practices | Assesses your page against established web development best practices. |
⚓ | SEO | Analyzes your page's search engine optimization, ensuring it follows SEO guidelines. |
📱 | PWA | Checks if your page meets the criteria for a Progressive Web App, providing a native-like experience. |
# | Abbr | Metric | Description |
---|---|---|---|
🖼️ | FCP | First Contentful Paint | Time taken for the first piece of content to appear on the screen. |
⏱️ | TTI | Time to Interactive | Time taken for the page to become fully interactive. |
📏 | SI | Speed Index | How quickly the contents of a page are visibly populated. |
📊 | CLS | Cumulative Layout Shift | Measure of visual stability; the sum of all individual layout shift scores. |
⏳ | LCP | Largest Contentful Paint | Time taken for the largest content element to appear. |
⛔ | TBT | Total Blocking Time | Total time that the main thread was blocked, preventing user interaction. |
Contributions are welcome! If you would like to contribute, please fork the repository and submit a pull request. For major changes, please open an issue to discuss what you would like to change.
This project is licensed under the MIT License. See the LICENSE file for more information.