Show real Google Analytics 4 pageview counts on your posts — without slowing your site down
Designed2Use GA Views displays the GA4 pageview total for any post or page with a simple shortcode. The point of difference is *how* it fetches those numbers: a visitor’s page load is never held up waiting on Google’s slow Analytics API.
Built properly: a hybrid fetch model
Most “view counter” plugins either call the Analytics API on every page load (slow, and it counts against your API quota) or store everything and drift out of date. This one does neither:
- Fresh value cached? It’s served instantly.
- Recent post, cache expired? The count is fetched live with a short, fail-fast timeout over a narrow date window (the post’s publish date to today) — fast, because the query is small.
- Older post, cache expired? The last known value is shown immediately and a background WP-Cron job refreshes it off the request path. The heavy, history-spanning query never runs while a visitor waits.
The result: accurate GA4 numbers, with page-load performance that doesn’t depend on Google responding quickly.
Features
- Simple shortcode — drop `
1 Views
` into a post, page, or template. - Or automatic display — append the count to post content, or article header, with no shortcode required.
- Full settings page — service-account credentials, GA4 Property ID, live-fetch window, cache duration, display label, metric, event name, and which post types are tracked.
- Legacy baseline — optionally add historical (e.g. Universal Analytics) views to the live GA4 count on a per-post basis, so totals stay continuous.
- Lightweight & self-contained — talks to the GA4 Data API directly over REST using a self-signed service-account token. No bundled multi-megabyte SDK.
Privacy & security
- The only external service contacted is Google’s GA4 Data API, using your own service-account credentials. No telemetry, no phone-home.
- All output is escaped; all writes are nonce- and capability-protected.
- For higher security you can keep your key out of the database entirely by defining `D2UGAV_CREDENTIALS_JSON` or `D2UGAV_CREDENTIALS_PATH` in `wp-config.php`.
Google Analytics is a third-party service governed by Google’s Privacy Policy and the Google Analytics Terms of Service.
Requirements
- WordPress 6.0 or later
- PHP 7.4 or later
- A Google Cloud service account with Viewer access to your GA4 property
Getting started
1. Install and activate the plugin (search “Designed2Use GA Views” in Plugins → Add New, or download from WordPress.org).
2. In Google Cloud, create a service account, grant it Viewer access to your GA4 property, and download its JSON key.
3. Go to Settings → GA Views, paste the JSON, enter your numeric GA4 Property ID, and save.
4. Add `
1 Views
` where you want the count, or switch on automatic display.1 Views