Download the PHP package revolution/laravel-google-searchconsole without Composer
On this page you can find all versions of the php package revolution/laravel-google-searchconsole. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download revolution/laravel-google-searchconsole
More information about revolution/laravel-google-searchconsole
Files in revolution/laravel-google-searchconsole
Package laravel-google-searchconsole
Short Description Google SearchConsole API for Laravel
License MIT
Informations about the package laravel-google-searchconsole
Google SearchConsole API for Laravel
https://developers.google.com/webmaster-tools
Overview
This Laravel package provides a comprehensive PHP wrapper for the Google Search Console API, enabling you to seamlessly integrate Search Console functionality into your Laravel applications. With this package, you can:
- Query Search Analytics Data: Retrieve search performance metrics including impressions, clicks, CTR, and average position
- Analyze Website Performance: Get detailed insights about your website's performance in Google Search results
- Filter by Dimensions: Query data by page, query, country, device, and more
- Manage Site Properties: List and manage your Search Console properties
- Flexible Authentication: Support for both OAuth 2.0 (user-based) and Service Account (server-to-server) authentication
- Laravel Integration: Built specifically for Laravel with facades, service providers, and Artisan commands
The package leverages the powerful revolution/laravel-google-sheets
dependency for Google API client management and authentication, providing automatic token refresh and robust error handling.
Perfect for: SEO tools, analytics dashboards, automated reporting, website monitoring, and any application that needs to access Google Search Console data programmatically.
Requirements
- PHP >= 8.2
- Laravel >= 11.0
Installation
Uninstall
Sample project
https://github.com/invokable/search-console-project
Configuration
Authentication Methods
This package supports two authentication methods for accessing the Google Search Console API:
- OAuth 2.0: Recommended for user-based access when you need to access data on behalf of individual Google users
- Service Account: Ideal for server-to-server applications with automated access to specific properties
- Note: API Key authentication is NOT supported by Google Search Console API
Prerequisites
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Enable the Google Search Console API
- Create credentials based on your chosen authentication method
OAuth 2.0 Setup (using Socialite)
For OAuth authentication, this package works seamlessly with Laravel Socialite's official Google driver.
1. Install Laravel Socialite
2. Create OAuth 2.0 Credentials
In Google Cloud Console:
- Go to "Credentials" → "Create Credentials" → "OAuth 2.0 Client IDs"
- Set application type to "Web application"
- Add your authorized redirect URIs (e.g.,
https://yourapp.com/auth/google/callback
)
3. Configure OAuth Settings
Add to config/services.php
:
Add to config/google.php
:
4. Environment Variables for OAuth
Service Account Setup
Service Accounts provide server-to-server authentication without user interaction. The Service Account email must be added as an owner or user in Search Console for each property you want to access.
1. Create Service Account Credentials
In Google Cloud Console:
- Go to "Credentials" → "Create Credentials" → "Service Account"
- Fill in the service account details
- Create and download the JSON key file
2. Configure Service Account
The package automatically uses Service Account authentication when configured through the laravel-google-sheets
dependency. Place your service account JSON file in your Laravel storage directory.
Even for service accounts, scopes must be set in config/google.php
:
3. Environment Variables for Service Account
Option 1: Using File Path
Option 2: Using JSON String
GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION
can be an array other than a file path, so you can set it as a JSON string in .env
and decode it to an array in config/google.php
.
This method is particularly well-suited for GitHub Actions deployment, as it allows the entire service account credentials to be stored as a single secret.
4. Add Service Account to Search Console
- Go to Google Search Console
- Select your property
- Go to Settings → Users and permissions
- Add your service account email as a user with "Full" permissions
Creating Custom Queries
All query classes extend Revolution\Google\SearchConsole\Query\AbstractQuery
, which is a subclass of Google\Service\Webmasters\SearchAnalyticsQueryRequest
. This provides access to all Google Search Console API query parameters.
Generate Query Classes
Use the Artisan command to create new query classes in app/Search
:
Query Structure
Each query class must implement the init()
method where you define your query parameters:
Available Query Parameters
You can use any of the following methods in your init()
method:
Date Range
Dimensions (group results by)
Filters
Additional Options
Example Query Classes
Top Pages Query
Mobile Search Queries
Country Performance Query
Basic Usage
Using OAuth 2.0 Authentication
When using OAuth, you'll need to obtain access tokens through the Socialite authentication flow, then use setAccessToken()
to authenticate your requests.
1. OAuth Authentication Flow (Controller Example)
2. Using OAuth with Model Integration
You can use the WithSearchConsole
trait to integrate Search Console functionality directly into your models:
Then use it in your application:
Using Service Account Authentication
With Service Account authentication, the package automatically handles authentication through the GoogleApiClient included in laravel-google-sheets
. No manual token management is required.
Service Account Usage Example
Using Service Account in Commands
Quick Reference
Available Facade Methods
Response Structure
The API returns objects with the following structure:
Laravel Helper Functions for Response Handling
The response objects work seamlessly with Laravel's helper functions, making data manipulation more convenient:
Using data_get()
for Safe Property Access
Using collect()
for Enhanced Data Processing
LICENSE
MIT
All versions of laravel-google-searchconsole with dependencies
illuminate/support Version ^11.0||^12.0
revolution/laravel-google-sheets Version ^7.0