diff --git a/packages/nodes-base/nodes/Google/Analytics/GoogleAnalytics.node.ts b/packages/nodes-base/nodes/Google/Analytics/GoogleAnalytics.node.ts index f27cad011d..45704490b3 100644 --- a/packages/nodes-base/nodes/Google/Analytics/GoogleAnalytics.node.ts +++ b/packages/nodes-base/nodes/Google/Analytics/GoogleAnalytics.node.ts @@ -212,6 +212,14 @@ export class GoogleAnalytics implements INodeType { body.dimensions = dimensions; } } + if (additionalFields.dimensionFiltersUi) { + const dimensionFilters = (additionalFields.dimensionFiltersUi as IDataObject).filterValues as IDataObject[]; + if (dimensionFilters) { + dimensionFilters.forEach(filter => filter.expressions = [filter.expressions]); + body.dimensionFilterClauses = { filters: dimensionFilters }; + } + } + if (additionalFields.includeEmptyRows) { Object.assign(body, { includeEmptyRows: additionalFields.includeEmptyRows }); } diff --git a/packages/nodes-base/nodes/Google/Analytics/Interfaces.ts b/packages/nodes-base/nodes/Google/Analytics/Interfaces.ts index 5a54a9acab..e997bbd1f5 100644 --- a/packages/nodes-base/nodes/Google/Analytics/Interfaces.ts +++ b/packages/nodes-base/nodes/Google/Analytics/Interfaces.ts @@ -1,6 +1,9 @@ export interface IData { viewId: string; dimensions?: IDimension[]; + dimensionFilterClauses?: { + filters: IDimensionFilter[]; + }; pageSize?: number; metrics?: IMetric[]; } @@ -10,6 +13,11 @@ export interface IDimension { histogramBuckets?: string[]; } +export interface IDimensionFilter { + dimensionName?: string; + operator?: string; + expressions?: string[]; +} export interface IMetric { expression?: string; alias?: string; diff --git a/packages/nodes-base/nodes/Google/Analytics/ReportDescription.ts b/packages/nodes-base/nodes/Google/Analytics/ReportDescription.ts index 962ca6b3f6..abb20b1b5a 100644 --- a/packages/nodes-base/nodes/Google/Analytics/ReportDescription.ts +++ b/packages/nodes-base/nodes/Google/Analytics/ReportDescription.ts @@ -183,6 +183,85 @@ export const reportFields = [ }, ], }, + { + displayName: 'Dimension Filters', + name: 'dimensionFiltersUi', + type: 'fixedCollection', + default: {}, + typeOptions: { + multipleValues: true, + }, + placeholder: 'Add Dimension Filter', + description: 'Dimension Filters in the request', + options: [ + { + displayName: 'Filters', + name: 'filterValues', + values: [ + { + displayName: 'Dimension Name', + name: 'dimensionName', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getDimensions', + }, + default: '', + description: 'Name of the dimension to filter by.', + }, + // https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/reports/batchGet#Operator + { + displayName: 'Operator', + name: 'operator', + type: 'options', + default: 'EXACT', + description: 'Operator to use in combination with value.', + options: [ + { + name: 'Begins With', + value: 'BEGINS_WITH', + }, + { + name: 'Ends With', + value: 'ENDS_WITH', + }, + { + name: 'Exact', + value: 'EXACT', + }, + { + name: 'Greater Than (number)', + value: 'NUMERIC_GREATER_THAN', + }, + { + name: 'Partial', + value: 'PARTIAL', + }, + { + name: 'Regular Expression', + value: 'REGEXP', + }, + { + name: 'Equal (number)', + value: 'NUMERIC_EQUAL', + }, + { + name: 'Less Than (number)', + value: 'NUMERIC_LESS_THAN', + }, + ], + }, + { + displayName: 'Value', + name: 'expressions', + type: 'string', + default: '', + placeholder: 'ga:newUsers', + description: `String or regular expression to match against.`, + }, + ], + }, + ], + }, { displayName: 'Hide Totals', name: 'hideTotals',