Search by

jeffersongoncalves / laravel-google-search-console

jeffersongoncalves

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!

jeffersongoncalves

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-09-07 14:53 UTC

This package is auto-updated.

Last update: 2026-09-07 14:53:47 UTC


README

Laravel Google Search Console

Laravel Google Search Console

Tests PHPStan Code Style Latest Version on Packagist Total Downloads License

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 query
  • searchAnalyticsByPage() — search analytics rows broken down by page
  • searchAnalyticsByCountry() — search analytics rows broken down by country
  • inspectUrl() — run the URL Inspection API against a given URL
  • sitemaps() — list submitted sitemaps
  • submitSitemap() — submit a sitemap
  • deleteSitemap() — 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.