Skip to content

Commit

Permalink
workaround bug in matomo: showColumns=bounce_rate does not work with …
Browse files Browse the repository at this point in the history
…API.get (#80)

* workaround bug in matomo: showColumns=bounce_rate does not work with API.get

* do not use showColumns for every Module.get API method, just to be sure no other core bugs surface

* add new test for querying a single metric from a ***.get method

* add new expected test file
  • Loading branch information
diosmosis authored Oct 5, 2024
1 parent 45b892a commit 6618509
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,16 @@ function getReportData(request: GoogleAppsScript.Data_Studio.Request<ConnectorPa
}

const SHOW_COLUMNS_UNSUPPORTED_METHODS = [
'VisitFrequency.get',
'Contents.getContentPieces',
'Contents.getContentNames',
'Actions.getPageUrlsFollowingSiteSearch',
];

let showColumns;
// showColumns does not work correctly with some API methods
if (!SHOW_COLUMNS_UNSUPPORTED_METHODS.includes(apiMethod)) {
if (!SHOW_COLUMNS_UNSUPPORTED_METHODS.includes(apiMethod)
&& reportParams.apiAction !== 'get' // showColumns does not work for API methods like API.get or VisitFrequency.get
) {
showColumns = (requestedFields.map(({name}) => name)).join(',');
}

Expand Down Expand Up @@ -290,8 +291,8 @@ function getReportData(request: GoogleAppsScript.Data_Studio.Request<ConnectorPa
filter_limit: `${limitToUse}`,
filter_offset: `${offset}`,
showColumns,
apiModule: null,
apiAction: null,
apiModule: undefined,
apiAction: undefined,
};

if (reportParams.apiModule !== 'Goals' && typeof params.idGoal === 'undefined') {
Expand Down
18 changes: 18 additions & 0 deletions tests/appscript/data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,24 @@ describe('data', () => {
expect(result).toEqual(getExpectedResponse(result, 'data', 'Events.getName_withDateDimension_date'));
});

it('should correctly fetch a single column from a **.get API method', async () => {
let result = await Clasp.run('getData', {
configParams: {
idsite: env.APPSCRIPT_TEST_IDSITE,
report: JSON.stringify({ apiModule: 'API', apiAction: 'get' }),
filter_limit: 5,
},
dateRange: {
startDate: DATE_TO_TEST,
endDate: DATE_TO_TEST,
},
fields: [
{ name: 'bounce_rate' },
],
});
expect(result).toEqual(getExpectedResponse(result, 'data', `API.get_singleProcessedMetric`));
});

it('should correctly fetch data for a date range spanning multiple days', async () => {
await Clasp.run('setScriptProperties', {}, true);

Expand Down
22 changes: 22 additions & 0 deletions tests/appscript/expected/data_API.get_singleProcessedMetric.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"filtersApplied": false,
"rows": [
{
"values": [
"0.73"
]
}
],
"schema": [
{
"dataType": "NUMBER",
"label": "Bounce Rate",
"name": "bounce_rate",
"semantics": {
"conceptType": "METRIC",
"isReaggregatable": false,
"semanticType": "PERCENT"
}
}
]
}

0 comments on commit 6618509

Please sign in to comment.