Skip to main content
Version: 2.0.0

Google Analytics

Google Analytics connects the store to a Google Analytics 4 (GA4) property, sending e-commerce events (product views, cart activity, checkout, purchases) via the GA4 Measurement Protocol and surfacing GA4 reporting data back inside the Craft control panel — as dashboard widgets, a report field type, and (when the yui/mcp plugin is installed) MCP tools an AI agent can query.

Key features

  • Server-side GA4 event tracking: page views and the full yStore shop funnel (product view, cart view, add/remove from cart, search, begin checkout, purchase, login, sign-up) are sent to GA4 automatically as Craft/yStore events fire — no client-side gtag wiring required.
  • CP dashboard widgets: an E-commerce widget (revenue, transactions), a Realtime widget (active users, active pages), and a configurable Analytics Report widget (any GA4 metric/dimension combination) for the standard Craft Dashboard.
  • Analytics Report field type: attach a per-element traffic/pageview chart (last month, by date) to any element that has a public URL.
  • Multi-site, multi-source: map each Craft site to its own GA4 property (Source), so a multi-site install can report each site against the correct GA4 account.
  • OAuth-connected GA4 Reporting/Admin APIs: sources, properties, and metadata are fetched directly from Google via an OAuth app you register, not hand-entered.
  • MCP tools: when yui/mcp is installed, four tools (analytics_report, analytics_realtime, analytics_ecommerce, analytics_geo) expose GA4 reporting data to AI agents.
  • Twig API for pulling GA4 event objects, tracking URLs, and raw report data into custom templates.

Requirements

  • Craft CMS 5+
  • yStore (yui/craft-plugin) 2+, for e-commerce event tracking (the reporting/dashboard side works standalone)
  • A Google Analytics 4 property with the Measurement Protocol API secret
  • A Google Cloud OAuth client ID/secret, to authorize GA4 Reporting/Admin API access from the CP

Installation

Install through Composer, using the credentials granted by your yStore license:

composer require yui/craft-ga-analytics

Enable the plugin in Settings → Plugins, then continue with Settings to connect a GA4 property.

Use cases

See Use Cases for connecting a GA4 property, mapping sites to sources, reading the dashboard widgets, and choosing which GA4 events get sent automatically.

Developer notes

See Developer / API for the Twig craft.serverAnalytics variable, the GA4 event pipeline, the MCP tools, and a reference table of CP routes.