jeffersongoncalves / laravel-google-search-console
A lightweight Google Search Console API client for Laravel — search analytics (queries/pages/countries), URL inspection, and sitemap management.
Package info
github.com/jeffersongoncalves/laravel-google-search-console
pkg:composer/jeffersongoncalves/laravel-google-search-console
Fund package maintenance!
Requires
- php: ^8.2
- illuminate/support: ^11.0|^12.0|^13.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.21
- orchestra/testbench: ^9.0|^10.0|^11.0
- pestphp/pest: ^3.0|^4.0
- pestphp/pest-plugin-laravel: ^3.0|^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Laravel Google Search Console
A lightweight Google Search Console API client for Laravel. It wraps search analytics queries, URL inspection, and sitemap management behind a small static client, threads your OAuth bearer token, and returns null/[]/false sentinels on ordinary HTTP failures instead of throwing.
Features
searchAnalyticsByQuery()— search analytics rows broken down by querysearchAnalyticsByPage()— search analytics rows broken down by pagesearchAnalyticsByCountry()— search analytics rows broken down by countryinspectUrl()— run the URL Inspection API against a given URLsitemaps()— list submitted sitemapssubmitSitemap()— submit a sitemapdeleteSitemap()— delete a submitted sitemap
Installation
composer require jeffersongoncalves/laravel-google-search-console
Optionally publish the config file:
php artisan vendor:publish --tag="google-search-console-config"
Configuration
Add to your .env:
GOOGLE_SEARCH_CONSOLE_ACCESS_TOKEN=ya29.xxxxxxxxxxxxxxxxxxxx GOOGLE_SEARCH_CONSOLE_SITE_URL=https://example.com/ GOOGLE_SEARCH_CONSOLE_TIMEOUT=8
GOOGLE_SEARCH_CONSOLE_ACCESS_TOKEN is the OAuth bearer token — see the authorizing guide. GOOGLE_SEARCH_CONSOLE_SITE_URL is the default verified site requests target when no site URL is passed explicitly — use the exact format shown in Search Console, e.g. https://example.com/ or sc-domain:example.com.
Config Options
// config/google-search-console.php return [ 'access_token' => env('GOOGLE_SEARCH_CONSOLE_ACCESS_TOKEN'), 'site_url' => env('GOOGLE_SEARCH_CONSOLE_SITE_URL'), 'timeout' => (int) env('GOOGLE_SEARCH_CONSOLE_TIMEOUT', 8), ];
Usage
use JeffersonGoncalves\GoogleSearchConsole\GoogleSearchConsoleClient; // Search analytics — site URL defaults to config('google-search-console.site_url'), // dates default to a 28-day window ending 3 days ago (Search Console's usual data lag) $byQuery = GoogleSearchConsoleClient::searchAnalyticsByQuery(); $byPage = GoogleSearchConsoleClient::searchAnalyticsByPage(startDate: '2026-01-01', endDate: '2026-01-31', limit: 50); $byCountry = GoogleSearchConsoleClient::searchAnalyticsByCountry(); // URL inspection $result = GoogleSearchConsoleClient::inspectUrl('https://example.com/page'); // Sitemaps $sitemaps = GoogleSearchConsoleClient::sitemaps(); GoogleSearchConsoleClient::submitSitemap('https://example.com/sitemap.xml'); GoogleSearchConsoleClient::deleteSitemap('https://example.com/sitemap.xml'); // Target a different site than the configured default $sitemaps = GoogleSearchConsoleClient::sitemaps(siteUrl: 'sc-domain:example.com');
Testing
composer test
Static Analysis
composer analyse
Code Formatting
composer format
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.
