Overview
Integrate Google Analytics 4 (GA4) to enable traffic-based priority for cache warming and job filtering. Adapt uses GA4 page view data to identify your most-visited pages and warm their cache first. Key Features:- OAuth 2.0 authentication with Google accounts
- GA4 Data API integration for page view metrics
- Traffic-based task prioritisation (7, 28, and 180-day periods)
- Per-organisation property configuration
- Automatic token refresh
OAuth Flow
Initiating Connection
Start the OAuth flow by making a POST request to initiate the connection:auth_url to complete authorisation.
Required OAuth Scopes
Adapt requests the following scopes from Google:https://www.googleapis.com/auth/analytics.readonly- Read access to Analytics datahttps://www.googleapis.com/auth/userinfo.email- User email for account linking
Adapt uses offline access with consent prompt to obtain a refresh token, allowing long-term access to analytics data without repeated login.
OAuth Callback
After user authorisation, Google redirects back to:- Validates the state parameter (HMAC-signed)
- Exchanges the authorisation code for access and refresh tokens
- Fetches available GA4 accounts and properties
- Creates a temporary session for property selection
- Redirects to settings page for property configuration
Property Configuration
Listing Accounts and Properties
After OAuth, fetch available GA4 accounts:Saving Selected Property
Once you’ve selected a GA4 property, save it to your organisation:Analytics Data Integration
Page View Metrics
Once configured, Adapt automatically fetches page view data for your crawled pages across three time periods:- 7 days - Recent traffic patterns
- 28 days - Monthly traffic trends
- 180 days - Long-term page popularity
Task Prioritisation
When listing tasks, you can sort by analytics metrics:ga4_page_views_7d- Page views in last 7 daysga4_page_views_28d- Page views in last 28 daysga4_page_views_180d- Page views in last 180 days
Data Fetching
Adapt fetches GA4 data in batches:- Initial batch: 100 pages
- Medium batches: 1,000 pages
- Large batches: 50,000 pages (after 10,000 offset)
Managing Connections
List Connections
View all Google Analytics connections for your organisation:Delete Connection
Remove a Google Analytics connection:Security
Token Storage
All OAuth tokens are stored securely in Supabase Vault:- Refresh tokens - Encrypted in
vault.secretstable - Access tokens - Cached in memory, refreshed automatically
- Organisation isolation - Tokens scoped per organisation via RLS
Token Refresh
Access tokens expire after 1 hour. Adapt automatically refreshes them using the stored refresh token when making GA4 API requests. If refresh fails (e.g., user revoked access), the connection status is marked asrefresh_failed and you’ll need to re-authorise.
Troubleshooting
No Analytics Data Appearing
Property not configured
Property not configured
Ensure you’ve completed the property selection step after OAuth. Check
/v1/integrations/google to verify property_id is set.Property ID mismatch
Property ID mismatch
GA4 property IDs must match exactly between your GA4 admin settings and Adapt. Format:
properties/123456789Insufficient permissions
Insufficient permissions
Verify your Google account has at least Viewer role on the GA4 property.
OAuth Errors
State validation failed
State validation failed
The OAuth state parameter prevents CSRF attacks. If validation fails:
- Ensure cookies are enabled
- Don’t bookmark the OAuth callback URL
- Start the flow from
/v1/integrations/googleeach time
Token refresh failed
Token refresh failed
If automatic token refresh fails:
- Delete the connection
- Re-initiate OAuth flow
- Grant consent again for offline access
API Rate Limits
Google Analytics Data API has quota limits:- Core Requests: 40,000 per day per project
- Tokens per request: 4,000 per hour
Next Steps
- Understanding Results - View GA4 metrics in task results
- Best Practices - Optimise cache warming with traffic data
- API Reference - Sort tasks by page views