Reference

Source

A Source object represents a configured analytics connection. Obtain one from Metrix's Sources service when integration code needs provider capabilities or data fetching. Dashboard templates do not normally call these methods directly.

use verbb\metrix\Metrix;

$source = Metrix::$plugin->getSources()->getSourceByHandle(
    'analytics',
    enabledOnly: true,
    connectedOnly: true,
);

if ($source && $source->supportsDimensions()) {
    $dimensions = $source->fetchAvailableDimensions();
}

Properties

id

The unique identifier for the source, or null before it’s saved.

name

The name of the source.

handle

The handle of the source.

enabled

Whether the source is enabled.

Provider-specific credentials, such as API keys, OAuth tokens and site IDs, live in each Source type’s settings rather than as shared attributes on every Source.

Methods

isConfigured()

Returns whether the source has the settings or credentials it needs to connect.

isConnected()

Returns whether the source is connected, using its saved credentials or OAuth token.

getCapabilities()

Returns the source’s capability flags, keyed as realtime, dimensions, connection, oauth and analyticsScope.

supportsRealtime()

Returns whether a realtime widget can use the source. It’s true when the source implements fetchRealtimeData().

supportsDimensions()

Returns whether the source can break data down by dimension, for table and pie widgets.

supportsAnalyticsScope()

Returns whether the source can apply a View’s analytics scope, such as a path prefix or hostname.

applyAnalyticsScope()

Arguments: array &$request, AnalyticsScope $scope

Changes a provider request to honour a View’s analytics scope. Sources that don’t support scope leave the request unchanged.

fetchAvailableMetrics()

Returns the metrics the source’s provider offers, as label and value pairs.

fetchAvailableDimensions()

Returns the dimensions the source’s provider offers, as label and value pairs.

fetchData()

Arguments: WidgetDataInterface $widgetData

Returns the data for a widget over its period, using the widget’s metric and dimension.

fetchRealtimeData()

Arguments: WidgetDataInterface $widgetData

Returns a real-time payload when the provider supports it. Implementing this method makes supportsRealtime() return true.

fetchConnection()

Returns whether a test request to the provider succeeds with the source’s saved credentials.

getPrimaryColor()

Returns the provider’s brand colour, used for the source in the control panel.

getIcon()

Returns the provider’s icon as SVG markup, or null when it has none.