@backstage-community/plugin-analytics-module-matomo 1.15.0 → 1.17.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 CHANGED
@@ -1,5 +1,28 @@
1
1
  ### Dependencies
2
2
 
3
+ ## 1.17.0
4
+
5
+ ### Minor Changes
6
+
7
+ - b5a8ecf: Added `sendPlainUserId` config, which controls whether hashing of userId should be disabled.
8
+ - 70f97c5: Backstage version bump to v1.40.2
9
+
10
+ ### Patch Changes
11
+
12
+ - 0775db8: remove devDependency on '@redhat-developer/red-hat-developer-hub-theme'
13
+ - 6877ddc: Updated dependency `@testing-library/jest-dom` to `6.6.4`.
14
+
15
+ ## 1.16.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 4ed9028: Backstage version bump to v1.39.0
20
+
21
+ ### Patch Changes
22
+
23
+ - 6a59fcf: remove support and lifecycle keywords in package.json
24
+ - e958f2f: Updated dependency `@types/node` to `22.15.29`.
25
+
3
26
  ## 1.15.0
4
27
 
5
28
  ### Minor Changes
package/README.md CHANGED
@@ -50,6 +50,7 @@ app:
50
50
  host: ${ANALYTICS_MATOMO_INSTANCE_URL}
51
51
  siteId: ${ANALYTICS_MATOMO_SITE_ID}
52
52
  identity: optional # (optional) to enable user tracking. Is disabled by default
