Designed2Use GA Views
·
Display Google Analytics 4 pageview counts on posts and pages. Recent posts fetch fast; older posts refresh in the background.
Designed2Use GA Views shows the Google Analytics 4 pageview total for a post or page using a simple shortcode. It is built so a visitor’s page load is never held up by the slow Google API.
How it fetches counts (hybrid model)
- A cached value is shown whenever one is fresh.
- On a cache miss for a recent post (published within your live-fetch window), the count is fetched live with a short, fail-fast timeout over a narrow date range (the post’s publish date to today) — fast because the query window is small.
- On a cache miss for an older post, a background job is queued and the last stored value is shown immediately. The slow, history-heavy query runs off the request path.
- Administrators can force a live refresh of the page they are viewing with
?d2ugav_refresh=1.
Features
[d2ugav_pageview]shortcode, or automatic display appended to post content / Echo Knowledge Base header.- Settings page for credentials, property ID, live-fetch window, cache duration, label, metric, event name, and post types.
- Optional per-post ”legacy baseline” to add historical (e.g. Universal Analytics) views to the live GA4 count.
- Lightweight: talks to the GA4 Data API directly over REST with a self-signed service-account token — no bundled multi-megabyte SDK.
Google Analytics is a third-party service governed by Google’s own terms; see https://policies.google.com/privacy and https://marketingplatform.google.com/about/analytics/terms/us/ .
