{"id":327920,"date":"2026-06-26T16:51:48","date_gmt":"2026-06-26T16:51:48","guid":{"rendered":"https:\/\/wordpress.org\/plugins\/designed2use-ga-views\/"},"modified":"2026-06-26T16:51:28","modified_gmt":"2026-06-26T16:51:28","slug":"designed2use-ga-views","status":"publish","type":"plugin","link":"https:\/\/wordpress.org\/plugins\/designed2use-ga-views\/","author":23516420,"comment_status":"closed","ping_status":"closed","template":"","meta":{"version":"2.0.0","stable_tag":"2.0.0","tested":"7.0","requires":"6.0","requires_php":"7.4","requires_plugins":null,"header_name":"Designed2Use GA Views","header_author":"Designed2Use","header_description":"Display Google Analytics 4 pageview counts on posts and pages via a shortcode. Recent posts fetch fast on render; older posts refresh in the background, so page loads never wait on the slow Google API.","assets_banners_color":"abb0bc","last_updated":"2026-06-26 16:51:28","external_support_url":"","external_repository_url":"","donate_link":"","header_plugin_uri":"https:\/\/www.designed2use.co.uk\/wordpress-plugins-built-properly\/ga-views\/","header_author_uri":"https:\/\/www.designed2use.co.uk","rating":0,"author_block_rating":0,"active_installs":0,"downloads":43,"num_ratings":0,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","faq","changelog"],"tags":{"2.0.0":{"tag":"2.0.0","author":"designed2use","date":"2026-06-26 16:51:28"}},"upgrade_notice":{"2.0.0":"<p>First public release. Configure your service account and property ID under Settings \u2192 GA Views after activating.<\/p>"},"ratings":[],"assets_icons":{"icon-128x128.png":{"filename":"icon-128x128.png","revision":3587469,"resolution":"128x128","location":"assets","locale":"","width":128,"height":128},"icon-256x256.png":{"filename":"icon-256x256.png","revision":3587469,"resolution":"256x256","location":"assets","locale":"","width":256,"height":256}},"assets_banners":{"banner-1544x500.png":{"filename":"banner-1544x500.png","revision":3587469,"resolution":"1544x500","location":"assets","locale":"","width":1544,"height":500},"banner-772x250.png":{"filename":"banner-772x250.png","revision":3587469,"resolution":"772x250","location":"assets","locale":"","width":772,"height":250}},"assets_blueprints":{},"all_blocks":[],"tagged_versions":["2.0.0"],"block_files":[],"assets_screenshots":{"screenshot-1.png":{"filename":"screenshot-1.png","revision":3587469,"resolution":"1","location":"assets","locale":"","width":1781,"height":1318},"screenshot-2.png":{"filename":"screenshot-2.png","revision":3587469,"resolution":"2","location":"assets","locale":"","width":1447,"height":1021}},"screenshots":{"1":"The settings page under Settings \u2192 GA Views.","2":"A pageview count rendered on a post."}},"plugin_section":[],"plugin_tags":[232,193472,1005,7175,872],"plugin_category":[36],"plugin_contributors":[269038,269039],"plugin_business_model":[],"class_list":["post-327920","plugin","type-plugin","status-publish","hentry","plugin_tags-analytics","plugin_tags-ga4","plugin_tags-google-analytics","plugin_tags-pageviews","plugin_tags-views","plugin_category-analytics","plugin_contributors-designed2use","plugin_contributors-guy1ncognito","plugin_committers-designed2use"],"banners":{"banner":"https:\/\/ps.w.org\/designed2use-ga-views\/assets\/banner-772x250.png?rev=3587469","banner_2x":"https:\/\/ps.w.org\/designed2use-ga-views\/assets\/banner-1544x500.png?rev=3587469","banner_rtl":false,"banner_2x_rtl":false},"icons":{"svg":false,"icon":"https:\/\/ps.w.org\/designed2use-ga-views\/assets\/icon-128x128.png?rev=3587469","icon_2x":"https:\/\/ps.w.org\/designed2use-ga-views\/assets\/icon-256x256.png?rev=3587469","generated":false},"screenshots":[{"src":"https:\/\/ps.w.org\/designed2use-ga-views\/assets\/screenshot-1.png?rev=3587469","caption":"The settings page under Settings \u2192 GA Views."},{"src":"https:\/\/ps.w.org\/designed2use-ga-views\/assets\/screenshot-2.png?rev=3587469","caption":"A pageview count rendered on a post."}],"raw_content":"<!--section=description-->\n<p>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.<\/p>\n\n<p><strong>How it fetches counts (hybrid model)<\/strong><\/p>\n\n<ul>\n<li>A cached value is shown whenever one is fresh.<\/li>\n<li>On a cache miss for a <strong>recent<\/strong> 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) \u2014 fast because the query window is small.<\/li>\n<li>On a cache miss for an <strong>older<\/strong> post, a background job is queued and the last stored value is shown immediately. The slow, history-heavy query runs off the request path.<\/li>\n<li>Administrators can force a live refresh of the page they are viewing with <code>?d2ugav_refresh=1<\/code>.<\/li>\n<\/ul>\n\n<p><strong>Features<\/strong><\/p>\n\n<ul>\n<li><code>[d2ugav_pageview]<\/code> shortcode, or automatic display appended to post content \/ Echo Knowledge Base header.<\/li>\n<li>Settings page for credentials, property ID, live-fetch window, cache duration, label, metric, event name, and post types.<\/li>\n<li>Optional per-post \"legacy baseline\" to add historical (e.g. Universal Analytics) views to the live GA4 count.<\/li>\n<li>Lightweight: talks to the GA4 Data API directly over REST with a self-signed service-account token \u2014 no bundled multi-megabyte SDK.<\/li>\n<\/ul>\n\n<p>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\/ .<\/p>\n\n<!--section=installation-->\n<ol>\n<li>Upload the <code>designed2use-ga-views<\/code> folder to <code>\/wp-content\/plugins\/<\/code>, or install through the Plugins screen.<\/li>\n<li>Activate the plugin.<\/li>\n<li>In Google Cloud, create or select a project and enable the <strong>Google Analytics Data API<\/strong> for it (APIs &amp; Services \u2192 Library \u2192 search \"Google Analytics Data API\" \u2192 Enable).<\/li>\n<li>Create a service account, add a JSON key, and download it.<\/li>\n<li>In Google Analytics, open Admin \u2192 Property access management and grant the service account's email the <strong>Viewer<\/strong> role on your GA4 property.<\/li>\n<li>Go to <strong>Settings \u2192 GA Views<\/strong>, paste the service-account JSON, enter your numeric GA4 Property ID, choose your options, and save.<\/li>\n<li>Add <code>[d2ugav_pageview]<\/code> to a post\/template, or set <strong>Automatic display<\/strong> to append it to post content.<\/li>\n<li>Optionally click <strong>Refresh counts now<\/strong> to queue a batch of posts for an immediate background refresh.<\/li>\n<\/ol>\n\n<p><strong>Advanced: keeping the key out of the database<\/strong><\/p>\n\n<p>Instead of pasting the JSON into the settings field, define one of these in <code>wp-config.php<\/code>:<\/p>\n\n<pre><code>define( 'D2UGAV_CREDENTIALS_JSON', '{ ...service account json... }' );\ndefine( 'D2UGAV_CREDENTIALS_PATH', '\/absolute\/path\/outside\/webroot\/key.json' );\n<\/code><\/pre>\n\n<p><strong>Diagnosing unexpected counts<\/strong><\/p>\n\n<p>If a count is not what you expect, open <strong>Settings \u2192 GA Views Diagnostics<\/strong>, pick a post, and click <strong>Run live test<\/strong>. It runs a live GA4 report and shows the exact URL it matched, the request, the HTTP status, the rows returned, the computed count, and the raw GA4 response \u2014 so you can see immediately whether the issue is a URL mismatch, an event-name mismatch, a date range, or credentials.<\/p>\n\n<p>For a logged trace of every request (including front-end renders and background refreshes), enable <strong>Debug logging<\/strong> on the settings page. The trace is written to your PHP error log and never includes credentials or access tokens; turn it off again when finished. The same logging can be forced on site-wide with <code>define( 'D2UGAV_DEBUG', true );<\/code> in <code>wp-config.php<\/code>.<\/p>\n\n<!--section=faq-->\n<dl>\n<dt id=\"where%20is%20my%20service-account%20key%20stored%3F\"><h3>Where is my service-account key stored?<\/h3><\/dt>\n<dd><p>If you paste it into the settings page, it is stored in the <code>wp_options<\/code> table of your database. The key is never displayed again after saving. For higher security, define <code>D2UGAV_CREDENTIALS_JSON<\/code> or <code>D2UGAV_CREDENTIALS_PATH<\/code> in <code>wp-config.php<\/code> instead \u2014 then nothing is stored in the database.<\/p><\/dd>\n<dt id=\"does%20this%20slow%20down%20my%20site%3F\"><h3>Does this slow down my site?<\/h3><\/dt>\n<dd><p>Recent posts make one fast, narrow GA call on the first view after the cache expires (then it is cached). Older posts never call Google on render \u2014 they refresh in the background. You can also set the live-fetch window to 0 to push <em>every<\/em> post to the background.<\/p><\/dd>\n<dt id=\"why%20don%27t%20counts%20appear%20immediately%3F\"><h3>Why don't counts appear immediately?<\/h3><\/dt>\n<dd><p>New posts and old posts are refreshed by a background job a few seconds after they are queued. Recent posts populate on their first front-end view. Use <strong>Refresh counts now<\/strong> to queue a batch right away.<\/p><\/dd>\n<dt id=\"my%20counts%20look%20low%20%2F%20high.\"><h3>My counts look low \/ high.<\/h3><\/dt>\n<dd><p>Check that the GA4 Property ID is correct, the selected metric\/event matches how your site tracks views, and (for very old content) that the fallback lookback window is long enough. Pages are matched by URL using the GA4 <code>fullPageUrl<\/code> dimension.<\/p><\/dd>\n\n<\/dl>\n\n<!--section=changelog-->\n<h4>2.0.0<\/h4>\n\n<ul>\n<li>Complete rewrite for WordPress.org distribution.<\/li>\n<li>Removed the bundled Google SDK; the GA4 Data API is now called directly over REST.<\/li>\n<li>Hybrid fetch model: recent posts fetched live with a narrow publish-date window and fail-fast timeout; older posts refreshed in the background via WP-Cron. Page loads never block on the slow API.<\/li>\n<li>Added a full settings page (credentials, property ID, live-fetch window, cache duration, label, metric, event, post types, display mode).<\/li>\n<li>Added nonce protection to the editor meta box and escaped all output.<\/li>\n<li>Added a Diagnostics screen (Settings \u2192 GA Views Diagnostics) and an optional debug-logging setting to troubleshoot unexpected counts.<\/li>\n<li>Clamp the GA4 query start date to the API's minimum so posts published before GA4 existed no longer fail.<\/li>\n<li>Prefixed all functions\/classes\/meta and added internationalization.<\/li>\n<\/ul>","raw_excerpt":"Display Google Analytics 4 pageview counts on posts and pages. Recent posts fetch fast; older posts refresh in the background.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/327920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=327920"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/designed2use"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=327920"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=327920"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=327920"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=327920"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=327920"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=327920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}