Skip to main content

📊 Semrush Integration

📖 Overview​

Semrush integration providing comprehensive SEO analytics including domain rankings, organic and paid keyword data, backlink analysis, competitor insights, and position tracking. Features intelligent caching with 7-day refresh cycles and subscription-based access control.

Provider: Semrush (https://www.semrush.com)
API Version: v1
Integration Type: API Key-based with automatic data caching

📚 Documentation Structure​

This integration is organized into the following sections:

✨ Features​

  • ✅ Domain Overview: Get domain authority, traffic estimates, and ranking metrics
  • ✅ Keyword Research: Analyze organic and paid keywords with search volumes
  • ✅ Competitor Analysis: Discover organic and paid competitors by domain
  • ✅ Backlink Metrics: Track backlinks, referring domains, and authority scores
  • ✅ Position Tracking: Monitor keyword rankings with historical data
  • ✅ Project Management: Save and manage Semrush projects per account
  • ✅ Intelligent Caching: 7-day data cache with force refresh option
  • ✅ Subscription Control: Plan-based keyword limits (Pro: 10, Plus: 20, Platinum: 40)
  • ✅ Country Database Support: Multi-country database selection
  • ✅ CSV Parsing: Automatic CSV-to-JSON conversion

🏗️ Architecture​

graph TD
A[Frontend Request] --> B{Cache Check}
B -->|Fresh Data < 7 days| C[Return Cached Data]
B -->|Stale Data > 7 days| D[Fetch from Semrush API]
B -->|Force Refresh ?new=true| D
D --> E[Parse CSV Response]
E --> F[Store in MongoDB]
F --> G[Return Fresh Data]

H[Subscription Validation] --> I{Has SEO Plan?}
I -->|Yes| J[Apply Keyword Limit]
I -->|No| K[Return 403 Error]

style A fill:#4CAF50
style D fill:#2196F3
style F fill:#FF9800
style H fill:#9C27B0

🗄️ MongoDB Collections​

📘 Detailed Schema: See Database Collections Documentation

semrush.auth​

Purpose: Store Semrush project configurations per account

Schema:

{
_id: ObjectId,
account_id: ObjectId, // DashClicks account reference
created_by: ObjectId, // User who created project
name: String, // Project name
domain: String, // Primary domain for project
project_id: String, // Semrush project ID
campaign_id: String, // Google campaign ID (for position tracking)
createdAt: Date,
updatedAt: Date
}

Indexes:

  • { account_id: 1, domain: 1 } (unique) - Primary lookup
  • { account_id: 1 } - Account-based queries

semrush.reports​

Purpose: Cache Semrush API responses with 7-day TTL

Schema:

{
_id: ObjectId,
uid: ObjectId, // User ID
account_id: ObjectId, // Account ID
domain: String, // Target domain
type: String, // Report type (see below)
data: Array/Object, // Parsed API response
createdAt: Date,
updatedAt: Date
}

Report Types:

  • domain_rank - Domain overview metrics
  • domain_organic - Organic keyword data
  • domain_organic_organic - Organic competitor data
  • domain_adwords_adwords - Paid competitor data
  • backlinks_overview - Backlink metrics
  • keyword_position_tracking_organic - Position tracking data
  • projects_list - Global projects list (domain: "global")

Indexes:

  • { account_id: 1, domain: 1, type: 1, createdAt: -1 } - Cache lookups

📂 Directory Structure​

Source Code Location:

external/Integrations/Semrush/
├── Controllers/
│ └── semrush.js # Request handlers with caching logic
├── Models/
│ └── semrush.js # Data access layer and cache queries
├── Providers/
│ └── semrush.js # Semrush API wrapper
├── Routes/
│ └── semrush.js # Route definitions
├── Validators/
│ └── index.js # Joi validation schemas
├── Utils/
│ └── countries.js # Country code mappings
└── index.js # Route registration

Shared Models Used:

  • shared/models/semrush-auth.js - Project configurations
  • shared/models/semrush.js - Cached report data
  • shared/models/store-subscription.js - Subscription validation

⚙️ Environment Variables​

# Required
SEMRUSH_API_KEY=your_api_key_here
SEMRUSH_API_URL=https://api.semrush.com/
SEMRUSH_DATABASE=us # Default country database

# Optional - For specific countries
# Supported: us, uk, ca, au, de, fr, es, it, nl, br, ru, in, etc.

🚀 Quick Start​

1. Save Project Configuration​

POST /v1/integrations/semrush/auth/project
Authorization: Bearer {jwt_token}
Content-Type: application/json

{
"projectName": "Client Website SEO",
"domain": "example.com",
"projectId": "12345678"
}

2. Get Domain Overview​

GET /v1/integrations/semrush/overview/example.com
Authorization: Bearer {jwt_token}

3. Analyze Organic Keywords​

GET /v1/integrations/semrush/keyword/organic/example.com?new=true
Authorization: Bearer {jwt_token}

4. Track Keyword Positions​

GET /v1/integrations/semrush/keyword/tracking/example.com?config_id=507f1f77bcf86cd799439011
Authorization: Bearer {jwt_token}

📡 API Endpoints Summary​

MethodEndpointDescription
Projects
POST/auth/projectSave project configuration
DELETE/authDelete project and cached data
GET/projectsList all Semrush projects
Domain Analytics
GET/overview/:domainDomain overview and rankings
Keywords
GET/keyword/organic/:domainOrganic keyword rankings
GET/keyword/tracking/:domainPosition tracking with history
Competitors
GET/competitor/organic/:domainOrganic competitors
GET/competitor/paid/:domainPaid competitors
Backlinks
GET/backlinks/overview/:domainBacklink metrics

🔒 Subscription Requirements​

SEO Subscription Plans​

Access requires an active SEO subscription with plan-based limits:

PlanKeyword Tracking LimitPrice Point
Pro10 keywordsEntry-level
Plus20 keywordsMid-tier
Platinum40 keywordsPremium
InternalUnlimitedDashClicks staff

Validation:

  • Subscription status: active, trialing, or past_due
  • Product type: seo
  • Returns 403 error if no valid subscription found

Note: Internal DashClicks users bypass all limits.

📊 Data Caching Strategy​

Cache Lifecycle​

  1. First Request: Fetches from Semrush API → Stores in MongoDB
  2. Subsequent Requests: Returns cached data if < 7 days old
  3. Stale Data: Auto-refreshes if > 7 days old
  4. Force Refresh: Use ?new=true to bypass cache

Cache Metadata​

Every response includes:

{
"data": [...],
"createdAt": "2025-10-03T10:00:00Z",
"lastUpdate": "2025-10-03T10:00:00Z",
"nextUpdate": "2025-10-10T10:00:00Z",
"daysSinceUpdate": 7,
"daysUntilUpdate": 0,
"isStale": true
}

🌍 Country Database Support​

Semrush supports multiple country-specific databases for localized SEO data:

Supported Countries (partial list):

  • us - United States (default)
  • uk - United Kingdom
  • ca - Canada
  • au - Australia
  • de - Germany
  • fr - France
  • es - Spain
  • it - Italy
  • nl - Netherlands
  • br - Brazil
  • ru - Russia
  • in - India
  • jp - Japan
  • cn - China
  • mx - Mexico

Country Detection: Automatically uses account's country from account.business.address.country

📈 Response Format​

Standard Response​

{
"success": true,
"message": "SUCCESS",
"data": {
"data": [
// Parsed CSV data as JSON array
],
"createdAt": "2025-10-10T08:00:00Z",
"lastUpdate": "2025-10-10T08:00:00Z",
"nextUpdate": "2025-10-17T08:00:00Z",
"daysSinceUpdate": 0,
"daysUntilUpdate": 7,
"isStale": false
}
}

Paginated Response (Projects/Keywords)​

{
"success": true,
"message": "SUCCESS",
"data": {
"data": [...],
"pagination": {
"currentPage": 1,
"totalPages": 3,
"totalItems": 75,
"itemsPerPage": 25,
"hasNextPage": true,
"hasPreviousPage": false
}
}
}

⚠️ Error Handling​

Semrush API Errors​

Error CodeMeaningHTTP Status
ERROR 50Invalid API key or subscription required500
ERROR 40Invalid request or resource not found400
ERROR 30Rate limit exceeded429

DashClicks Errors​

ErrorHTTP StatusDescription
SUBSCRIPTION_REQUIRED403No active SEO subscription found
PROJECT_NOT_FOUND404Project configuration missing
INVALID_DOMAIN400Domain format invalid
TIMEOUT_ERROR504Request timeout (600s limit)

🎯 Common Use Cases​

1. Client SEO Dashboard​

Track client website performance with:

  • Domain authority and rankings
  • Top organic keywords
  • Backlink profile
  • Competitor analysis

2. Keyword Position Tracking​

Monitor keyword rankings over time:

  • Historical position data
  • Ranking distribution (Top 1, 2-5, 6-10, 10+)
  • URL-level tracking
  • Trend analysis

3. Competitive Intelligence​

Analyze competitors:

  • Shared organic keywords
  • Paid advertising strategies
  • Traffic estimates
  • Keyword gaps

4. SEO Reporting​

Generate comprehensive SEO reports:

  • Weekly/monthly position tracking
  • Keyword performance trends
  • Backlink growth
  • Domain authority changes

📝 Important Notes​

  • 🕒 Cache Duration: 7 days (configurable via shouldForceRefresh)
  • 🔄 Force Refresh: Use ?new=true to bypass cache
  • 🌍 Country-Specific: Automatically selects database based on account country
  • 📊 CSV Format: API returns CSV; automatically parsed to JSON
  • 🔐 Subscription Required: Position tracking requires active SEO subscription
  • ⏱️ Timeout: 600 seconds (10 minutes) for API requests
  • 🚫 Rate Limiting: Semrush enforces API rate limits (varies by subscription)
  • 📈 Pagination: Projects and keyword tracking support pagination
  • 🔍 Search: Projects endpoint supports search by name, domain, or URL
  • 🎯 Plan Limits: Keyword tracking limited by subscription plan

🆕 Recent Enhancements​

  • ✅ Subscription Validation: Added SEO subscription requirement for position tracking
  • ✅ Plan-Based Limits: Keyword limits based on Pro/Plus/Platinum plans
  • ✅ MongoDB Aggregation: Efficient sorting and pagination for large datasets
  • ✅ Keyword Summary: Ranking distribution (rank 1, 2-5, 6-10, 10+)
  • ✅ Enhanced Error Handling: Detailed error context for debugging
  • ✅ Project Campaigns: Auto-fetch Google campaign ID for position tracking
  • ✅ Search Functionality: Search projects by multiple fields
  • ✅ Force Refresh Logic: Improved cache invalidation

Last Updated: October 10, 2025
Integration Status: Production Ready
API Version: Semrush v1

💬

Documentation Assistant

Ask me anything about the docs

Hi! I'm your documentation assistant. Ask me anything about the docs!

I can help you with:
- Code examples
- Configuration details
- Troubleshooting
- Best practices

Try asking: How do I configure the API?
09:31 AM