Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support aggregation types and formulas for Matomo metrics #68

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
436 changes: 435 additions & 1 deletion package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"build": "rollup -c",
"build:test": "rollup -c rollup-test.config.js",
"build:test": "rollup -c rollup-test.config.mjs",
"clasp": "clasp",
"create": "mkdir -p dist && clasp create --rootDir dist --title='Matomo Looker Studio Connector' --type=standalone && mv ./dist/.clasp.json .",
"push": "tsx ./scripts/push.ts",
Expand All @@ -27,6 +27,7 @@
"devDependencies": {
"@google/clasp": "^2.4.2",
"@jest/globals": "^29.5.0",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.0.0",
"@types/inquirer": "^8.2.10",
Expand Down Expand Up @@ -55,6 +56,7 @@
"dependencies": {
"@types/axios": "^0.14.0",
"@types/google-apps-script": "^1.0.58",
"dayjs": "^1.11.11"
"dayjs": "^1.11.11",
"mathjs": "^13.0.0"
}
}
2 changes: 1 addition & 1 deletion rollup-test.config.js → rollup-test.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

const config = require('./rollup.config');
import config from './rollup.config.mjs';

config.input = 'src-test/index.ts';

Expand Down
24 changes: 19 additions & 5 deletions rollup.config.js → rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

const typescript = require('@rollup/plugin-typescript');
const copy = require('rollup-plugin-copy');
const dotenv = require('rollup-plugin-dotenv').default;
const { nodeResolve } = require('@rollup/plugin-node-resolve');
import typescript from '@rollup/plugin-typescript';
import copy from 'rollup-plugin-copy';
import dotenvModule from 'rollup-plugin-dotenv';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';

const dotenv = dotenvModule.default;

// removes export statements since they are not recognized by apps script, but rollup always puts them in for esm output
const removeExports = () => {
Expand All @@ -20,14 +23,25 @@ const removeExports = () => {
};
};

module.exports = {
export default {
input: 'src/index.ts',
output: {
dir: 'dist',
format: 'esm',
name: 'MatomoLookerStudio',
},
plugins: [
{
transform(code, id) {
// the commonjs rollup plugin does not handle export statements in strings well
if (/\/mathjs\//.test(id)) {
code = code.replace('export const path = "expression.transform"', '');
}
code = code.replace(/\/\*\*.*?\*\//gms, ''); // strip comments since they can have stray imports/exports
return code;
},
},
commonjs(),
nodeResolve(),
typescript(),
dotenv(),
Expand Down
11 changes: 10 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export interface ReportMetadata {
metricTypes?: Record<string, string>;
metricTypesGoal?: Record<string, string>;
parameters?: Record<string, string>;
metricAggregationTypes?: Record<string, string>;
metricAggregationTypesGoal?: Record<string, string>;
processedMetricFormulas?: Record<string, string>;
temporaryMetricAggregationTypes?: Record<string, string>;
temporaryMetricSemanticTypes?: Record<string, string>;
}

export interface Goal {
Expand Down Expand Up @@ -202,10 +207,14 @@ export function fetchAll(requests: MatomoRequestParams[], options: ApiFetchOptio
return; // retry
}

const content = r.getContentText('UTF-8');

responseContents[responseIndex] = {
result: 'error',
message: `Matomo server failed with code ${code}. Truncated response: ${r.getContentText('UTF-8').substring(0, 100)}`,
message: `Matomo server failed with code ${code}. Truncated response: ${content.substring(0, 100)}`,
};

debugLog(`Whole response: ${content}`);
} else {
// save the response even if it's an error so we can get the server-side error message if needed
responseContents[responseIndex] = r.getContentText('UTF-8') || '{}';
Expand Down
Loading
Loading