diff --git a/src/api.ts b/src/api.ts index d329ec9..0f72a99 100644 --- a/src/api.ts +++ b/src/api.ts @@ -52,6 +52,8 @@ export interface ReportMetadata { metricTypes?: Record; metricTypesGoal?: Record; parameters?: Record; + metricAggregationTypes?: Record; + metricAggregationTypesGoal?: Record; } export interface Goal { diff --git a/src/schema/data-types.ts b/src/schema/data-types.ts index ec1391d..aee9a2c 100644 --- a/src/schema/data-types.ts +++ b/src/schema/data-types.ts @@ -5,8 +5,10 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ +import AggregationType = GoogleAppsScript.Data_Studio.AggregationType; import cc from '../connector'; -import dayjs from "dayjs/esm"; +import dayjs from 'dayjs/esm'; +import { log } from '../log'; export const MATOMO_SEMANTIC_TYPE_TO_LOOKER_MAPPING = { 'dimension': cc.FieldType.TEXT, @@ -97,3 +99,23 @@ export function convertMatomoTypeToLooker(value: any, matomoType: string) { // fail to display the data. return `${value}`; } + +export function mapMatomoAggregationTypeToLooker(matomoAggregation: string): AggregationType|undefined { + switch (matomoAggregation.toLowerCase()) { + case 'avg': + return AggregationType.AVG; + case 'count': // TODO: do we really need to support count and count_distinct? does not seem to apply to matomo + return AggregationType.COUNT; + case 'count_distinct': + return AggregationType.COUNT_DISTINCT; + case 'max': + return AggregationType.SUM; + case 'min': + return AggregationType.MIN; + case 'sum': + return AggregationType.SUM; + default: + log(`unknown matomo aggregation type encountered: ${matomoAggregation}`); + return undefined; + } +} diff --git a/src/schema/report-metadata.ts b/src/schema/report-metadata.ts index fa8c26e..cf9608f 100644 --- a/src/schema/report-metadata.ts +++ b/src/schema/report-metadata.ts @@ -10,6 +10,7 @@ import * as Api from '../api'; import { DATE_DIMENSIONS, mapMatomoSemanticTypeToLooker, + mapMatomoAggregationTypeToLooker, } from "./data-types"; export function getReportMetadataAndGoalsAndCurrency(request: GoogleAppsScript.Data_Studio.Request) { @@ -87,15 +88,28 @@ function metricsForEachGoal(metrics: Record, goals: Record