Overview
Reportr connects to three Google services to collect comprehensive SEO data for your client reports:- Google Search Console - Organic search performance (clicks, keywords, positions)
- Google Analytics 4 - Website traffic and user behavior
- PageSpeed Insights - Performance scores and Core Web Vitals
All integrations use read-only API access. Reportr never modifies your Google data.
Authentication Architecture
Reportr uses OAuth 2.0 to securely access Google APIs without storing passwords.OAuth Flow
User Initiates Connection
Click “Connect Google Accounts” on a client card. This triggers the OAuth authorization flow.
Authorization Request
Reportr redirects to Google’s OAuth consent screen with:
- Client ID from environment variables
- Requested scopes (Search Console, Analytics)
- Redirect URI for callback
User Grants Access
Select Google account and approve permissions. Google returns an authorization code.
Token Exchange
Reportr exchanges the authorization code for:
- Access Token (short-lived, 1 hour)
- Refresh Token (long-lived, no expiration)
Token Refresh Mechanism
Access tokens expire after 1 hour. Reportr automatically refreshes them:Token Refresh (from config.ts)
Google Search Console
Required Permissions
OAuth Scope:https://www.googleapis.com/auth/webmasters.readonly
What this allows:
- Read Search Console performance data
- List verified sites and properties
- Access search analytics reports
- Modify site settings
- Add/remove users
- Change verification status
Available Data
Reportr fetches comprehensive Search Console metrics:- Overall Performance
- Top Keywords
- Top Pages
- Daily Time Series
- Keyword-Page Mapping
Aggregated metrics for the selected date range:
Property Types
Search Console supports two property types:URL-Prefix Property
Format:
https://example.com/- Specific protocol (http/https)
- Includes subdomain
- Requires trailing slash
https://www.example.com/Domain Property
Format:
sc-domain:example.com- All protocols (http, https)
- All subdomains
- All paths
sc-domain:example.comAPI Implementation
Search Console data fetching with retry logic:Search Console Client (from search-console.ts)
Rate Limits
Google Search Console API limits:1,200 requests per day per projectReportr uses 3-5 queries per report generation.
300 requests per minuteReportr implements automatic retry with exponential backoff if rate limits are hit.
2-3 day delayLatest available data is typically 2-3 days old. Reports should use date ranges ending at least 2 days ago.
Google Analytics 4
Required Permissions
OAuth Scopes:https://www.googleapis.com/auth/analytics.readonlyhttps://www.googleapis.com/auth/analytics.edit(for property listing only)
- Read GA4 report data
- List accessible properties
- Access admin metadata
- Modify property settings
- Change user permissions
- Delete data
Available Data
- Organic Traffic Metrics
- Top Landing Pages
- Traffic Trend
- Traffic Sources
GA4 Data API
Reportr uses the GA4 Data API (v1beta):Analytics Client (from analytics.ts)
Organic Search Filtering
Reportr filters GA4 data to only include organic search traffic:Dimension Filter
Rate Limits
250,000 requests per day per project
10 concurrent requestsReportr batches requests and uses queuing for high-volume operations.
24-48 hour delayGA4 data is typically 24-48 hours delayed. Use date ranges ending at least 1 day ago.
PageSpeed Insights
API Access
PageSpeed Insights uses a simple API key (no OAuth required):PageSpeed Client (from pagespeed.ts)
Core Web Vitals
PageSpeed Insights measures three key metrics:LCP
Largest Contentful PaintTime until main content loads
- Good: ≤ 2.5s
- Needs Work: 2.5s - 4.0s
- Poor: > 4.0s
FID
First Input DelayTime until page is interactive
- Good: ≤ 100ms
- Needs Work: 100ms - 300ms
- Poor: > 300ms
CLS
Cumulative Layout ShiftVisual stability score
- Good: ≤ 0.1
- Needs Work: 0.1 - 0.25
- Poor: > 0.25
Performance Opportunities
PageSpeed Insights provides actionable recommendations:Opportunity Extraction
Rate Limits
25,000 requests per day (default quota)Can be increased via Google Cloud Console.
20-60 seconds per URLPageSpeed runs Lighthouse analysis which takes time. Reportr shows progress indicators.
Error Handling
Reportr implements comprehensive error handling for Google APIs:Retry Strategy
Exponential Backoff (from error-handling.ts)
Error Types
401 Unauthorized
401 Unauthorized
403 Forbidden
403 Forbidden
Cause: User doesn’t have access to requested resourceReportr Action:
- Check if property still exists
- Verify user has proper permissions
- Suggest user check Google Console access
429 Rate Limit
429 Rate Limit
Cause: Too many requests to Google APIReportr Action:
- Automatic retry with exponential backoff
- Wait 1s → 2s → 4s → 8s between attempts
- Max 3 retries before failing
500/502/503 Server Error
500/502/503 Server Error
Cause: Google API temporary outageReportr Action:
- Automatic retry (these errors are transient)
- Exponential backoff between attempts
- Log error for monitoring
Error Handling Implementation
Google API Error Handler
Disconnecting Integrations
Users can disconnect Google accounts:Security Best Practices
Token Encryption
All OAuth tokens are encrypted in the database using AES-256 encryption before storage.
Minimal Scopes
Reportr requests only the minimum scopes needed:
- Read-only Search Console
- Read-only Analytics
- No admin or write permissions
Automatic Token Refresh
Access tokens are refreshed automatically when expired, preventing authentication failures.
Error Logging
All API errors are logged for debugging while sanitizing sensitive data (tokens redacted).
Testing Integrations
After connecting Google, test the integration:Test API Connectivity
Related Resources
Client Management
Set up clients and manage Google connections
Report Generation
Use Google data to generate reports
Google API Docs
Official Google API documentation