Fetch Google Analytics 4 data directly into dotCMS templates using the analytics Velocity viewtool — query metrics, dimensions, and date ranges programmatically.
What it does
This plugin provides a $analytics viewtool in Velocity templates that lets you query Google Analytics 4 (GA4) data directly from your dotCMS pages. You can retrieve metrics like active users, page views, sessions, and more, filtered by dimensions like date, page path, device category, and others.
This plugin is for fetching analytics data from Google Analytics into dotCMS. It does not add tracking code to your site. For tracking, use Google Tag Manager or add the GA4 tracking script directly to your templates.
Use Cases
Content analytics dashboards inside dotCMS — surface real GA4 performance data (pageviews, sessions, bounce rate) directly in your editorial interface, so your team can make smarter content decisions without leaving the CMS
Personalization and content recommendations — power “Most Popular,” “Trending This Week,” or “Readers Also Visited” modules driven by actual traffic data, not manual curation
Identify content to retire or improve — spot low-traffic, high-bounce, or stale pages and act on them before they become a liability
Automate archive and review workflows — trigger content review states based on real engagement signals, so nothing slips through the cracks
Key capabilities
Query GA4 metrics and dimensions directly from Velocity templates
Configurable date ranges, filters, and result limits
Service account authentication via JSON key file configured in the Apps tool
Compatible with all GA4 Data API v1 metrics and dimensions
How to set it up
Requires dotCMS 23.01.10 or higher, a Google Cloud Platform account with the Google Analytics Data API enabled, a service account with JSON credentials, and a GA4 property with Viewer access granted to the service account.
Enable the Google Analytics Data API in your Google Cloud Console project and create a service account with a JSON key file.
Add the service account email as a Viewer in your GA4 property under Admin → Property Access Management.
Download the plugin JAR from the dotCMS/google-analytics GitHub releases page and upload it via System → Dynamic Plugins.
Go to Settings → Apps → Google Analytics, enter an application name, and paste the full contents of your JSON key file.
Use the $analytics viewtool in Velocity templates to create requests, set metrics and dimensions, and query GA4 data.