This guide provides step-by-step instructions for setting up the data source integrations used by SEO Machine: Google Analytics 4 (GA4), Google Search Console, DataForSEO, and WordPress.
- Google Analytics 4 (GA4) Setup
- Google Search Console Setup
- DataForSEO Setup
- WordPress Setup
- Testing Your Integrations
- Troubleshooting
Google Analytics 4 provides traffic data, user behavior metrics, and page performance insights for your website.
- Admin access to your Google Analytics 4 property
- A Google Cloud project (will be created if you don't have one)
- Go to the Google Cloud Console
- Select or create a project for your SEO Machine integration
- Navigate to APIs & Services > Library
- Search for "Google Analytics Data API"
- Click on the API and click Enable
- In Google Cloud Console, go to APIs & Services > Credentials
- Click Create Credentials and select Service Account
- Fill in the service account details:
- Name:
seo-machine-ga4(or any descriptive name) - Description: "Service account for SEO Machine GA4 integration"
- Name:
- Click Create and Continue
- Skip the optional "Grant this service account access to project" step (click Continue)
- Skip the optional "Grant users access to this service account" step (click Done)
- Find your newly created service account in the Credentials page
- Click on the service account email
- Go to the Keys tab
- Click Add Key > Create new key
- Select JSON as the key type
- Click Create
- The JSON key file will automatically download to your computer
- Important: Keep this file secure! It provides access to your GA4 data
- Go to Google Analytics
- Select your GA4 property
- Click Admin (gear icon in bottom left)
- Under Property, click Property access management
- Click the + button in the top right and select Add users
- Enter the service account email (from Step 2, looks like
seo-machine-ga4@your-project.iam.gserviceaccount.com) - Select the role Viewer (read-only access)
- Uncheck "Notify new users by email"
- Click Add
- In Google Analytics, click Admin
- Under Property, click Property Settings
- Copy your Property ID (format:
123456789)
- Rename your downloaded JSON key file to
ga4-credentials.json - Move the file to:
credentials/ga4-credentials.json - Create a
.envfile in the root directory if it doesn't exist - Add the following line to your
.envfile:(Replace with your actual Property ID from Step 5)GA4_PROPERTY_ID=123456789
Google Search Console provides search query data, click-through rates, average positions, and impressions for your website in Google Search results.
- Verified ownership of your website in Google Search Console
- A Google Cloud project (same one used for GA4 is fine)
- Go to the Google Cloud Console
- Select the same project you used for GA4 (or create a new one)
- Navigate to APIs & Services > Library
- Search for "Google Search Console API"
- Click on the API and click Enable
Option A: Reuse Your GA4 Service Account (Recommended)
- You can use the same service account created for GA4
- Skip to Step 3 and use the same JSON key file
Option B: Create a New Service Account
- In Google Cloud Console, go to APIs & Services > Credentials
- Click Create Credentials and select Service Account
- Fill in the service account details:
- Name:
seo-machine-gsc(or any descriptive name) - Description: "Service account for SEO Machine GSC integration"
- Name:
- Click Create and Continue
- Skip the optional steps and click Done
- Create and download a JSON key (same process as GA4 Step 3)
- Go to Google Search Console
- Select your property (website)
- Click Settings in the left sidebar
- Click Users and permissions
- Click Add user
- Enter the service account email (e.g.,
seo-machine-ga4@your-project.iam.gserviceaccount.com) - Select permission level: Full (required for API access, but only provides read access)
- Click Add
Your site URL is the property name in Search Console, typically one of:
https://yoursite.com/(for URL prefix properties)sc-domain:yoursite.com(for domain properties)- Check in Search Console settings to confirm the exact format
Using the Same Service Account as GA4 (Your Current Setup):
Since you're using the same service account for both GA4 and GSC, the configuration is simple:
- Credentials file: Use the existing
credentials/ga4-credentials.json(no additional file needed) - Add to your
.envfile:GSC_SITE_URL=https://yoursite.com/ GSC_CREDENTIALS_PATH=credentials/ga4-credentials.json - The integration will automatically use the shared credentials file
If Using a Separate Service Account (Alternative):
- Rename the JSON key to
gsc-credentials.json - Move to:
credentials/gsc-credentials.json - Add to your
.envfile:GSC_SITE_URL=https://yoursite.com/ GSC_CREDENTIALS_PATH=credentials/gsc-credentials.json
DataForSEO provides keyword research data, search volume, competition metrics, and SERP analysis.
- A DataForSEO account
- API credits (free trial available, or paid plan)
- Go to DataForSEO
- Click Sign Up or Get Started
- Complete the registration process
- Verify your email address
- Log in to your DataForSEO account
- Go to the Dashboard
- Navigate to API Access or API Credentials
- You'll see your:
- Login (username/email)
- Password (API password, different from account password)
- Copy both values
Note: DataForSEO uses Basic Authentication with login/password, not API keys.
- In the DataForSEO dashboard, go to Billing or Add Credits
- Choose a payment option:
- Free Trial: Usually provides $1-5 in credits to test
- Pay As You Go: Add credits as needed
- Monthly Plan: Subscribe for discounted rates
- Complete the payment process
Add the following to your .env file:
DATAFORSEO_LOGIN=your_username_or_email
DATAFORSEO_PASSWORD=your_api_password
DataForSEO charges per API request. Common pricing:
- Keywords For Site: ~$0.10 per 1000 keywords
- Search Volume: ~$0.20 per 1000 keywords
- SERP Analysis: ~$0.005 per SERP
Tip: Start with the free trial to test the integration, then add credits based on your usage needs.
WordPress integration enables publishing articles and landing pages directly from SEO Machine via the REST API.
- A WordPress site with REST API enabled
- Admin access to install plugins
- Yoast SEO plugin installed (for SEO metadata)
- Copy
wordpress/seo-machine-yoast-rest.phpto your WordPress site'swp-content/mu-plugins/directory - This plugin exposes Yoast SEO fields via the REST API for programmatic publishing
- Log in to your WordPress admin
- Go to Users > Profile
- Scroll to Application Passwords
- Enter a name:
SEO Machine - Click Add New Application Password
- Copy the generated password (you won't see it again)
Add the following to your .env file:
WP_URL=https://yoursite.com
WP_USERNAME=your_admin_username
WP_APP_PASSWORD=xxxx xxxx xxxx xxxx xxxx xxxx
Add the snippet from wordpress/functions-snippet.php to your theme's functions.php for additional publishing features.
See wordpress/README.md for more details.
After setting up your data sources, test them to ensure they're working correctly.
Run the GA4 agent to fetch traffic data:
npm run agent:ga4-traffic-dataExpected output:
- List of top-performing pages with pageviews
- Traffic metrics for recent time periods
- No authentication errors
Run the GSC agent to fetch search data:
npm run agent:gsc-search-dataExpected output:
- List of top search queries
- Click and impression data
- Average position metrics
Run the keyword research agent:
npm run agent:keyword-research "your target keyword"Expected output:
- Keyword suggestions related to your query
- Search volume data
- Keyword difficulty scores
Error: "Permission denied"
- Verify the service account email is added to your GA4 property with Viewer permissions
- Double-check you're using the correct Property ID in
.env
Error: "API not enabled"
- Make sure you enabled the Google Analytics Data API in Google Cloud Console
- Wait a few minutes after enabling for changes to propagate
Error: "Invalid credentials"
- Verify the JSON key file is in the correct location
- Ensure the file hasn't been corrupted or modified
- Check that the service account hasn't been deleted
Error: "User does not have sufficient permissions"
- Verify the service account is added to Search Console with Full permissions
- Make sure you're using the correct site URL format in
.env
Error: "Site not found"
- Check the
GSC_SITE_URLformat matches exactly what's in Search Console - Try both formats:
https://yoursite.com/andsc-domain:yoursite.com
Error: "Authentication failed"
- Verify your login/password in
.envare correct - Make sure you're using the API password, not your account password
- Check for any extra spaces in the credentials
Error: "Insufficient credits"
- Check your account balance at app.dataforseo.com
- Add more credits or upgrade your plan
Error: "Rate limit exceeded"
- DataForSEO has rate limits; wait a few minutes before retrying
- Consider spreading out API calls over time
Environment Variables Not Loading
- Make sure your
.envfile is in the root directory - Verify there are no syntax errors in the
.envfile - Restart your application after modifying
.env
Credentials File Not Found
- Check the file path is correct:
credentials/ - Create the
credentials/directory if it doesn't exist:mkdir -p credentials/
- Verify file names match exactly (case-sensitive)
-
Never commit credentials to Git
- Add to
.gitignore:credentials/ .env
- Add to
-
Restrict file permissions:
chmod 600 credentials/*.json chmod 600 .env -
Rotate credentials regularly
- Regenerate service account keys every 90 days
- Update DataForSEO password periodically
-
Use principle of least privilege
- Only grant Viewer/Read access where possible
- Don't share credentials between projects unnecessarily
Store encrypted backups of your credentials in a secure location:
- Password manager (1Password, LastPass, etc.)
- Encrypted cloud storage
- Secure company vault
seomachine/
├── .env # Environment variables
├── credentials/
│ ├── ga4-credentials.json # GA4 service account key
│ └── gsc-credentials.json # GSC service account key (or reuse GA4)
├── config/
│ └── competitors.json # Competitor configuration
└── data-sources-setup.md # This file
# Google Analytics 4
GA4_PROPERTY_ID=123456789
# Google Search Console
GSC_SITE_URL=https://yoursite.com/
COMPANY_NAME=Your Company
# DataForSEO
DATAFORSEO_LOGIN=your_username
DATAFORSEO_PASSWORD=your_api_password
# WordPress (optional, for /publish-draft)
WP_URL=https://yoursite.com
WP_USERNAME=your_username
WP_APP_PASSWORD=your_application_password- Google Cloud Console
- Google Analytics
- Google Search Console
- DataForSEO Dashboard
- DataForSEO API Documentation
If you encounter issues not covered in this guide:
- Check the official documentation for each service
- Review error logs for specific error messages
- Verify all prerequisites are met
- Test each integration independently to isolate the issue
Last Updated: January 2025