53
+ sendPlainUserId: optional # (optional) to not hash User ID when user tracking is enabled. User ID is hashed by default.
53
54
  ```
54
55
 
55
56
  4. Update CSP in your `app-config.yaml`:(optional)
package/config.d.ts CHANGED
@@ -35,6 +35,13 @@ export interface Config {
35
35
  * @visibility frontend
36
36
  */
37
37
  identity?: 'disabled' | 'optional' | 'required';
38
+
39
+ /**
40
+ * Controls if the hashing of userId should be disabled
41
+ *
42
+ * @visibility frontend
43
+ */
44
+ sendPlainUserId?: boolean;
38
45
  };
39
46
  };
40
47
  };
@@ -4,13 +4,18 @@ class MatomoAnalytics {
4
4
  constructor(options) {
5
5
  loadMatomo(options.matomoUrl, options.siteId);
6
6
  if (options.identity !== "disabled" && options.identityApi) {
7
- this.setUserFrom(options.identityApi).then(() => {
8
- return;
9
- });
7
+ this.setUserFrom(options.identityApi, options.sendPlainUserId).catch(
8
+ () => {
9
+ return;
10
+ }
11
+ );
10
12
  }
11
13
  }
12
14
  static fromConfig(config, options) {
13
15
  const identity = config.getOptionalString("app.analytics.matomo.identity") || "disabled";
16
+ const sendPlainUserId = config.getOptionalBoolean(
17
+ "app.analytics.matomo.sendPlainUserId"
18
+ );
14
19
  const matomoUrl = config.getString("app.analytics.matomo.host");
15
20
  const siteId = config.getNumber("app.analytics.matomo.siteId");
16
21
  if (identity === "required" && !options?.identityApi) {
@@ -22,7 +27,8 @@ class MatomoAnalytics {
22
27
  matomoUrl,
23
28
  siteId,
24
29
  identity,
25
- identityApi: options?.identityApi
30
+ identityApi: options?.identityApi,
31
+ sendPlainUserId
26
32
  });
27
33
  }
28
34
  captureEvent(event) {
@@ -35,10 +41,14 @@ class MatomoAnalytics {
35
41
  value
36
42
  ]);
37
43
  }
38
- async setUserFrom(identityApi) {
44
+ async setUserFrom(identityApi, sendPlainUserId) {
39
45
  const { userEntityRef } = await identityApi.getBackstageIdentity();
40
- const userId = await this.getPrivateUserId(userEntityRef);
41
- window._paq.push(["setUserId", userId]);
46
+ if (sendPlainUserId) {
47
+ window._paq.push(["setUserId", userEntityRef]);
48
+ } else {
49
+ const userId = await this.getPrivateUserId(userEntityRef);
50
+ window._paq.push(["setUserId", userId]);
51
+ }
42
52
  }
43
53
  getPrivateUserId(userEntityRef) {
44
54
  return this.hash(userEntityRef);
@@ -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 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,CAAE,KAAK,MAAM;AAC/C,QAAA;AAAA,OACD,CAAA;AAAA;AACH;AACF,EAEA,OAAO,UACL,CAAA,MAAA,EACA,OAGA,EAAA;AACA,IAAA,MAAM,QACJ,GAAA,MAAA,CAAO,iBAAkB,CAAA,+BAA+B,CAAK,IAAA,UAAA;AAE/D,IAAM,MAAA,SAAA,GAAY,MAAO,CAAA,SAAA,CAAU,2BAA2B,CAAA;AAC9D,IAAM,MAAA,MAAA,GAAS,MAAO,CAAA,SAAA,CAAU,6BAA6B,CAAA;AAE7D,IAAA,IAAI,QAAa,KAAA,UAAA,IAAc,CAAC,OAAA,EAAS,WAAa,EAAA;AACpD,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA;AAGF,IAAA,OAAO,IAAI,eAAgB,CAAA;AAAA,MACzB,SAAA;AAAA,MACA,MAAA;AAAA,MACA,QAAA;AAAA,MACA,aAAa,OAAS,EAAA;AAAA,KACvB,CAAA;AAAA;AACH,EAEA,aAAa,KAAuB,EAAA;AAClC,IAAA,MAAM,EAAE,OAAA,EAAS,MAAQ,EAAA,OAAA,EAAS,OAAU,GAAA,KAAA;AAG5C,IAAA,MAAA,CAAO,KAAK,IAAK,CAAA;AAAA,MACf,YAAA;AAAA,MACA,QAAQ,SAAa,IAAA,KAAA;AAAA,MACrB,MAAA;AAAA,MACA,OAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA;AACH,EAEA,MAAc,YAAY,WAA0B,EAAA;AAClD,IAAA,MAAM,EAAE,aAAA,EAAkB,GAAA,MAAM,YAAY,oBAAqB,EAAA;AAGjE,IAAA,MAAM,MAAS,GAAA,MAAM,IAAK,CAAA,gBAAA,CAAiB,aAAa,CAAA;AAExD,IAAA,MAAA,CAAO,IAAK,CAAA,IAAA,CAAK,CAAC,WAAA,EAAa,MAAM,CAAC,CAAA;AAAA;AACxC,EAEQ,iBAAiB,aAAwC,EAAA;AAC/D,IAAO,OAAA,IAAA,CAAK,KAAK,aAAa,CAAA;AAAA;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;;;;"}
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 sendPlainUserId?: boolean;\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, options.sendPlainUserId).catch(\n () => {\n return;\n },\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 sendPlainUserId = config.getOptionalBoolean(\n 'app.analytics.matomo.sendPlainUserId',\n );\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 sendPlainUserId,\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(\n identityApi: IdentityApi,\n sendPlainUserId?: boolean,\n ) {\n const { userEntityRef } = await identityApi.getBackstageIdentity();\n\n if (sendPlainUserId) {\n window._paq.push(['setUserId', userEntityRef]);\n } else {\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\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,OAMjB,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,WAAa,EAAA,OAAA,CAAQ,eAAe,CAAE,CAAA,KAAA;AAAA,QAC7D,MAAM;AACJ,UAAA;AAAA;AACF,OACF;AAAA;AACF;AACF,EAEA,OAAO,UACL,CAAA,MAAA,EACA,OAGA,EAAA;AACA,IAAA,MAAM,QACJ,GAAA,MAAA,CAAO,iBAAkB,CAAA,+BAA+B,CAAK,IAAA,UAAA;AAE/D,IAAA,MAAM,kBAAkB,MAAO,CAAA,kBAAA;AAAA,MAC7B;AAAA,KACF;AAEA,IAAM,MAAA,SAAA,GAAY,MAAO,CAAA,SAAA,CAAU,2BAA2B,CAAA;AAC9D,IAAM,MAAA,MAAA,GAAS,MAAO,CAAA,SAAA,CAAU,6BAA6B,CAAA;AAE7D,IAAA,IAAI,QAAa,KAAA,UAAA,IAAc,CAAC,OAAA,EAAS,WAAa,EAAA;AACpD,MAAA,MAAM,IAAI,KAA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A,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage-community/plugin-analytics-module-matomo",
3
- "version": "1.15.0",
3
+ "version": "1.17.0",
4
4
  "main": "dist/index.esm.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -34,19 +34,18 @@
34
34
  "directory": "workspaces/analytics/plugins/analytics-module-matomo"
35
35
  },
36
36
  "dependencies": {
37
- "@backstage/core-plugin-api": "^1.10.6"
37
+ "@backstage/core-plugin-api": "^1.10.8"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "react": "^16.13.1 || ^17.0.0 || ^18.0.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@backstage/cli": "^0.32.0",
44
- "@backstage/core-app-api": "^1.16.1",
45
- "@backstage/core-components": "^0.17.1",
46
- "@backstage/dev-utils": "^1.1.9",
47
- "@redhat-developer/red-hat-developer-hub-theme": "0.4.0",
48
- "@testing-library/jest-dom": "6.6.3",
49
- "@types/node": "18.19.103",
43
+ "@backstage/cli": "^0.33.0",
44
+ "@backstage/core-app-api": "^1.17.1",
45
+ "@backstage/core-components": "^0.17.3",
46
+ "@backstage/dev-utils": "^1.1.11",
47
+ "@testing-library/jest-dom": "6.6.4",
48
+ "@types/node": "22.15.29",
50
49
  "cross-fetch": "4.0.0",
51
50
  "msw": "1.3.5"
52
51
  },
@@ -62,10 +61,6 @@
62
61
  ],
63
62
  "author": "The Backstage Community",
64
63
  "bugs": "https://github.com/backstage/community-plugins/issues",
65
- "keywords": [
66
- "support:tech-preview",
67
- "lifecycle:active"
68
- ],
69
64
  "typesVersions": {
70
65
  "*": {
71
66
  "package.json": [