| Package Data | |
|---|---|
| Maintainer Username: | schulzefelix | 
| Maintainer Contact: | github@schulze.co (Felix Schulze) | 
| Package Create Date: | 2017-07-19 | 
| Package Last Update: | 2023-10-05 | 
| Language: | PHP | 
| License: | MIT | 
| Last Refreshed: | 2025-11-04 03:00:42 | 
| Package Statistics | |
|---|---|
| Total Downloads: | 37,272 | 
| Monthly Downloads: | 196 | 
| Daily Downloads: | 7 | 
| Total Stars: | 50 | 
| Total Watchers: | 5 | 
| Total Forks: | 26 | 
| Total Open Issues: | 2 | 
Using this package you can easily retrieve data from Google Search Console API.
This package can be installed through Composer.
$ composer require schulzefelix/laravel-search-console
In Laravel 5.5 or higher the package will autoregister the service provider. In Laravel 5.4 you must install this service provider.
// config/app.php
'providers' => [
    ...
    SchulzeFelix\SearchConsole\SearchConsoleServiceProvider::class,
    ...
];
In Laravel 5.5 or higher the package will autoregister the facade. In Laravel 5.4 you must install the facade manually.
// config/app.php
'aliases' => [
    ...
    'SearchConsole' => SchulzeFelix\SearchConsole\SearchConsoleFacade::class,
    ...
];
Optionally, you can publish the config file of this package with this command:
php artisan vendor:publish --provider="SchulzeFelix\SearchConsole\SearchConsoleServiceProvider"
The following config file will be published in config/search-console.php
return [
    /*
    |--------------------------------------------------------------------------
    | Authentication
    |--------------------------------------------------------------------------
    | Google offers access via OAuth client IDs or service accounts.
    | For more information see: https://developers.google.com/identity/protocols/OAuth2
    |
    | Supported: "oauth", "oauth_json", "service_account",
    */
 
    'auth_type' => env('GOOGLE_AUTH_TYPE', 'oauth'),
 
    /*
    |--------------------------------------------------------------------------
    | Application Credentials
    |--------------------------------------------------------------------------
    |
    | https://developers.google.com/api-client-library/php/auth/service-accounts#creatinganaccount
    */
 
    'connections' => [
 
        'oauth' => [
            'client_id' => env('GOOGLE_CLIENT_ID'),
            'client_secret' => env('GOOGLE_CLIENT_SECRET'),
        ],
 
        'oauth_json' => [
            'auth_config' => env('GOOGLE_AUTH_CONFIG'),
        ],
 
        'service_account' => [
            'application_credentials' => env('GOOGLE_APPLICATION_CREDENTIALS'),
        ],
 
    ],
 
    /*
     |--------------------------------------------------------------------------
     | Cache Settings
     |--------------------------------------------------------------------------
     | Here you may configure the "store" that the underlying Google_Client will
     | use to store it's data.  You may also add extra parameters that will
     | be passed on setCacheConfig (see docs for google-api-php-client).
     |
     | Optional parameters: "lifetime", "prefix"
     */
 
    'cache' => [
        'store' => file,
    ],
 
    /*
    |--------------------------------------------------------------------------
    | Application Name
    |--------------------------------------------------------------------------
    */
 
    'application_name' => env('SEARCH_CONSOLE_APPLICATION_NAME', 'GSC Agent'),
];
Here are two basic example to retrieve all sites and an export for search analytics data.
$sites = SearchConsole::setAccessToken($token)->listSites();
    $data = SearchConsole::setAccessToken($token)->setQuotaUser('uniqueQuotaUserString')
        ->searchAnalyticsQuery(
            'https://www.example.com/',
            Period::create(Carbon::now()->subDays(30), Carbon::now()->subDays(2)),
            ['query', 'page', 'country', 'device', 'date'],
            [['dimension' => 'query', 'operator' => 'notContains', 'expression' => 'cheesecake']],
            1000,
            'web'
        );
public function public function getSite(string $siteUrl): array
public function public function listSites(): Collection
public function searchAnalyticsQuery(string $siteUrl, Period $period, array $dimensions = [], array $filters = [], int $rows = 1000, string $searchType = 'web'): Collection
public function public function isAccessTokenExpired(): Bool
$sites = SearchConsole::setAccessToken($token)->listSites();
To avoid to the API limits, you can provide a unique string for the authenticated account.
More information: https://developers.google.com/webmaster-tools/search-console-api-original/v3/limits
$sites = SearchConsole::setAccessToken($token)->setQuotaUser('uniqueQuotaUserString')->listSites();
You can get access to the underlying Google_Service_Webmasters object:
SearchConsole::getWebmastersService();
Please see CHANGELOG for more information what has changed recently.
$ vendor/bin/phpunit
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email githubissues@schulze.co instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.