Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/jwilson529/top5ga/archive/refs/heads/main.zipNo built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.
Top 5 GA is a WordPress plugin that integrates Google Analytics (GA4) data with your WordPress site. It retrieves GA data, maps page view counts to posts (stored as post meta), and provides a shortcode to display the top posts based on GA metrics.
Note: This plugin is a headstart and is not production-ready. It is intended as a starting point for developers to build upon.
Features
- OAuth Integration: Connect your Google Analytics account via OAuth.
- GA Data Retrieval: Fetch GA accounts, properties, and detailed report data using the GA4 Data API.
- Post Meta Mapping: Automatically update posts with GA view counts via a cron job.
- Shortcode: Display the top posts based on GA data using the
[top_ga_posts]shortcode. - Cron Jobs: Scheduled tasks to refresh OAuth tokens and update post metadata.
Installation
- Clone or download the repository.
- Upload the plugin folder to your
/wp-content/plugins/directory. - Activate the plugin via the WordPress Admin panel.
- Go to Settings > Top 5 GA to configure the plugin.
Google Cloud Setup
To get started, you need to obtain OAuth credentials from Google Cloud:
- Visit Google Cloud Console:
- Create a new project or select an existing one.
- Enable APIs:
- Navigate to APIs & Services > Dashboard.
- Click Enable APIs and Services and enable:
- Google Analytics API
- Google Analytics Data API
- Create OAuth Credentials:
- Go to APIs & Services > Credentials.
- Click Create Credentials > OAuth client ID.
- Choose Web Application as the application type.
- Authorized Redirect URI:
https://yourdomain.com/wp-admin/options-general.php?page=top5ga-settingsReplace
yourdomain.comwith your actual domain. - Obtain Your Credentials:
- Click Create to generate your Client ID and Client Secret.
- Configure the Plugin:
- Enter the Client ID and Client Secret on the plugin’s settings page.
Usage
Updating GA Data
- The plugin uses cron jobs to automatically refresh the OAuth token and update post metadata with GA view counts hourly.
- GA data is fetched and mapped to posts by matching the post slug with the GA page path.
Shortcode
Display the top posts on your site by adding this shortcode to a page or widget:
[top_ga_posts limit="5" post_type="post"]