Description
Display popular posts using the page views your site already collects with Google Analytics 4 (GA4).
EMIANO Analytics Ranking is a free WordPress plugin that uses existing GA4 data. You can build your first ranking from historical data after the first successful retrieval, without waiting for new page views to accumulate.
The plugin adds no tracking script and makes no per-view database writes for ranking. It retrieves aggregated page views in the background and saves the latest ranking results for each period in WordPress, including post IDs, view totals, and the retrieval time. Individual visit histories are not stored, and displaying a ranking uses the saved results without calling Google.
Features
- Choose up to five periods from seven options: 12 hours, 1 day, 3 days, 1 week, 1 month, 3 months, and 6 months. The start of each period is calculated in the GA4 property’s time zone and rounded down to the hour.
- The scheduled retrieval intervals are 1 hour for the 12-hour and 1-day rankings, 6 hours for the 3-day and 1-week rankings, and 1 day for longer rankings. Actual timing depends on WP-Cron.
- Use the Analytics Ranking block or the
[emiano_ranking]shortcode to display up to ten published posts for a selected period and public post type. You can filter by one category and its child categories. WordPress pages are excluded. - Set site-wide options for featured images, rank numbers, publication dates, and the ranking’s last update time. Posts without a featured image show an empty frame of the same size.
- Customize the optional heading text, HTML tag (H1 to H6, p, or div), CSS classes, and message shown when there is no ranking data. The plugin adds a CSS class to the heading for the selected period. Rankings inherit your theme’s fonts and colors.
- Views from different URLs that resolve to the same post are combined, including old slugs recorded by WordPress. Both pretty and Plain permalinks (
/?p=123) are supported. - Check the last successful retrieval, result, error type, and next scheduled retrieval for each period in the settings. When you change the property ID or key, you can choose to retrieve the data again right away.
Requirements
Set up GA4 on your WordPress site and have your numeric property ID and Google Cloud service account JSON key ready. Enable the Google Analytics Data API and Google Analytics Admin API, and grant the service account the Viewer role on the GA4 property for read-only access.
Shortcode
[emiano_ranking period="1w" post_type="post"]
period: one of the periods selected on the settings screen (12h,1d,3d,1w,1m,3m,6m). If omitted, the shortest selected period is used.post_type: one public post type. Default:post.category: one category slug, including posts in child categories. If omitted, all categories are included.
Category rankings are selected from the overall ranking, so categories with few posts may show fewer than ten posts.
If a period that is not selected on the settings screen is specified, the shortcode shows the same output as when there is no data.
If a category slug does not exist, the shortcode shows the same output as when there is no data.
For developers
emiano_ar_get_ranking( $args ): accepts the same arguments as the shortcode (period,post_type,category) and returns an array of post IDs in ranking order, up to ten posts.emiano_ar_ranking_post_ids: filter receiving the array of candidate post IDs and the arguments. Applied before filtering by post type and category. Use it to exclude or reorder posts.emiano_ar_ranking_html: filter receiving the HTML, the array of displayed post IDs, and the arguments. Applied to shortcode and block output, but not to the text shown when there is no data.
About GA4 data
Google lists a typical processing time of 2 to 6 hours for intraday data in standard GA4 properties. Processing can take 24 to 48 hours, and reported totals can change during that time. Rankings reflect the data available at the last successful scheduled or manual retrieval.
External services
This plugin connects to the following Google services to retrieve your GA4 data. Requests are made only after you save a property ID and a service account key. They are sent from your server, not from your visitors’ browsers. No information about your visitors is sent.
Google OAuth 2.0 token service
Used to obtain a short-lived access token for the service account.
Endpoint: https://oauth2.googleapis.com/token
Data sent: a JSON Web Token signed on your server with the service account private key. It contains the service account email address, the read-only Analytics scope, the token endpoint as the audience, and the time it was issued and expires. The private key itself is never sent.
When: when an access token is needed for the requests below. The token is cached until shortly before it expires.
Google Analytics Admin API
Used to read the time zone of your GA4 property, so that periods are counted in the property’s time zone.
Endpoint: https://analyticsadmin.googleapis.com/
Data sent: the property ID and the access token.
When: before retrieving page views, at most once a day per property (the time zone is cached).
Google Analytics Data API
Used to retrieve page views per page path for the selected periods.
Endpoint: https://analyticsdata.googleapis.com/
Data sent: the property ID, the access token, and the report request (date range, page path dimension, page view metric, sort order, and row limit).
When: on the automatic schedule described above, when you choose to retrieve data again after changing the settings, and when you use “Test connection”.
Google APIs Terms of Service: https://developers.google.com/terms
Google Privacy Policy: https://policies.google.com/privacy
Installation
- Install and activate the plugin.
- In Google Cloud, create or choose a project and enable both the “Google Analytics Data API” and the “Google Analytics Admin API”.
- In the same project, create a service account. No Google Cloud role is needed. Open the service account, go to Keys, choose Add key > Create new key > JSON, and download the key file.
- In Google Analytics, open Admin > Property access management for your GA4 property and add the service account email address with the Viewer role.
- In Google Analytics, open Admin > Property details and copy the numeric property ID. Do not use the measurement ID that starts with “G-“.
- In WordPress, open Settings > Analytics Ranking. Enter the property ID, paste the contents of the key file, choose the periods, and save.
- Use “Test connection” to check the settings.
- Add the “Analytics Ranking” block or the
[emiano_ranking]shortcode to a post, page, or widget area.
If another EMIANO plugin is active, the settings screen is under the EMIANO menu instead of Settings.
FAQ
Do I need to add a tracking code?
No. The plugin uses the data that your GA4 property already collects. GA4 itself must be installed on your site separately.
Why does the ranking not show my latest views?
GA4 makes recent data available through its API after a delay of usually 2 to 6 hours, and the plugin retrieves data on a schedule. See “About GA4 data” above.
Why is the ranking empty?
Check the retrieval status on the settings screen. Rankings appear after the first successful retrieval. The plugin uses WP-Cron, which runs when your site receives visits. Also check that the ranking’s period is selected on the settings screen.
If WP-Cron is disabled (DISABLE_WP_CRON) or loopback requests are blocked, call wp-cron.php from your server’s cron or use ALTERNATE_WP_CRON.
The settings screen says “Check the property ID, and make sure the service account is added…”
Google returns the same error when the property ID is wrong and when the service account has no access to the property. Check both.
How is the service account key stored?
The key is saved in your site’s database, in the emiano_ar_settings option, which is not autoloaded and is not exposed through the REST API. It is never displayed again after saving; the settings screen shows only the service account email address. Leave the key field empty to keep the saved key. Use a service account that only has the Viewer role on the GA4 property.
Does it work with the Plain permalink structure?
Yes. With Plain permalinks, the plugin asks GA4 for the page path including the query string (for example /?p=123) and matches it to the post.
Are private or password-protected posts shown?
Private posts, drafts, scheduled posts, and trashed posts are never shown. A post that is made private after retrieval is hidden immediately. Password-protected posts are shown with their protected title, in the same way as WordPress post lists.
What is removed when I delete the plugin?
The settings (including the service account key), the stored rankings, the retrieval status, the cached access token and time zone, and the scheduled events.
Screenshots
Changelog
1.1.0
- Added: Category filter for the block and the
categoryshortcode attribute. - Added:
emiano_ar_get_ranking()function and theemiano_ar_ranking_post_idsandemiano_ar_ranking_htmlfilters. - Changed: Retrieve up to 500 page paths from GA4 per period (previously 200).
- Changed: The Data tab and the preview now tell retrieved-but-empty data apart from data that has not been retrieved yet.
1.0.0
- Initial release.



