@backstage-community/plugin-analytics-module-matomo 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -0
- package/config.d.ts +7 -0
- package/dist/api/Matomo.esm.js +38 -16
- package/dist/api/Matomo.esm.js.map +1 -1
- package/dist/index.d.ts +16 -9
- package/dist/index.esm.js +12 -1
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/config.d.ts
CHANGED
|
@@ -28,6 +28,13 @@ export interface Config {
|
|
|
28
28
|
* @visibility frontend
|
|
29
29
|
*/
|
|
30
30
|
siteId: string;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Controls how the identityApi is used when sending data to Matomo:
|
|
34
|
+
*
|
|
35
|
+
* @visibility frontend
|
|
36
|
+
*/
|
|
37
|
+
identity?: 'disabled' | 'optional' | 'required';
|
|
31
38
|
};
|
|
32
39
|
};
|
|
33
40
|
};
|
package/dist/api/Matomo.esm.js
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
|
-
import { createApiFactory, analyticsApiRef, configApiRef } from '@backstage/core-plugin-api';
|
|
2
1
|
import { loadMatomo } from './loadMatomo.esm.js';
|
|
3
2
|
|
|
4
3
|
class MatomoAnalytics {
|
|
5
|
-
configApi;
|
|
6
4
|
constructor(options) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
loadMatomo(options.matomoUrl, options.siteId);
|
|
6
|
+
if (options.identity !== "disabled" && options.identityApi) {
|
|
7
|
+
this.setUserFrom(options.identityApi).then(() => {
|
|
8
|
+
return;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
13
11
|
}
|
|
14
|
-
static fromConfig(config) {
|
|
15
|
-
|
|
12
|
+
static fromConfig(config, options) {
|
|
13
|
+
const identity = config.getOptionalString("app.analytics.matomo.identity") || "disabled";
|
|
14
|
+
const matomoUrl = config.getString("app.analytics.matomo.host");
|
|
15
|
+
const siteId = config.getNumber("app.analytics.matomo.siteId");
|
|
16
|
+
if (identity === "required" && !options?.identityApi) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
"Invalid config: identity API must be provided to deps when app.matomo.identity is required"
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
return new MatomoAnalytics({
|
|
22
|
+
matomoUrl,
|
|
23
|
+
siteId,
|
|
24
|
+
identity,
|
|
25
|
+
identityApi: options?.identityApi
|
|
26
|
+
});
|
|
16
27
|
}
|
|
17
28
|
captureEvent(event) {
|
|
18
29
|
const { context, action, subject, value } = event;
|
|
@@ -24,12 +35,23 @@ class MatomoAnalytics {
|
|
|
24
35
|
value
|
|
25
36
|
]);
|
|
26
37
|
}
|
|
38
|
+
async setUserFrom(identityApi) {
|
|
39
|
+
const { userEntityRef } = await identityApi.getBackstageIdentity();
|
|
40
|
+
const userId = await this.getPrivateUserId(userEntityRef);
|
|
41
|
+
window._paq.push(["setUserId", userId]);
|
|
42
|
+
}
|
|
43
|
+
getPrivateUserId(userEntityRef) {
|
|
44
|
+
return this.hash(userEntityRef);
|
|
45
|
+
}
|
|
46
|
+
async hash(value) {
|
|
47
|
+
const digest = await window.crypto.subtle.digest(
|
|
48
|
+
"sha-256",
|
|
49
|
+
new TextEncoder().encode(value)
|
|
50
|
+
);
|
|
51
|
+
const hashArray = Array.from(new Uint8Array(digest));
|
|
52
|
+
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
53
|
+
}
|
|
27
54
|
}
|
|
28
|
-
const MatomoAnalyticsApi = createApiFactory({
|
|
29
|
-
api: analyticsApiRef,
|
|
30
|
-
deps: { configApi: configApiRef },
|
|
31
|
-
factory: ({ configApi }) => MatomoAnalytics.fromConfig(configApi)
|
|
32
|
-
});
|
|
33
55
|
|
|
34
|
-
export { MatomoAnalytics
|
|
56
|
+
export { MatomoAnalytics };
|
|
35
57
|
//# sourceMappingURL=Matomo.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Matomo.esm.js","sources":["../../src/api/Matomo.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n AnalyticsApi,\n AnalyticsEvent,\n ConfigApi,\n
|
|
1
|
+
{"version":3,"file":"Matomo.esm.js","sources":["../../src/api/Matomo.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n AnalyticsApi,\n AnalyticsEvent,\n ConfigApi,\n IdentityApi,\n} from '@backstage/core-plugin-api';\n\nimport { loadMatomo } from './loadMatomo';\n\ndeclare const window: Window &\n typeof globalThis & {\n _paq: any[];\n };\n\n/**\n * @public\n */\nexport class MatomoAnalytics implements AnalyticsApi {\n private constructor(options: {\n matomoUrl: string;\n siteId: number;\n identity: string;\n identityApi?: IdentityApi;\n }) {\n loadMatomo(options.matomoUrl, options.siteId);\n\n /* Add user tracking if identity is enabled and identityApi is provided */\n if (options.identity !== 'disabled' && options.identityApi) {\n this.setUserFrom(options.identityApi).then(() => {\n return;\n });\n }\n }\n\n static fromConfig(\n config: ConfigApi,\n options?: {\n identityApi?: IdentityApi;\n },\n ) {\n const identity =\n config.getOptionalString('app.analytics.matomo.identity') || 'disabled';\n\n const matomoUrl = config.getString('app.analytics.matomo.host');\n const siteId = config.getNumber('app.analytics.matomo.siteId');\n\n if (identity === 'required' && !options?.identityApi) {\n throw new Error(\n 'Invalid config: identity API must be provided to deps when app.matomo.identity is required',\n );\n }\n\n return new MatomoAnalytics({\n matomoUrl,\n siteId,\n identity,\n identityApi: options?.identityApi,\n });\n }\n\n captureEvent(event: AnalyticsEvent) {\n const { context, action, subject, value } = event;\n // REF: https://github.com/backstage/community-plugins/blob/main/workspaces/analytics/plugins/analytics-module-ga/src/apis/implementations/AnalyticsApi/GoogleAnalytics.ts#L160\n // REF: https://matomo.org/faq/reports/implement-event-tracking-with-matomo/\n window._paq.push([\n 'trackEvent',\n context.extension || 'App',\n action,\n subject,\n value,\n ]);\n }\n\n private async setUserFrom(identityApi: IdentityApi) {\n const { userEntityRef } = await identityApi.getBackstageIdentity();\n\n // Prevent PII from being passed to Matomo\n const userId = await this.getPrivateUserId(userEntityRef);\n\n window._paq.push(['setUserId', userId]);\n }\n\n private getPrivateUserId(userEntityRef: string): Promise<string> {\n return this.hash(userEntityRef);\n }\n\n private async hash(value: string): Promise<string> {\n const digest = await window.crypto.subtle.digest(\n 'sha-256',\n new TextEncoder().encode(value),\n );\n const hashArray = Array.from(new Uint8Array(digest));\n return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');\n }\n}\n"],"names":[],"mappings":";;AAgCO,MAAM,eAAwC,CAAA;AAAA,EAC3C,YAAY,OAKjB,EAAA;AACD,IAAW,UAAA,CAAA,OAAA,CAAQ,SAAW,EAAA,OAAA,CAAQ,MAAM,CAAA;AAG5C,IAAA,IAAI,OAAQ,CAAA,QAAA,KAAa,UAAc,IAAA,OAAA,CAAQ,WAAa,EAAA;AAC1D,MAAA,IAAA,CAAK,WAAY,CAAA,OAAA,CAAQ,WAAW,CAAA,CAA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AAA;AAChC,EAEA,MAAc,KAAK,KAAgC,EAAA;AACjD,IAAA,MAAM,MAAS,GAAA,MAAM,MAAO,CAAA,MAAA,CAAO,MAAO,CAAA,MAAA;AAAA,MACxC,SAAA;AAAA,MACA,IAAI,WAAA,EAAc,CAAA,MAAA,CAAO,KAAK;AAAA,KAChC;AACA,IAAA,MAAM,YAAY,KAAM,CAAA,IAAA,CAAK,IAAI,UAAA,CAAW,MAAM,CAAC,CAAA;AACnD,IAAA,OAAO,SAAU,CAAA,GAAA,CAAI,CAAK,CAAA,KAAA,CAAA,CAAE,QAAS,CAAA,EAAE,CAAE,CAAA,QAAA,CAAS,CAAG,EAAA,GAAG,CAAC,CAAA,CAAE,KAAK,EAAE,CAAA;AAAA;AAEtE;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
|
-
import * as _backstage_core_plugin_api from '@backstage/core-plugin-api';
|
|
2
|
-
import { AnalyticsApi, ConfigApi, AnalyticsEvent } from '@backstage/core-plugin-api';
|
|
3
1
|
import * as _backstage_config_index from '@backstage/config/index';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
declare const analyticsModuleMatomoPlugin: _backstage_core_plugin_api.BackstagePlugin<{}, {}, {}>;
|
|
2
|
+
import * as _backstage_core_plugin_api from '@backstage/core-plugin-api';
|
|
3
|
+
import { AnalyticsApi, ConfigApi, IdentityApi, AnalyticsEvent } from '@backstage/core-plugin-api';
|
|
7
4
|
|
|
8
5
|
/**
|
|
9
6
|
* @public
|
|
10
7
|
*/
|
|
11
8
|
declare class MatomoAnalytics implements AnalyticsApi {
|
|
12
|
-
private readonly configApi;
|
|
13
9
|
private constructor();
|
|
14
|
-
static fromConfig(config: ConfigApi
|
|
10
|
+
static fromConfig(config: ConfigApi, options?: {
|
|
11
|
+
identityApi?: IdentityApi;
|
|
12
|
+
}): MatomoAnalytics;
|
|
15
13
|
captureEvent(event: AnalyticsEvent): void;
|
|
14
|
+
private setUserFrom;
|
|
15
|
+
private getPrivateUserId;
|
|
16
|
+
private hash;
|
|
16
17
|
}
|
|
18
|
+
|
|
19
|
+
/** @public */
|
|
20
|
+
declare const analyticsModuleMatomoPlugin: _backstage_core_plugin_api.BackstagePlugin<{}, {}, {}>;
|
|
21
|
+
|
|
17
22
|
/**
|
|
18
|
-
*
|
|
23
|
+
* API factory method for matomo
|
|
24
|
+
*
|
|
19
25
|
* @public
|
|
20
26
|
*/
|
|
21
|
-
declare const MatomoAnalyticsApi: _backstage_core_plugin_api.ApiFactory<AnalyticsApi, MatomoAnalytics, {
|
|
27
|
+
declare const MatomoAnalyticsApi: _backstage_core_plugin_api.ApiFactory<_backstage_core_plugin_api.AnalyticsApi, MatomoAnalytics, {
|
|
22
28
|
configApi: _backstage_config_index.Config;
|
|
29
|
+
identityApi: _backstage_core_plugin_api.IdentityApi;
|
|
23
30
|
}>;
|
|
24
31
|
|
|
25
32
|
export { MatomoAnalytics, MatomoAnalyticsApi, analyticsModuleMatomoPlugin };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
import { createApiFactory, analyticsApiRef, configApiRef, identityApiRef } from '@backstage/core-plugin-api';
|
|
2
|
+
import { MatomoAnalytics } from './api/Matomo.esm.js';
|
|
1
3
|
export { analyticsModuleMatomoPlugin } from './plugin.esm.js';
|
|
2
|
-
|
|
4
|
+
|
|
5
|
+
const MatomoAnalyticsApi = createApiFactory({
|
|
6
|
+
api: analyticsApiRef,
|
|
7
|
+
deps: { configApi: configApiRef, identityApi: identityApiRef },
|
|
8
|
+
factory: ({ configApi, identityApi }) => MatomoAnalytics.fromConfig(configApi, {
|
|
9
|
+
identityApi
|
|
10
|
+
})
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export { MatomoAnalytics, MatomoAnalyticsApi };
|
|
3
14
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/index.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n analyticsApiRef,\n configApiRef,\n createApiFactory,\n identityApiRef,\n} from '@backstage/core-plugin-api';\nimport { MatomoAnalytics } from './api';\n\nexport { analyticsModuleMatomoPlugin } from './plugin';\nexport * from './api';\n/**\n * API factory method for matomo\n *\n * @public\n */\nexport const MatomoAnalyticsApi = createApiFactory({\n api: analyticsApiRef,\n deps: { configApi: configApiRef, identityApi: identityApiRef },\n factory: ({ configApi, identityApi }) =>\n MatomoAnalytics.fromConfig(configApi, {\n identityApi,\n }),\n});\n"],"names":[],"mappings":";;;;AA8BO,MAAM,qBAAqB,gBAAiB,CAAA;AAAA,EACjD,GAAK,EAAA,eAAA;AAAA,EACL,IAAM,EAAA,EAAE,SAAW,EAAA,YAAA,EAAc,aAAa,cAAe,EAAA;AAAA,EAC7D,OAAA,EAAS,CAAC,EAAE,SAAA,EAAW,aACrB,KAAA,eAAA,CAAgB,WAAW,SAAW,EAAA;AAAA,IACpC;AAAA,GACD;AACL,CAAC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage-community/plugin-analytics-module-matomo",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"main": "dist/index.esm.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"sideEffects": false,
|
|
18
18
|
"scripts": {
|
|
19
|
-
"start": "backstage-cli package start",
|
|
19
|
+
"start": "backstage-cli package start --config app-config.yaml",
|
|
20
20
|
"build": "backstage-cli package build",
|
|
21
21
|
"prettier:check": "prettier --ignore-unknown --check .",
|
|
22
22
|
"prettier:fix": "prettier --ignore-unknown --write .",
|