Each entry must have a type of ucAnalyticsWidget along with a unique alias and name. An element key should be defined to import the implementation of the UcAnalyticsWidget component interface.
A meta entry provides configuration options for the widget
The Analytics Widget element
In order to define the UI for a widget, you'll need to define a component that implements the UcAnalyticsWidget interface. This interface is defined as
This provides widget implementations with access to the current storeId, the defined manifest, and the current selected timeframe for which the widget should show relevant data.
An example implementation would be
// total-orders-widget.element.jsimport { customElement, html, property, state } from"@umbraco-cms/backoffice/external/lit";import { UmbLitElement } from"@umbraco-cms/backoffice/lit-element";import { UcAnalyticsTimeframe, UcAnalyticsWidget, UcManifestAnalyticsWidget } from"@umbraco-commerce/backoffice";@customElement('uc-total-orders-widget')exportclassUcTotalOrdersWidgetElementextendsUmbLitElementimplementsUcAnalyticsWidget { @property({ type:String }) storeId!:string; @property({ type: Object, attribute:false }) manifest?:UcManifestAnalyticsWidget; @property({ type: Object, attribute:false })settimeframe(timeframe:UcAnalyticsTimeframe) {this._timeframe = timeframe;this.#fetchData(); }private _timeframe?:UcAnalyticsTimeframe; @state()private _data?:any[];#fetchData=async () => {// Fetch data using this._timeframe properties as a filter// and store the result in this._data }render() {if (!this._data) return;returnhtml`-- WIDGET MARKUP GOES HERE --`; }}exportdefault UcTotalOrdersWidgetElement;declare global {interfaceHTMLElementTagNameMap {'uc-total-orders-widget':UcTotalOrdersWidgetElement; }}
When an alternative timeframe is selected from the widget dashboard, all widget's timeframe properties will be updated to re-fetch and render the widget.
Name
Description
label
A label for this widget (supports the # prefix localization string syntax)
description
A description for this widget (supports the # prefix localization string syntax)