Blueprint
System Data Flow
The GA4 Analytics Bridge
Data Engineering / Analytics
A Node.js service that pulls per-provider page metrics from the Google Analytics 4 Reporting API on a scheduled cadence and writes them directly into WordPress post meta via the REST API — powering a live provider dashboard without any manual data entry.
Logic Breakdown
A service account authenticates with GA4's Reporting API using OAuth2. `runReport()` is called with a dimension filter scoped to the specific provider's profile page path, returning `screenPageViews` for the last 7 days. The resulting metric value is then pushed to WordPress via `axios.post()` to the WP REST API, updating the `_weekly_views` post meta field. The Provider Dashboard reads this meta field to display live analytics.
Architecture Decisions
- 01Service account authenticates with GA4 Reporting API using OAuth2 credentials stored in env.
- 02`runReport()` queries page-level `screenPageViews` for the last 7 days, filtered by profile path.
- 03Dimension filter scopes the report to a specific provider's `/provider/{id}` page path.
- 04`axios.post()` writes the metric value to WordPress post meta via the authenticated REST API.
Code Snippet
javascript// Node.js: Syncing GA4 Metrics to WordPress REST API
async function syncProviderMetrics(profileId, ga4PropertyId) {
const [response] = await analyticsClient.runReport({
property: `properties/${ga4PropertyId}`,
dateRanges: [{ startDate: '7daysAgo', endDate: 'today' }],
dimensions: [{ name: 'pagePath' }],
metrics: [{ name: 'screenPageViews' }],
dimensionFilter: { fieldName: 'pagePath', stringFilter: { value: `/provider/${profileId}` } }
});
// Update WP Meta via REST
await axios.post(`${WP_URL}/wp-json/wp/v2/provider/${profileId}`, {
meta: { _weekly_views: response.rows[0].metricValues[0].value }
});
}Live Pipeline
GA4 → WordPressAPI Request
GA4 Reporting API v1
Auth Layer
OAuth2 · Service Account
ETL + Cache
node-cache · rate-limited
Provider UI
Live dashboard metric
Key Dependencies
Known Limitations
- GA4 API quota: 10 concurrent requests per property — batch provider updates with rate limiting.
- WordPress App Passwords must be transmitted over HTTPS to protect credentials in transit.
Technical Spec
- Language
- JavaScript (Node.js 18+)
- GA4 API
- Data API v1
- Transport
- Axios (REST)
- Target
- WordPress REST API v2
- Metric
- screenPageViews (7-day)
- Schedule
- Cron / Cloud Scheduler
- Auth
- Service Account + WP App Password
Tags
Live Sandbox
Interactive runtime environment — The GA4 Analytics Bridge v1.3.0
$ npm run sandbox
> Initialising The GA4 Analytics Bridge v1.3.0…
> Status: Production
// Live iframe mounted once sandboxUrl is configured.