Overview
The analytics integrations provide:- Google Analytics 4 (GA4): Traffic, engagement, and conversion metrics
- Google Search Console (GSC): Search performance and keyword rankings
- DataForSEO: Competitive SEO data and keyword research
/performance-review command and inform content strategy decisions.
Prerequisites
- Google account with access to GA4 and Search Console properties
- DataForSEO account (optional, for competitive analysis)
- Python 3.8+ installed
pippackage manager
Install Dependencies
Install Python packages
From the repository root, install all required dependencies:This installs:
google-analytics-data- GA4 API clientgoogle-auth-oauthlib- Google authenticationgoogle-api-python-client- Search Console APIrequests- HTTP client for DataForSEOpython-dotenv- Environment variable managementpandas- Data analysis and manipulation
Google Analytics 4 Setup
Create Service Account
Create Google Cloud project
- Go to Google Cloud Console
- Click Select a project → New Project
- Name it “SEO Machine” or similar
- Click Create
Enable Google Analytics Data API
- In your project, go to APIs & Services → Library
- Search for “Google Analytics Data API”
- Click the API, then click Enable
Create service account
- Go to APIs & Services → Credentials
- Click Create Credentials → Service Account
- Name:
seo-machine-analytics - Description: “Service account for SEO Machine data access”
- Click Create and Continue
- Skip role assignment (permissions set in GA4)
- Click Done
Generate credentials JSON
- Click on the service account you just created
- Go to the Keys tab
- Click Add Key → Create new key
- Select JSON format
- Click Create - the JSON file downloads automatically
- Save as
credentials/ga4-credentials.jsonin your repository
Add service account to GA4
- Open Google Analytics
- Go to Admin (gear icon, bottom left)
- In the Property column, click Property Access Management
- Click Add users (+) button
- Paste the service account email (found in the JSON file, looks like
[email protected]) - Select role: Viewer
- Uncheck “Notify new users by email”
- Click Add
Configure GA4 Settings
Add your GA4 configuration todata_sources/config/.env:
Find your GA4 Property ID in Analytics: Admin → Property Settings → Property ID
Google Search Console Setup
Enable Search Console API
In the same Google Cloud project:
- Go to APIs & Services → Library
- Search for “Google Search Console API”
- Click the API, then click Enable
Use existing service account
You can reuse the same service account created for GA4, or create a new one following the same process.If creating a new service account, save credentials as
data_sources/config/gsc_credentials.json.Add service account to Search Console
- Go to Google Search Console
- Select your property
- Click Settings (gear icon, left sidebar)
- Click Users and permissions
- Click Add user
- Paste service account email
- Select permission: Full (required for API access)
- Click Add
Configure GSC Settings
Add your Search Console configuration todata_sources/config/.env:
The
GSC_SITE_URL must exactly match your verified property in Search Console, including https:// or http:// and with or without www.DataForSEO Setup
DataForSEO provides competitive keyword data, SERP analysis, and ranking tracking.Create DataForSEO account
- Sign up at DataForSEO
- Verify your email address
- Add payment method (pay-per-request pricing)
Get API credentials
- Log in to DataForSEO dashboard
- Go to API Access section
- Copy your Login (email)
- Copy or generate your Password (API password, not account password)
DataForSEO Pricing Overview
| Request Type | Cost per Request | Use Case |
|---|---|---|
| SERP Check | $0.006 | Check top 10 results for a keyword |
| Ranking Check | $0.0005 | Check your position for a keyword |
| Keyword Data | $0.006 | Get search volume and difficulty |
| Competitor Analysis | $0.01-0.05 | Analyze competitor rankings |
- Enable 24-hour caching (see below)
- Batch requests for multiple keywords
- Focus on high-priority keywords only
- Set monthly budget alerts in DataForSEO dashboard
Cache Configuration
Caching reduces API costs and rate limit issues by storing responses locally.How caching works
How caching works
- First API request is made and response stored in
data_sources/cache/ - Subsequent requests for the same data return cached response
- Cache expires after TTL (time-to-live) period
- Expired cache automatically refreshes on next request
Cache management
Cache management
Clear all cache:Clear specific source:Check cache size:
When to clear cache
When to clear cache
- After making changes to tracked keywords
- When you need real-time data (performance review)
- If seeing stale or incorrect data
- After significant traffic events
Complete .env Configuration
Your finaldata_sources/config/.env file should look like:
Test API Connections
Verify each integration is working correctly:The
test_dataforseo.py script validates API credentials and returns sample data to confirm connectivity.Using Analytics Data
Performance Review Command
Run a comprehensive performance analysis:- Fetches data from GA4, GSC, and DataForSEO
- Identifies declining content
- Finds quick-win opportunities (keywords ranking 11-20)
- Prioritizes content updates
- Suggests new content topics
- Generates a detailed report in
reports/performance-review-YYYY-MM-DD.md
Python Module Usage
Fetch GA4 Data
Fetch Search Console Data
Fetch DataForSEO Data
Aggregate All Data Sources
Data-Driven Decisions
SEO Machine uses analytics data to:Identify Declining Content
- Articles losing traffic (GA4)
- Keywords dropping in rankings (GSC + DataForSEO)
- Increased bounce rates (GA4)
Find Quick Wins
- Keywords ranking 11-20 (GSC + DataForSEO)
- High impressions, low CTR (GSC)
- Competitor keyword gaps (DataForSEO)
Prioritize Updates
- High-traffic articles with outdated data
- Page 2 rankings for valuable keywords
- Content gaps in topic clusters
Suggest New Content
- Rising search queries (GSC)
- Competitor content gaps (DataForSEO)
- Related questions people ask (DataForSEO)
Rate Limits & Quotas
Google Analytics 4
- Free Tier: 25,000 requests/day per property
- Standard Properties: Unlimited (within quotas)
- Cost: Free
Google Search Console
- Rate Limit: Unlimited (reasonable use)
- Rows per Request: 1,000 maximum
- Cost: Free
DataForSEO
- Pricing: Pay-per-request (see pricing table above)
- No Rate Limits: Based on account balance
- Tip: Enable aggressive caching to minimize costs
Troubleshooting
Authentication failed (GA4/GSC)
Authentication failed (GA4/GSC)
Problem:
google.auth.exceptions.DefaultCredentialsErrorSolutions:- Verify credentials JSON file exists at specified path
- Check service account has access to GA4/GSC property
- Ensure APIs are enabled in Google Cloud Console
- Confirm service account email is correct
- Try regenerating credentials JSON
No data returned
No data returned
Problem: API returns empty resultsSolutions:
- Check date ranges (some properties have 24-48 hour data delay)
- Verify property IDs and site URLs are correct
- Ensure property has data for requested time period
- Confirm filters aren’t too restrictive
- Check that site has traffic in that date range
Rate limit exceeded (DataForSEO)
Rate limit exceeded (DataForSEO)
Problem:
429 Too Many Requests or insufficient balanceSolutions:- Enable caching to reduce API calls
- Increase cache TTL in
.envto 24-48 hours - Check DataForSEO account balance
- Reduce number of keywords tracked
- Batch requests instead of individual calls
Module not found error
Module not found error
Problem:
ModuleNotFoundError: No module named 'google'Solutions:- Install dependencies:
pip install -r data_sources/requirements.txt - Check Python path includes
data_sourcesdirectory - Verify using correct Python version (3.8+)
- Try:
python3 -m pip install -r data_sources/requirements.txt
Property ID not found
Property ID not found
Problem: GA4 returns “Property not found” errorSolutions:
- Verify
GA4_PROPERTY_IDis the numeric property ID, not measurement ID (starts with “G-”) - Check service account has Viewer access to property
- Confirm using correct Google account for property ownership
- Wait 24 hours after adding service account (propagation delay)
Security Best Practices
.envfiles are in.gitignore- Credential JSON files are in
.gitignore - Use service accounts, not user accounts
- Grant minimum required permissions (Viewer for GA4/GSC)
- Rotate credentials every 90 days
- Store credentials in secure password manager
- Use separate service accounts for production/development
Next Steps
WordPress Integration
Set up WordPress publishing with Yoast SEO metadata
Content Commands
Learn commands that use analytics data for content decisions