jeffersongoncalves / laravel-semrush
A lightweight Semrush Analytics API client for Laravel — domain analytics, keyword research, and backlinks.
Package info
github.com/jeffersongoncalves/laravel-semrush
pkg:composer/jeffersongoncalves/laravel-semrush
Fund package maintenance!
Requires
- php: ^8.2
- illuminate/support: ^11.0|^12.0|^13.0
- spatie/laravel-package-tools: ^1.16
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 Semrush
A lightweight Semrush Analytics API client for Laravel. It wraps the domain, keyword and backlink reports behind a small Semrush client/facade, threads your API key, and decodes the ;-separated CSV export into plain associative rows — no DTOs, no response wrappers.
Features
- Domain overview —
domainOverview() - Domain organic keywords —
domainOrganic() - Domain organic competitors —
domainCompetitors() - Keyword overview —
keywordOverview() - Related keywords —
relatedKeywords() - Keyword difficulty —
keywordDifficulty() - Backlinks overview —
backlinksOverview() - Backlinks list —
backlinks() - Semicolon-separated CSV decoded into
array<int, array<string, string>>, keyed by the report's own columns - Semrush reports errors with HTTP 200 and an
ERROR ...body — those raiseSemrushException - A non-2xx response raises
Illuminate\Http\Client\RequestException - Optional
database/limitparams are omitted from the query when leftnull
Installation
composer require jeffersongoncalves/laravel-semrush
Optionally publish the config file:
php artisan vendor:publish --tag="semrush-config"
Configuration
Add to your .env:
SEMRUSH_API_KEY=your-semrush-api-key SEMRUSH_DATABASE=us
Grab a key at semrush.com/api-analytics.
Config Options
// config/semrush.php return [ 'key' => env('SEMRUSH_API_KEY'), 'database' => env('SEMRUSH_DATABASE', 'us'), 'base_url' => env('SEMRUSH_BASE_URL', 'https://api.semrush.com'), ];
When semrush.key is null the client falls back to config('services.semrush.key').
Usage
Via the facade:
use JeffersonGoncalves\Semrush\Facades\Semrush; Semrush::domainOverview('example.com'); Semrush::domainOrganic('example.com', database: 'br', limit: 50); Semrush::domainCompetitors('example.com', limit: 20); Semrush::keywordOverview('laravel', database: 'us'); Semrush::relatedKeywords('laravel', database: 'us', limit: 25); Semrush::keywordDifficulty('laravel'); Semrush::backlinksOverview('example.com'); Semrush::backlinks('example.com', targetType: 'domain', limit: 100);
Or inject/resolve the underlying client:
use JeffersonGoncalves\Semrush\Semrush; $semrush = app(Semrush::class); $semrush->domainOverview('example.com');
Return shape
Every method returns a list of rows keyed by the report's export_columns:
Semrush::keywordOverview('laravel'); // [ // ['Ph' => 'laravel', 'Nq' => '12100', 'Cp' => '1.35', 'Co' => '0.07', 'Nr' => '154000000'], // ]
Values are always strings — cast them yourself where you need numbers.
Any other report
Every Semrush report type is reachable through get(), which appends the key, escapes the export and decodes the CSV for you:
Semrush::get([ 'type' => 'phrase_this', 'phrase' => 'laravel', 'database' => 'us', 'export_columns' => 'Ph,Nq,Cp', ]);
Databases
us (default), br, uk, de, fr, es, … — the full list is in the Semrush docs. Set the default with SEMRUSH_DATABASE or pass database: per call.
Error handling
use Illuminate\Http\Client\RequestException; use JeffersonGoncalves\Semrush\Exceptions\SemrushException; try { $rows = Semrush::keywordOverview('laravel'); } catch (SemrushException $e) { // "ERROR 50 :: NOTHING FOUND", "ERROR 120 :: WRONG KEY", ... } catch (RequestException $e) { // $e->response->status(), $e->response->body(), ... }
Testing
composer test
Static Analysis
composer analyse
Code Formatting
composer format
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
