Skip to main content
Version: 2.0.0

Analytics

The Analytics page collects store statistics and presents them in the Control Panel. Access is consent-gated: an admin must explicitly enable data collection before the dashboard is visible.

Navigate to yStore → Analytics.

Enabling analytics

The first time you visit the Analytics page, yStore checks whether consent has been granted (analyticsConsentGiven plugin setting). If consent has not been given, access is blocked with a notice directing you to enable it from Plugin Settings.

To enable:

  1. Go to yStore → Settings → Plugin.
  2. Find the Analytics section and enable data collection.
  3. Save the settings.
  4. Navigate to yStore → Analytics — the statistics dashboard is now accessible.

Consent can be revoked at any time from the same Plugin Settings page. Revoking consent prevents the analytics dashboard from loading and stops new data collection.

What the dashboard shows

The analytics dashboard displays store-wide statistics derived from live database queries. The data is organized into sections, each populated by an analytics.xml definition file. Sections can include:

  • General store information (site name, currency, Craft version, PHP version, installed plugins)
  • Plugin settings snapshot
  • Statistical aggregates from order, product, and customer tables

The exact metrics available depend on the analytics.xml files shipped with each yStore plugin. Each file contributes named table sections that appear as cards or groups on the dashboard.

Exporting analytics data

The Download action on the Analytics page collects statistics and plugin logs, encrypts them, and compresses them into .gz files available for download. These files are intended for sharing with yStore support when troubleshooting.

The download process:

  1. Statistics are collected and encrypted with AES-256-CBC using the store's configured encryptionKey and encryptionIv values (Plugin Settings → API Credentials).
  2. Plugin logs are encrypted and compressed separately.
  3. Both files are offered as downloads. After download, the compressed files are deleted from the server.
warning

The encryption key and IV are included as metadata in the download response so that the recipient (yStore support) can decrypt the data. Treat downloaded analytics files as confidential.

StateEffect
Not set (default)Dashboard blocked; download endpoint returns no data
Consent grantedDashboard accessible; download creates encrypted files
Consent revokedDashboard blocked; analyticsConsentGiven = null is persisted

Developer reference

Service

yui\craft\services\AnalyticsService (access via Plugin::getInstance()->getAnalytics())

MethodDescription
collectStatistics()Scan vendor analytics.xml files, run queries, populate the data array. Returns $this for chaining.
getCollectedData()Return the populated statistics array
encryptData($data)AES-256-CBC encrypt a string or array using the store's key/IV
saveToFile($encryptedData, $compress, $filename)Write and optionally gzip-compress encrypted data to storage/yui/
getCompressedFilePath($filename)Return the path to an existing .gz file, or null
getPlugins($onlyYuiMade, $licenses)Return an array of installed plugin metadata

Analytics XML definition format

Any plugin can contribute analytics data by placing an analytics.xml file in its vendor directory. The service recursively scans @vendor/yui for files named analytics.xml.

Basic structure:

<analytics>
<table name="yui_orders" code="orders_statistics">
<columns>
<column name="total_orders" type="count" target="entity_id"/>
<column name="total_revenue" type="sum" target="grand_total"/>
<column name="avg_order_value" type="avg" target="grand_total"/>
</columns>
</table>
</analytics>
AttributeDescription
table[@name]Database table name (without prefix)
table[@code]Key under which the result is stored in the data array
column[@type]Aggregation type: count, sum, avg, or omit for a plain column
column[@target]Column to aggregate (comma-separate multiple for multi-column sums)
column[@expression]Raw SQL expression to use instead of a typed column

When table[@code] contains the string statistics, the result is stored as a single row (aggregates). Otherwise it is stored as {total, items}.

Add optional <condition>, <order>, <group>, and <join> child elements to filter or join data:

<table name="yui_orders" code="recent_orders">
<columns>
<column name="increment_id"/>
<column name="grand_total"/>
</columns>
<condition logic="and">
<rule column="order_id" operator="isNotNull"/>
</condition>
<order column="dateCreated" direction="DESC"/>
</table>

Supported condition operators: isNotNull, isNull, greaterThan, lessThan, =.

Controller actions

yui\craft\controllers\AnalyticsController

ActionRouteDescription
actionIndexGET yui/analyticsRender the analytics dashboard (requires consent)
actionSaveConsentPOST yui/analytics/save-consentSave or revoke consent (consent: true/false/null)
actionDownloadGET yui/analytics/downloadCollect, encrypt, compress, and return analytics + log files