sidecar / craft-analytics
Google Analytics 4 dashboard for Craft CMS
Package info
github.com/alexandreSideCar/craft-analytics
Type:craft-plugin
pkg:composer/sidecar/craft-analytics
Requires
- php: ^8.2
- craftcms/cms: ^5.3.0
- google/analytics-data: ^0.14
- google/apiclient: ^2.15
- google/apiclient-services: ^0.350
README
Google Analytics 4 dashboard plugin for Craft CMS 5.
Features
- Dashboard overview — Users, sessions, and page views for today, 7 days, and 30 days with percentage comparison vs previous period
- Daily traffic chart — Line chart showing users, sessions, and page views over the last 30 days
- Top pages — Most visited pages with title, path, views, and trend
- Traffic sources — Channel breakdown with doughnut chart
- Key events — GA4 key events (conversions) with counts and trends
- Engagement stats — Average session duration, bounce rate, pages per session, new vs returning users
- Google Search Console — Search performance data including queries, pages, clicks, impressions, CTR, and average position
- Dashboard widget — Compact summary widget for the Craft dashboard
- Permissions — Granular user permissions (View Analytics / Manage Analytics)
- Translations — English and French included
- Caching — All API responses cached (configurable duration)
- OAuth2 — Secure connection via Google OAuth2 (no service account JSON needed)
Requirements
- Craft CMS 5.3+
- PHP 8.2+
- A Google Cloud project with the Google Analytics Data API and Google Search Console API enabled
- A GA4 property
- A Search Console property (optional, for Search Console features)
Installation
composer require sidecar/craft-analytics php craft plugin/install craft-analytics
Or install via the Craft CMS Plugin Store.
Google Cloud Setup
- Go to Google Cloud Console
- Create or select a project
- Enable the Google Analytics Data API and the Google Search Console API (APIs & Services > Library)
- Create OAuth 2.0 credentials:
- Go to APIs & Services > Credentials
- Click Create Credentials > OAuth client ID
- Application type: Web application
- Add the Authorized redirect URI shown in the plugin settings page
- Copy the Client ID and Client Secret
Plugin Configuration
- Go to Settings > Plugins > Analytics in the Craft CP
- Enter your GA4 Property ID (numeric ID from GA4 Admin > Property Settings, e.g.
123456789) - Enter your OAuth Client ID and OAuth Client Secret
- Click Save
- Click Connect to Google and authorize access
- You're connected — visit the Analytics section in the CP sidebar
Environment Variables
All settings support environment variables:
GA4_PROPERTY_ID=123456789 GA4_OAUTH_CLIENT_ID=your-client-id.apps.googleusercontent.com GA4_OAUTH_CLIENT_SECRET=your-client-secret
Then in plugin settings, use $GA4_PROPERTY_ID, $GA4_OAUTH_CLIENT_ID, $GA4_OAUTH_CLIENT_SECRET.
Permissions
The plugin registers two permissions under Settings > Users:
| Permission | Description |
|---|---|
| View Analytics | Access the Analytics CP page and dashboard widget |
| Manage Analytics | Clear cache and refresh data (nested under View) |
Admin users always have full access. OAuth connection and plugin settings are restricted to admins only.
Cache
API responses are cached for 5 minutes by default. You can change this in the plugin settings (Cache Duration field). Click Clear Cache & Refresh on the Analytics page to force a refresh.
Translations
The plugin ships with English and French translations. Translation files are located in src/translations/.
License
MIT
Credits
Developed by Side-Car.