@backstage-community/plugin-analytics-module-ga4 0.2.6 → 0.2.8

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,17 @@
1
1
  # @backstage-community/plugin-analytics-module-ga4
2
2
 
3
+ ## 0.2.8
4
+
5
+ ### Patch Changes
6
+
7
+ - fa9e4f4: version:bump to v1.29.1
8
+
9
+ ## 0.2.7
10
+
11
+ ### Patch Changes
12
+
13
+ - 347a5eb: Filter out custom dimenstion keys with empty string values
14
+
3
15
  ## 0.2.6
4
16
 
5
17
  ### Patch Changes
@@ -0,0 +1,198 @@
1
+ import ReactGA from 'react-ga4';
2
+ import { DeferredCapture } from '../../../util/DeferredCapture.esm.js';
3
+
4
+ class GoogleAnalytics4 {
5
+ customUserIdTransform;
6
+ capture;
7
+ contentGroupBy;
8
+ allowedContexts;
9
+ allowedAttributes;
10
+ /**
11
+ * Instantiate the implementation and initialize ReactGA.
12
+ * @param options initializes Google Analytics module with the config
13
+ */
14
+ constructor(options) {
15
+ const {
16
+ identity,
17
+ measurementId,
18
+ identityApi,
19
+ userIdTransform = "sha-256",
20
+ testMode,
21
+ debug,
22
+ enableSendPageView,
23
+ contentGroupBy,
24
+ allowedContexts,
25
+ allowedAttributes
26
+ } = options;
27
+ ReactGA.initialize(measurementId, {
28
+ testMode,
29
+ gaOptions: {
30
+ debug_mode: debug
31
+ },
32
+ gtagOptions: {
33
+ debug_mode: debug,
34
+ send_page_view: enableSendPageView
35
+ }
36
+ });
37
+ this.contentGroupBy = contentGroupBy;
38
+ this.allowedAttributes = allowedAttributes;
39
+ this.allowedContexts = allowedContexts;
40
+ this.capture = new DeferredCapture({ defer: identity === "required" });
41
+ this.customUserIdTransform = typeof userIdTransform === "function" ? userIdTransform : void 0;
42
+ if (identity !== "disabled") {
43
+ if (identityApi) {
44
+ this.setUserFrom(identityApi).then(() => {
45
+ return;
46
+ });
47
+ }
48
+ }
49
+ }
50
+ /**
51
+ * Instantiate a fully configured GA Analytics API implementation.
52
+ * @param config - Config object from app config
53
+ * @param options - options with identityApi and userIdTransform config
54
+ */
55
+ static fromConfig(config, options = {}) {
56
+ const measurementId = config.getString("app.analytics.ga4.measurementId");
57
+ const identity = config.getOptionalString("app.analytics.ga4.identity") || "disabled";
58
+ const debug = config.getOptionalBoolean("app.analytics.ga4.debug") ?? false;
59
+ const enableSendPageView = config.getOptionalBoolean("app.analytics.ga4.enableSendPageView") ?? false;
60
+ const testMode = config.getOptionalBoolean("app.analytics.ga4.testMode") ?? false;
61
+ const contentGroupBy = config.getOptionalString(
62
+ "app.analytics.ga4.contentGrouping"
63
+ );
64
+ const allowedContexts = config.getOptionalStringArray(
65
+ "app.analytics.ga4.allowedContexts"
66
+ );
67
+ const allowedAttributes = config.getOptionalStringArray(
68
+ "app.analytics.ga4.allowedAttributes"
69
+ );
70
+ if (identity === "required" && !options.identityApi) {
71
+ throw new Error(
72
+ "Invalid config: identity API must be provided to deps when ga4.identity is required"
73
+ );
74
+ }
75
+ return new GoogleAnalytics4({
76
+ ...options,
77
+ identity,
78
+ measurementId,
79
+ testMode,
80
+ debug,
81
+ enableSendPageView,
82
+ contentGroupBy,
83
+ allowedContexts,
84
+ allowedAttributes
85
+ });
86
+ }
87
+ /**
88
+ * Primary event capture implementation. Handles core navigate event as a
89
+ * pageview and the rest as custom events. All custom dimensions/metrics are
90
+ * applied as they should be (set on pageview, merged object on events).
91
+ * @param event - AnalyticsEvent type captured
92
+ */
93
+ captureEvent(event) {
94
+ const { context, action, subject, value, attributes } = event;
95
+ const customEventData = this.setEventParameters(context, attributes);
96
+ if (this.contentGroupBy) {
97
+ customEventData.content_group = context[this.contentGroupBy];
98
+ }
99
+ const extensionId = context.extensionId || context.extension;
100
+ const category = extensionId ? String(extensionId) : "App";
101
+ if (action === "navigate" && category.toLocaleLowerCase("en-US").startsWith("app")) {
102
+ this.capture.event(
103
+ {
104
+ category,
105
+ action: "page_view",
106
+ label: subject,
107
+ value
108
+ },
109
+ customEventData
110
+ );
111
+ return;
112
+ }
113
+ if (action === "search") {
114
+ customEventData.search_term = subject;
115
+ }
116
+ this.capture.event(
117
+ {
118
+ category,
119
+ action,
120
+ label: subject,
121
+ value
122
+ },
123
+ customEventData
124
+ );
125
+ }
126
+ /**
127
+ * Returns an object of dimensions/metrics given an Analytics Context and an
128
+ * Event Attributes, e.g. { c_pluginId: "some value", a_attribute1: 42 }
129
+ * @param context analytics context object
130
+ * @param attributes additional analytics event attributes
131
+ */
132
+ setEventParameters(context, attributes = {}) {
133
+ const customEventParameters = {};
134
+ const contextKeys = this.allowedContexts?.join("") === "*" ? Object.keys(context) : this.allowedContexts;
135
+ contextKeys?.forEach((ctx) => {
136
+ if (context[ctx] !== void 0 && context[ctx] !== null && context[ctx] !== "") {
137
+ customEventParameters[`c_${ctx}`] = context[ctx];
138
+ }
139
+ });
140
+ const attrKeys = this.allowedAttributes?.join("") === "*" ? Object.keys(attributes) : this.allowedAttributes;
141
+ attrKeys?.forEach((attr) => {
142
+ if (attributes[attr] !== void 0 && attributes[attr] !== null && attributes[attr] !== "") {
143
+ customEventParameters[`a_${attr}`] = attributes[attr];
144
+ }
145
+ });
146
+ return customEventParameters;
147
+ }
148
+ /**
149
+ * Sets the GA userId, based on the `userEntityRef` set on the backstage
150
+ * identity loaded from a given Backstage Identity API instance. Because
151
+ * Google forbids sending any PII (including on the userId field), we hash
152
+ * the entire `userEntityRef` on behalf of integrators:
153
+ *
154
+ * - With value `User:default/name`, userId becomes `sha256(User:default/name)`
155
+ *
156
+ * If an integrator wishes to use an alternative hashing mechanism or an
157
+ * entirely different value, they may do so by passing a `userIdTransform`
158
+ * function alongside the `identityApi` to `GoogleAnalytics.fromConfig()`.
159
+ * This function receives the `userEntityRef` as an argument and should
160
+ * resolve to a hashed version of whatever identifier they choose.
161
+ *
162
+ * Note: this feature requires that an integrator has set up a Google
163
+ * Analytics User ID view in the property used to track Backstage.
164
+ * @param identityApi IdentityApi object
165
+ */
166
+ async setUserFrom(identityApi) {
167
+ const { userEntityRef } = await identityApi.getBackstageIdentity();
168
+ const userId = await this.getPrivateUserId(userEntityRef);
169
+ ReactGA.set({ user_id: userId });
170
+ this.capture.setReady();
171
+ }
172
+ /**
173
+ * Returns a PII-free (according to Google's terms of service) user ID for
174
+ * use in Google Analytics.
175
+ * @param userEntityRef user entity as string
176
+ */
177
+ getPrivateUserId(userEntityRef) {
178
+ if (this.customUserIdTransform) {
179
+ return this.customUserIdTransform(userEntityRef);
180
+ }
181
+ return this.hash(userEntityRef);
182
+ }
183
+ /**
184
+ * Simple hash function; relies on web cryptography + the sha-256 algorithm.
185
+ * @param value value to be hashed
186
+ */
187
+ async hash(value) {
188
+ const digest = await window.crypto.subtle.digest(
189
+ "sha-256",
190
+ new TextEncoder().encode(value)
191
+ );
192
+ const hashArray = Array.from(new Uint8Array(digest));
193
+ return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
194
+ }
195
+ }
196
+
197
+ export { GoogleAnalytics4 };
198
+ //# sourceMappingURL=GoogleAnalytics4.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoogleAnalytics4.esm.js","sources":["../../../../src/apis/implementations/AnalyticsApi/GoogleAnalytics4.ts"],"sourcesContent":["/*\n * Copyright 2023 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 */\n\nimport ReactGA from 'react-ga4';\nimport {\n AnalyticsApi,\n AnalyticsContextValue,\n AnalyticsEventAttributes,\n AnalyticsEvent,\n IdentityApi,\n} from '@backstage/core-plugin-api';\nimport {\n AnalyticsApi as NewAnalyticsApi,\n AnalyticsEvent as NewAnalyticsEvent,\n AnalyticsContextValue as NewAnalyticsContextValue,\n} from '@backstage/frontend-plugin-api';\nimport { Config } from '@backstage/config';\nimport { DeferredCapture } from '../../../util/DeferredCapture';\n\n/**\n * Google Analytics API provider for the Backstage Analytics API.\n * @public\n */\nexport class GoogleAnalytics4 implements AnalyticsApi, NewAnalyticsApi {\n private readonly customUserIdTransform?: (\n userEntityRef: string,\n ) => Promise<string>;\n private readonly capture: DeferredCapture;\n private readonly contentGroupBy?: string;\n private readonly allowedContexts?: string[];\n private readonly allowedAttributes?: string[];\n /**\n * Instantiate the implementation and initialize ReactGA.\n * @param options initializes Google Analytics module with the config\n */\n private constructor(options: {\n identityApi?: IdentityApi;\n userIdTransform?: 'sha-256' | ((userEntityRef: string) => Promise<string>);\n identity: string;\n measurementId: string;\n testMode: boolean;\n debug: boolean;\n enableSendPageView: boolean;\n contentGroupBy?: string;\n allowedContexts?: string[];\n allowedAttributes?: string[];\n }) {\n const {\n identity,\n measurementId,\n identityApi,\n userIdTransform = 'sha-256',\n testMode,\n debug,\n enableSendPageView,\n contentGroupBy,\n allowedContexts,\n allowedAttributes,\n } = options;\n // Initialize Google Analytics.\n ReactGA.initialize(measurementId, {\n testMode,\n gaOptions: {\n debug_mode: debug,\n },\n gtagOptions: {\n debug_mode: debug,\n send_page_view: enableSendPageView,\n },\n });\n\n this.contentGroupBy = contentGroupBy;\n this.allowedAttributes = allowedAttributes;\n this.allowedContexts = allowedContexts;\n // If identity is required, defer event capture until identity is known.\n this.capture = new DeferredCapture({ defer: identity === 'required' });\n\n // Allow custom userId transformation.\n this.customUserIdTransform =\n typeof userIdTransform === 'function' ? userIdTransform : undefined;\n\n // Capture user only when explicitly enabled and provided.\n if (identity !== 'disabled') {\n if (identityApi) {\n this.setUserFrom(identityApi).then(() => {\n return;\n });\n }\n }\n }\n\n /**\n * Instantiate a fully configured GA Analytics API implementation.\n * @param config - Config object from app config\n * @param options - options with identityApi and userIdTransform config\n */\n static fromConfig(\n config: Config,\n options: {\n identityApi?: IdentityApi;\n userIdTransform?:\n | 'sha-256'\n | ((userEntityRef: string) => Promise<string>);\n } = {},\n ) {\n // Get all necessary configuration.\n const measurementId = config.getString('app.analytics.ga4.measurementId');\n const identity =\n config.getOptionalString('app.analytics.ga4.identity') || 'disabled';\n const debug = config.getOptionalBoolean('app.analytics.ga4.debug') ?? false;\n const enableSendPageView =\n config.getOptionalBoolean('app.analytics.ga4.enableSendPageView') ??\n false;\n const testMode =\n config.getOptionalBoolean('app.analytics.ga4.testMode') ?? false;\n\n const contentGroupBy = config.getOptionalString(\n 'app.analytics.ga4.contentGrouping',\n );\n const allowedContexts = config.getOptionalStringArray(\n 'app.analytics.ga4.allowedContexts',\n );\n const allowedAttributes = config.getOptionalStringArray(\n 'app.analytics.ga4.allowedAttributes',\n );\n\n if (identity === 'required' && !options.identityApi) {\n throw new Error(\n 'Invalid config: identity API must be provided to deps when ga4.identity is required',\n );\n }\n\n // Return an implementation instance.\n return new GoogleAnalytics4({\n ...options,\n identity,\n measurementId: measurementId,\n testMode,\n debug,\n enableSendPageView,\n contentGroupBy,\n allowedContexts,\n allowedAttributes,\n });\n }\n\n /**\n * Primary event capture implementation. Handles core navigate event as a\n * pageview and the rest as custom events. All custom dimensions/metrics are\n * applied as they should be (set on pageview, merged object on events).\n * @param event - AnalyticsEvent type captured\n */\n captureEvent(event: AnalyticsEvent | NewAnalyticsEvent) {\n const { context, action, subject, value, attributes } = event;\n const customEventData = this.setEventParameters(context, attributes);\n if (this.contentGroupBy) {\n customEventData.content_group = context[this.contentGroupBy]!;\n }\n\n const extensionId = context.extensionId || context.extension;\n const category = extensionId ? String(extensionId) : 'App';\n\n // The legacy default extension was 'App' and the new one is 'app'\n if (\n action === 'navigate' &&\n category.toLocaleLowerCase('en-US').startsWith('app')\n ) {\n this.capture.event(\n {\n category,\n action: 'page_view',\n label: subject,\n value,\n },\n customEventData,\n );\n return;\n }\n\n if (action === 'search') {\n customEventData.search_term = subject;\n }\n\n this.capture.event(\n {\n category,\n action,\n label: subject,\n value,\n },\n customEventData,\n );\n }\n\n /**\n * Returns an object of dimensions/metrics given an Analytics Context and an\n * Event Attributes, e.g. { c_pluginId: \"some value\", a_attribute1: 42 }\n * @param context analytics context object\n * @param attributes additional analytics event attributes\n */\n private setEventParameters(\n context: AnalyticsContextValue | NewAnalyticsContextValue,\n attributes: AnalyticsEventAttributes = {},\n ) {\n const customEventParameters: {\n [x: string]: string | number | boolean | undefined;\n } = {};\n\n const contextKeys =\n this.allowedContexts?.join('') === '*'\n ? Object.keys(context)\n : this.allowedContexts;\n\n contextKeys?.forEach(ctx => {\n if (\n context[ctx] !== undefined &&\n context[ctx] !== null &&\n context[ctx] !== ''\n ) {\n customEventParameters[`c_${ctx}`] = context[ctx];\n }\n });\n\n const attrKeys =\n this.allowedAttributes?.join('') === '*'\n ? Object.keys(attributes)\n : this.allowedAttributes;\n attrKeys?.forEach(attr => {\n if (\n attributes[attr] !== undefined &&\n attributes[attr] !== null &&\n attributes[attr] !== ''\n ) {\n customEventParameters[`a_${attr}`] = attributes[attr];\n }\n });\n\n return customEventParameters;\n }\n\n /**\n * Sets the GA userId, based on the `userEntityRef` set on the backstage\n * identity loaded from a given Backstage Identity API instance. Because\n * Google forbids sending any PII (including on the userId field), we hash\n * the entire `userEntityRef` on behalf of integrators:\n *\n * - With value `User:default/name`, userId becomes `sha256(User:default/name)`\n *\n * If an integrator wishes to use an alternative hashing mechanism or an\n * entirely different value, they may do so by passing a `userIdTransform`\n * function alongside the `identityApi` to `GoogleAnalytics.fromConfig()`.\n * This function receives the `userEntityRef` as an argument and should\n * resolve to a hashed version of whatever identifier they choose.\n *\n * Note: this feature requires that an integrator has set up a Google\n * Analytics User ID view in the property used to track Backstage.\n * @param identityApi IdentityApi object\n */\n private async setUserFrom(identityApi: IdentityApi) {\n const { userEntityRef } = await identityApi.getBackstageIdentity();\n\n // Prevent PII from being passed to Google Analytics.\n const userId = await this.getPrivateUserId(userEntityRef);\n\n // Set the user ID.\n ReactGA.set({ user_id: userId });\n\n // Notify the deferred capture mechanism that it may proceed.\n this.capture.setReady();\n }\n\n /**\n * Returns a PII-free (according to Google's terms of service) user ID for\n * use in Google Analytics.\n * @param userEntityRef user entity as string\n */\n private getPrivateUserId(userEntityRef: string): Promise<string> {\n // Allow integrators to provide their own hashing transformer.\n if (this.customUserIdTransform) {\n return this.customUserIdTransform(userEntityRef);\n }\n\n return this.hash(userEntityRef);\n }\n\n /**\n * Simple hash function; relies on web cryptography + the sha-256 algorithm.\n * @param value value to be hashed\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":";;;AAoCO,MAAM,gBAA0D,CAAA;AAAA,EACpD,qBAAA,CAAA;AAAA,EAGA,OAAA,CAAA;AAAA,EACA,cAAA,CAAA;AAAA,EACA,eAAA,CAAA;AAAA,EACA,iBAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKT,YAAY,OAWjB,EAAA;AACD,IAAM,MAAA;AAAA,MACJ,QAAA;AAAA,MACA,aAAA;AAAA,MACA,WAAA;AAAA,MACA,eAAkB,GAAA,SAAA;AAAA,MAClB,QAAA;AAAA,MACA,KAAA;AAAA,MACA,kBAAA;AAAA,MACA,cAAA;AAAA,MACA,eAAA;AAAA,MACA,iBAAA;AAAA,KACE,GAAA,OAAA,CAAA;AAEJ,IAAA,OAAA,CAAQ,WAAW,aAAe,EAAA;AAAA,MAChC,QAAA;AAAA,MACA,SAAW,EAAA;AAAA,QACT,UAAY,EAAA,KAAA;AAAA,OACd;AAAA,MACA,WAAa,EAAA;AAAA,QACX,UAAY,EAAA,KAAA;AAAA,QACZ,cAAgB,EAAA,kBAAA;AAAA,OAClB;AAAA,KACD,CAAA,CAAA;AAED,IAAA,IAAA,CAAK,cAAi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CAAA;AAAA,KAChC,CAAA;AACA,IAAA,MAAM,YAAY,KAAM,CAAA,IAAA,CAAK,IAAI,UAAA,CAAW,MAAM,CAAC,CAAA,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,CAAA;AAAA,GACpE;AACF;;;;"}
package/dist/index.esm.js CHANGED
@@ -1,267 +1,2 @@
1
- import ReactGA from 'react-ga4';
2
-
3
- var __defProp$1 = Object.defineProperty;
4
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
- var __publicField$1 = (obj, key, value) => {
6
- __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
7
- return value;
8
- };
9
- class DeferredCapture {
10
- /**
11
- * constructor for creating the DeferredCapture object
12
- * @param defer type of {defer: boolean}
13
- */
14
- constructor({ defer = false }) {
15
- /**
16
- * Queue of deferred hits to be processed when ready. When undefined, hits
17
- * can safely be sent without delay.
18
- */
19
- __publicField$1(this, "queue");
20
- this.queue = defer ? [] : void 0;
21
- }
22
- /**
23
- * Indicates that deferred capture may now proceed.
24
- */
25
- setReady() {
26
- if (this.queue) {
27
- this.queue.forEach(this.sendDeferred);
28
- this.queue = void 0;
29
- }
30
- }
31
- /**
32
- * Either forwards the event directly to GA, or (if configured) enqueues the
33
- * event hit to be captured when ready.
34
- * @param eventDetails type of UaEventOptions object
35
- * @param metadata any object that can be passed as additional parameter to the event
36
- */
37
- event(eventDetails, metadata = {}) {
38
- const data = {
39
- ...eventDetails,
40
- ...metadata
41
- };
42
- if (this.queue) {
43
- this.queue.push({
44
- hitType: eventDetails.action,
45
- data: {
46
- ...data,
47
- timestamp_micros: Date.now() * 1e3
48
- }
49
- });
50
- return;
51
- }
52
- ReactGA.event(eventDetails.action, data);
53
- }
54
- /**
55
- * Sends a given hit to GA, decorated with the correct queue time.
56
- * @param hit Hit object
57
- */
58
- sendDeferred(hit) {
59
- ReactGA.event(hit.hitType, {
60
- ...hit.data
61
- });
62
- }
63
- }
64
-
65
- var __defProp = Object.defineProperty;
66
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
67
- var __publicField = (obj, key, value) => {
68
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
69
- return value;
70
- };
71
- class GoogleAnalytics4 {
72
- /**
73
- * Instantiate the implementation and initialize ReactGA.
74
- * @param options initializes Google Analytics module with the config
75
- */
76
- constructor(options) {
77
- __publicField(this, "customUserIdTransform");
78
- __publicField(this, "capture");
79
- __publicField(this, "contentGroupBy");
80
- __publicField(this, "allowedContexts");
81
- __publicField(this, "allowedAttributes");
82
- const {
83
- identity,
84
- measurementId,
85
- identityApi,
86
- userIdTransform = "sha-256",
87
- testMode,
88
- debug,
89
- enableSendPageView,
90
- contentGroupBy,
91
- allowedContexts,
92
- allowedAttributes
93
- } = options;
94
- ReactGA.initialize(measurementId, {
95
- testMode,
96
- gaOptions: {
97
- debug_mode: debug
98
- },
99
- gtagOptions: {
100
- debug_mode: debug,
101
- send_page_view: enableSendPageView
102
- }
103
- });
104
- this.contentGroupBy = contentGroupBy;
105
- this.allowedAttributes = allowedAttributes;
106
- this.allowedContexts = allowedContexts;
107
- this.capture = new DeferredCapture({ defer: identity === "required" });
108
- this.customUserIdTransform = typeof userIdTransform === "function" ? userIdTransform : void 0;
109
- if (identity !== "disabled") {
110
- if (identityApi) {
111
- this.setUserFrom(identityApi).then(() => {
112
- return;
113
- });
114
- }
115
- }
116
- }
117
- /**
118
- * Instantiate a fully configured GA Analytics API implementation.
119
- * @param config - Config object from app config
120
- * @param options - options with identityApi and userIdTransform config
121
- */
122
- static fromConfig(config, options = {}) {
123
- var _a, _b, _c;
124
- const measurementId = config.getString("app.analytics.ga4.measurementId");
125
- const identity = config.getOptionalString("app.analytics.ga4.identity") || "disabled";
126
- const debug = (_a = config.getOptionalBoolean("app.analytics.ga4.debug")) != null ? _a : false;
127
- const enableSendPageView = (_b = config.getOptionalBoolean("app.analytics.ga4.enableSendPageView")) != null ? _b : false;
128
- const testMode = (_c = config.getOptionalBoolean("app.analytics.ga4.testMode")) != null ? _c : false;
129
- const contentGroupBy = config.getOptionalString(
130
- "app.analytics.ga4.contentGrouping"
131
- );
132
- const allowedContexts = config.getOptionalStringArray(
133
- "app.analytics.ga4.allowedContexts"
134
- );
135
- const allowedAttributes = config.getOptionalStringArray(
136
- "app.analytics.ga4.allowedAttributes"
137
- );
138
- if (identity === "required" && !options.identityApi) {
139
- throw new Error(
140
- "Invalid config: identity API must be provided to deps when ga4.identity is required"
141
- );
142
- }
143
- return new GoogleAnalytics4({
144
- ...options,
145
- identity,
146
- measurementId,
147
- testMode,
148
- debug,
149
- enableSendPageView,
150
- contentGroupBy,
151
- allowedContexts,
152
- allowedAttributes
153
- });
154
- }
155
- /**
156
- * Primary event capture implementation. Handles core navigate event as a
157
- * pageview and the rest as custom events. All custom dimensions/metrics are
158
- * applied as they should be (set on pageview, merged object on events).
159
- * @param event - AnalyticsEvent type captured
160
- */
161
- captureEvent(event) {
162
- const { context, action, subject, value, attributes } = event;
163
- const customEventData = this.setEventParameters(context, attributes);
164
- if (this.contentGroupBy) {
165
- customEventData.content_group = context[this.contentGroupBy];
166
- }
167
- const extensionId = context.extensionId || context.extension;
168
- const category = extensionId ? String(extensionId) : "App";
169
- if (action === "navigate" && category.toLocaleLowerCase("en-US").startsWith("app")) {
170
- this.capture.event(
171
- {
172
- category,
173
- action: "page_view",
174
- label: subject,
175
- value
176
- },
177
- customEventData
178
- );
179
- return;
180
- }
181
- if (action === "search") {
182
- customEventData.search_term = subject;
183
- }
184
- this.capture.event(
185
- {
186
- category,
187
- action,
188
- label: subject,
189
- value
190
- },
191
- customEventData
192
- );
193
- }
194
- /**
195
- * Returns an object of dimensions/metrics given an Analytics Context and an
196
- * Event Attributes, e.g. { c_pluginId: "some value", a_attribute1: 42 }
197
- * @param context analytics context object
198
- * @param attributes additional analytics event attributes
199
- */
200
- setEventParameters(context, attributes = {}) {
201
- var _a, _b;
202
- const customEventParameters = {};
203
- const contextKeys = ((_a = this.allowedContexts) == null ? void 0 : _a.join("")) === "*" ? Object.keys(context) : this.allowedContexts;
204
- contextKeys == null ? void 0 : contextKeys.forEach((ctx) => {
205
- if (context[ctx] !== void 0 && context[ctx] !== null) {
206
- customEventParameters[`c_${ctx}`] = context[ctx];
207
- }
208
- });
209
- const attrKeys = ((_b = this.allowedAttributes) == null ? void 0 : _b.join("")) === "*" ? Object.keys(attributes) : this.allowedAttributes;
210
- attrKeys == null ? void 0 : attrKeys.forEach((attr) => {
211
- if (attributes[attr] !== void 0 && attributes[attr] !== null) {
212
- customEventParameters[`a_${attr}`] = attributes[attr];
213
- }
214
- });
215
- return customEventParameters;
216
- }
217
- /**
218
- * Sets the GA userId, based on the `userEntityRef` set on the backstage
219
- * identity loaded from a given Backstage Identity API instance. Because
220
- * Google forbids sending any PII (including on the userId field), we hash
221
- * the entire `userEntityRef` on behalf of integrators:
222
- *
223
- * - With value `User:default/name`, userId becomes `sha256(User:default/name)`
224
- *
225
- * If an integrator wishes to use an alternative hashing mechanism or an
226
- * entirely different value, they may do so by passing a `userIdTransform`
227
- * function alongside the `identityApi` to `GoogleAnalytics.fromConfig()`.
228
- * This function receives the `userEntityRef` as an argument and should
229
- * resolve to a hashed version of whatever identifier they choose.
230
- *
231
- * Note: this feature requires that an integrator has set up a Google
232
- * Analytics User ID view in the property used to track Backstage.
233
- * @param identityApi IdentityApi object
234
- */
235
- async setUserFrom(identityApi) {
236
- const { userEntityRef } = await identityApi.getBackstageIdentity();
237
- const userId = await this.getPrivateUserId(userEntityRef);
238
- ReactGA.set({ user_id: userId });
239
- this.capture.setReady();
240
- }
241
- /**
242
- * Returns a PII-free (according to Google's terms of service) user ID for
243
- * use in Google Analytics.
244
- * @param userEntityRef user entity as string
245
- */
246
- getPrivateUserId(userEntityRef) {
247
- if (this.customUserIdTransform) {
248
- return this.customUserIdTransform(userEntityRef);
249
- }
250
- return this.hash(userEntityRef);
251
- }
252
- /**
253
- * Simple hash function; relies on web cryptography + the sha-256 algorithm.
254
- * @param value value to be hashed
255
- */
256
- async hash(value) {
257
- const digest = await window.crypto.subtle.digest(
258
- "sha-256",
259
- new TextEncoder().encode(value)
260
- );
261
- const hashArray = Array.from(new Uint8Array(digest));
262
- return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
263
- }
264
- }
265
-
266
- export { GoogleAnalytics4 };
1
+ export { GoogleAnalytics4 } from './apis/implementations/AnalyticsApi/GoogleAnalytics4.esm.js';
267
2
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/util/DeferredCapture.ts","../src/apis/implementations/AnalyticsApi/GoogleAnalytics4.ts"],"sourcesContent":["/*\n * Copyright 2023 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 ReactGA from 'react-ga4';\n\nimport { UaEventOptions } from 'react-ga4/types/ga4';\n\ntype Hit = {\n hitType: string;\n data: {\n [x: string]: any;\n };\n};\n\n/**\n * A wrapper around ReactGA that can optionally handle latent capture logic.\n *\n * - When defer is `false`, event data is sent directly to GA.\n * - When defer is `true`, event data is queued (with a timestamp), so that it\n * can be sent to GA once externally indicated to be ready. This relies on\n * the `qt` or `queueTime` parameter of the Measurement Protocol.\n *\n * @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#qt\n */\nexport class DeferredCapture {\n /**\n * Queue of deferred hits to be processed when ready. When undefined, hits\n * can safely be sent without delay.\n */\n private queue: Hit[] | undefined;\n\n /**\n * constructor for creating the DeferredCapture object\n * @param defer type of {defer: boolean}\n */\n constructor({ defer = false }: { defer: boolean }) {\n this.queue = defer ? [] : undefined;\n }\n\n /**\n * Indicates that deferred capture may now proceed.\n */\n setReady() {\n if (this.queue) {\n this.queue.forEach(this.sendDeferred);\n this.queue = undefined;\n }\n }\n\n /**\n * Either forwards the event directly to GA, or (if configured) enqueues the\n * event hit to be captured when ready.\n * @param eventDetails type of UaEventOptions object\n * @param metadata any object that can be passed as additional parameter to the event\n */\n event(eventDetails: UaEventOptions, metadata: any = {}) {\n const data = {\n ...eventDetails,\n ...metadata,\n };\n if (this.queue) {\n this.queue.push({\n hitType: eventDetails.action,\n data: {\n ...data,\n timestamp_micros: Date.now() * 1000,\n },\n });\n return;\n }\n ReactGA.event(eventDetails.action, data);\n }\n\n /**\n * Sends a given hit to GA, decorated with the correct queue time.\n * @param hit Hit object\n */\n private sendDeferred(hit: Hit) {\n // Send the hit with the appropriate queue time (`qt`).\n ReactGA.event(hit.hitType, {\n ...hit.data,\n });\n }\n}\n","/*\n * Copyright 2023 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 */\n\nimport ReactGA from 'react-ga4';\nimport {\n AnalyticsApi,\n AnalyticsContextValue,\n AnalyticsEventAttributes,\n AnalyticsEvent,\n IdentityApi,\n} from '@backstage/core-plugin-api';\nimport {\n AnalyticsApi as NewAnalyticsApi,\n AnalyticsEvent as NewAnalyticsEvent,\n AnalyticsContextValue as NewAnalyticsContextValue,\n} from '@backstage/frontend-plugin-api';\nimport { Config } from '@backstage/config';\nimport { DeferredCapture } from '../../../util/DeferredCapture';\n\n/**\n * Google Analytics API provider for the Backstage Analytics API.\n * @public\n */\nexport class GoogleAnalytics4 implements AnalyticsApi, NewAnalyticsApi {\n private readonly customUserIdTransform?: (\n userEntityRef: string,\n ) => Promise<string>;\n private readonly capture: DeferredCapture;\n private readonly contentGroupBy?: string;\n private readonly allowedContexts?: string[];\n private readonly allowedAttributes?: string[];\n /**\n * Instantiate the implementation and initialize ReactGA.\n * @param options initializes Google Analytics module with the config\n */\n private constructor(options: {\n identityApi?: IdentityApi;\n userIdTransform?: 'sha-256' | ((userEntityRef: string) => Promise<string>);\n identity: string;\n measurementId: string;\n testMode: boolean;\n debug: boolean;\n enableSendPageView: boolean;\n contentGroupBy?: string;\n allowedContexts?: string[];\n allowedAttributes?: string[];\n }) {\n const {\n identity,\n measurementId,\n identityApi,\n userIdTransform = 'sha-256',\n testMode,\n debug,\n enableSendPageView,\n contentGroupBy,\n allowedContexts,\n allowedAttributes,\n } = options;\n // Initialize Google Analytics.\n ReactGA.initialize(measurementId, {\n testMode,\n gaOptions: {\n debug_mode: debug,\n },\n gtagOptions: {\n debug_mode: debug,\n send_page_view: enableSendPageView,\n },\n });\n\n this.contentGroupBy = contentGroupBy;\n this.allowedAttributes = allowedAttributes;\n this.allowedContexts = allowedContexts;\n // If identity is required, defer event capture until identity is known.\n this.capture = new DeferredCapture({ defer: identity === 'required' });\n\n // Allow custom userId transformation.\n this.customUserIdTransform =\n typeof userIdTransform === 'function' ? userIdTransform : undefined;\n\n // Capture user only when explicitly enabled and provided.\n if (identity !== 'disabled') {\n if (identityApi) {\n this.setUserFrom(identityApi).then(() => {\n return;\n });\n }\n }\n }\n\n /**\n * Instantiate a fully configured GA Analytics API implementation.\n * @param config - Config object from app config\n * @param options - options with identityApi and userIdTransform config\n */\n static fromConfig(\n config: Config,\n options: {\n identityApi?: IdentityApi;\n userIdTransform?:\n | 'sha-256'\n | ((userEntityRef: string) => Promise<string>);\n } = {},\n ) {\n // Get all necessary configuration.\n const measurementId = config.getString('app.analytics.ga4.measurementId');\n const identity =\n config.getOptionalString('app.analytics.ga4.identity') || 'disabled';\n const debug = config.getOptionalBoolean('app.analytics.ga4.debug') ?? false;\n const enableSendPageView =\n config.getOptionalBoolean('app.analytics.ga4.enableSendPageView') ??\n false;\n const testMode =\n config.getOptionalBoolean('app.analytics.ga4.testMode') ?? false;\n\n const contentGroupBy = config.getOptionalString(\n 'app.analytics.ga4.contentGrouping',\n );\n const allowedContexts = config.getOptionalStringArray(\n 'app.analytics.ga4.allowedContexts',\n );\n const allowedAttributes = config.getOptionalStringArray(\n 'app.analytics.ga4.allowedAttributes',\n );\n\n if (identity === 'required' && !options.identityApi) {\n throw new Error(\n 'Invalid config: identity API must be provided to deps when ga4.identity is required',\n );\n }\n\n // Return an implementation instance.\n return new GoogleAnalytics4({\n ...options,\n identity,\n measurementId: measurementId,\n testMode,\n debug,\n enableSendPageView,\n contentGroupBy,\n allowedContexts,\n allowedAttributes,\n });\n }\n\n /**\n * Primary event capture implementation. Handles core navigate event as a\n * pageview and the rest as custom events. All custom dimensions/metrics are\n * applied as they should be (set on pageview, merged object on events).\n * @param event - AnalyticsEvent type captured\n */\n captureEvent(event: AnalyticsEvent | NewAnalyticsEvent) {\n const { context, action, subject, value, attributes } = event;\n const customEventData = this.setEventParameters(context, attributes);\n if (this.contentGroupBy) {\n customEventData.content_group = context[this.contentGroupBy]!;\n }\n\n const extensionId = context.extensionId || context.extension;\n const category = extensionId ? String(extensionId) : 'App';\n\n // The legacy default extension was 'App' and the new one is 'app'\n if (\n action === 'navigate' &&\n category.toLocaleLowerCase('en-US').startsWith('app')\n ) {\n this.capture.event(\n {\n category,\n action: 'page_view',\n label: subject,\n value,\n },\n customEventData,\n );\n return;\n }\n\n if (action === 'search') {\n customEventData.search_term = subject;\n }\n\n this.capture.event(\n {\n category,\n action,\n label: subject,\n value,\n },\n customEventData,\n );\n }\n\n /**\n * Returns an object of dimensions/metrics given an Analytics Context and an\n * Event Attributes, e.g. { c_pluginId: \"some value\", a_attribute1: 42 }\n * @param context analytics context object\n * @param attributes additional analytics event attributes\n */\n private setEventParameters(\n context: AnalyticsContextValue | NewAnalyticsContextValue,\n attributes: AnalyticsEventAttributes = {},\n ) {\n const customEventParameters: {\n [x: string]: string | number | boolean | undefined;\n } = {};\n\n const contextKeys =\n this.allowedContexts?.join('') === '*'\n ? Object.keys(context)\n : this.allowedContexts;\n\n contextKeys?.forEach(ctx => {\n if (context[ctx] !== undefined && context[ctx] !== null) {\n customEventParameters[`c_${ctx}`] = context[ctx];\n }\n });\n\n const attrKeys =\n this.allowedAttributes?.join('') === '*'\n ? Object.keys(attributes)\n : this.allowedAttributes;\n attrKeys?.forEach(attr => {\n if (attributes[attr] !== undefined && attributes[attr] !== null) {\n customEventParameters[`a_${attr}`] = attributes[attr];\n }\n });\n\n return customEventParameters;\n }\n\n /**\n * Sets the GA userId, based on the `userEntityRef` set on the backstage\n * identity loaded from a given Backstage Identity API instance. Because\n * Google forbids sending any PII (including on the userId field), we hash\n * the entire `userEntityRef` on behalf of integrators:\n *\n * - With value `User:default/name`, userId becomes `sha256(User:default/name)`\n *\n * If an integrator wishes to use an alternative hashing mechanism or an\n * entirely different value, they may do so by passing a `userIdTransform`\n * function alongside the `identityApi` to `GoogleAnalytics.fromConfig()`.\n * This function receives the `userEntityRef` as an argument and should\n * resolve to a hashed version of whatever identifier they choose.\n *\n * Note: this feature requires that an integrator has set up a Google\n * Analytics User ID view in the property used to track Backstage.\n * @param identityApi IdentityApi object\n */\n private async setUserFrom(identityApi: IdentityApi) {\n const { userEntityRef } = await identityApi.getBackstageIdentity();\n\n // Prevent PII from being passed to Google Analytics.\n const userId = await this.getPrivateUserId(userEntityRef);\n\n // Set the user ID.\n ReactGA.set({ user_id: userId });\n\n // Notify the deferred capture mechanism that it may proceed.\n this.capture.setReady();\n }\n\n /**\n * Returns a PII-free (according to Google's terms of service) user ID for\n * use in Google Analytics.\n * @param userEntityRef user entity as string\n */\n private getPrivateUserId(userEntityRef: string): Promise<string> {\n // Allow integrators to provide their own hashing transformer.\n if (this.customUserIdTransform) {\n return this.customUserIdTransform(userEntityRef);\n }\n\n return this.hash(userEntityRef);\n }\n\n /**\n * Simple hash function; relies on web cryptography + the sha-256 algorithm.\n * @param value value to be hashed\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":["__publicField"],"mappings":";;;;;;;;AAoCO,MAAM,eAAgB,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW3B,WAAY,CAAA,EAAE,KAAQ,GAAA,KAAA,EAA6B,EAAA;AANnD;AAAA;AAAA;AAAA;AAAA,IAAQA,eAAA,CAAA,IAAA,EAAA,OAAA,CAAA,CAAA;AAON,IAAK,IAAA,CAAA,KAAA,GAAQ,KAAQ,GAAA,EAAK,GAAA,KAAA,CAAA,CAAA;AAAA,GAC5B;AAAA;AAAA;AAAA;AAAA,EAKA,QAAW,GAAA;AACT,IAAA,IAAI,KAAK,KAAO,EAAA;AACd,MAAK,IAAA,CAAA,KAAA,CAAM,OAAQ,CAAA,IAAA,CAAK,YAAY,CAAA,CAAA;AACpC,MAAA,IAAA,CAAK,KAAQ,GAAA,KAAA,CAAA,CAAA;AAAA,KACf;AAAA,GACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,KAAM,CAAA,YAAA,EAA8B,QAAgB,GAAA,EAAI,EAAA;AACtD,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,GAAG,YAAA;AAAA,MACH,GAAG,QAAA;AAAA,KACL,CAAA;AACA,IAAA,IAAI,KAAK,KAAO,EAAA;AACd,MAAA,IAAA,CAAK,MAAM,IAAK,CAAA;A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;AAAA;AAAA;AAAA;AAAA;AAAA,EAOQ,iBAAiB,aAAwC,EAAA;AAE/D,IAAA,IAAI,KAAK,qBAAuB,EAAA;AAC9B,MAAO,OAAA,IAAA,CAAK,sBAAsB,aAAa,CAAA,CAAA;AAAA,KACjD;AAEA,IAAO,OAAA,IAAA,CAAK,KAAK,aAAa,CAAA,CAAA;AAAA,GAChC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,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,CAAA;AAAA,KAChC,CAAA;AACA,IAAA,MAAM,YAAY,KAAM,CAAA,IAAA,CAAK,IAAI,UAAA,CAAW,MAAM,CAAC,CAAA,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,CAAA;AAAA,GACpE;AACF;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,60 @@
1
+ import ReactGA from 'react-ga4';
2
+
3
+ class DeferredCapture {
4
+ /**
5
+ * Queue of deferred hits to be processed when ready. When undefined, hits
6
+ * can safely be sent without delay.
7
+ */
8
+ queue;
9
+ /**
10
+ * constructor for creating the DeferredCapture object
11
+ * @param defer type of {defer: boolean}
12
+ */
13
+ constructor({ defer = false }) {
14
+ this.queue = defer ? [] : void 0;
15
+ }
16
+ /**
17
+ * Indicates that deferred capture may now proceed.
18
+ */
19
+ setReady() {
20
+ if (this.queue) {
21
+ this.queue.forEach(this.sendDeferred);
22
+ this.queue = void 0;
23
+ }
24
+ }
25
+ /**
26
+ * Either forwards the event directly to GA, or (if configured) enqueues the
27
+ * event hit to be captured when ready.
28
+ * @param eventDetails type of UaEventOptions object
29
+ * @param metadata any object that can be passed as additional parameter to the event
30
+ */
31
+ event(eventDetails, metadata = {}) {
32
+ const data = {
33
+ ...eventDetails,
34
+ ...metadata
35
+ };
36
+ if (this.queue) {
37
+ this.queue.push({
38
+ hitType: eventDetails.action,
39
+ data: {
40
+ ...data,
41
+ timestamp_micros: Date.now() * 1e3
42
+ }
43
+ });
44
+ return;
45
+ }
46
+ ReactGA.event(eventDetails.action, data);
47
+ }
48
+ /**
49
+ * Sends a given hit to GA, decorated with the correct queue time.
50
+ * @param hit Hit object
51
+ */
52
+ sendDeferred(hit) {
53
+ ReactGA.event(hit.hitType, {
54
+ ...hit.data
55
+ });
56
+ }
57
+ }
58
+
59
+ export { DeferredCapture };
60
+ //# sourceMappingURL=DeferredCapture.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeferredCapture.esm.js","sources":["../../src/util/DeferredCapture.ts"],"sourcesContent":["/*\n * Copyright 2023 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 ReactGA from 'react-ga4';\n\nimport { UaEventOptions } from 'react-ga4/types/ga4';\n\ntype Hit = {\n hitType: string;\n data: {\n [x: string]: any;\n };\n};\n\n/**\n * A wrapper around ReactGA that can optionally handle latent capture logic.\n *\n * - When defer is `false`, event data is sent directly to GA.\n * - When defer is `true`, event data is queued (with a timestamp), so that it\n * can be sent to GA once externally indicated to be ready. This relies on\n * the `qt` or `queueTime` parameter of the Measurement Protocol.\n *\n * @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#qt\n */\nexport class DeferredCapture {\n /**\n * Queue of deferred hits to be processed when ready. When undefined, hits\n * can safely be sent without delay.\n */\n private queue: Hit[] | undefined;\n\n /**\n * constructor for creating the DeferredCapture object\n * @param defer type of {defer: boolean}\n */\n constructor({ defer = false }: { defer: boolean }) {\n this.queue = defer ? [] : undefined;\n }\n\n /**\n * Indicates that deferred capture may now proceed.\n */\n setReady() {\n if (this.queue) {\n this.queue.forEach(this.sendDeferred);\n this.queue = undefined;\n }\n }\n\n /**\n * Either forwards the event directly to GA, or (if configured) enqueues the\n * event hit to be captured when ready.\n * @param eventDetails type of UaEventOptions object\n * @param metadata any object that can be passed as additional parameter to the event\n */\n event(eventDetails: UaEventOptions, metadata: any = {}) {\n const data = {\n ...eventDetails,\n ...metadata,\n };\n if (this.queue) {\n this.queue.push({\n hitType: eventDetails.action,\n data: {\n ...data,\n timestamp_micros: Date.now() * 1000,\n },\n });\n return;\n }\n ReactGA.event(eventDetails.action, data);\n }\n\n /**\n * Sends a given hit to GA, decorated with the correct queue time.\n * @param hit Hit object\n */\n private sendDeferred(hit: Hit) {\n // Send the hit with the appropriate queue time (`qt`).\n ReactGA.event(hit.hitType, {\n ...hit.data,\n });\n }\n}\n"],"names":[],"mappings":";;AAoCO,MAAM,eAAgB,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKnB,KAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMR,WAAY,CAAA,EAAE,KAAQ,GAAA,KAAA,EAA6B,EAAA;AACjD,IAAK,IAAA,CAAA,KAAA,GAAQ,KAAQ,GAAA,EAAK,GAAA,KAAA,CAAA,CAAA;AAAA,GAC5B;AAAA;AAAA;AAAA;AAAA,EAKA,QAAW,GAAA;AACT,IAAA,IAAI,KAAK,KAAO,EAAA;AACd,MAAK,IAAA,CAAA,KAAA,CAAM,OAAQ,CAAA,IAAA,CAAK,YAAY,CAAA,CAAA;AACpC,MAAA,IAAA,CAAK,KAAQ,GAAA,KAAA,CAAA,CAAA;AAAA,KACf;AAAA,GACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,KAAM,CAAA,YAAA,EAA8B,QAAgB,GAAA,EAAI,EAAA;AACtD,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,GAAG,YAAA;AAAA,MACH,GAAG,QAAA;AAAA,KACL,CAAA;AACA,IAAA,IAAI,KAAK,KAAO,EAAA;AACd,MAAA,IAAA,CAAK,MAAM,IAAK,CAAA;AAAA,QACd,SAAS,YAAa,CAAA,MAAA;AAAA,QACtB,IAAM,EAAA;AAAA,UACJ,GAAG,IAAA;AAAA,UACH,gBAAA,EAAkB,IAAK,CAAA,GAAA,EAAQ,GAAA,GAAA;AAAA,SACjC;AAAA,OACD,CAAA,CAAA;AACD,MAAA,OAAA;AAAA,KACF;AACA,IAAQ,OAAA,CAAA,KAAA,CAAM,YAAa,CAAA,MAAA,EAAQ,IAAI,CAAA,CAAA;AAAA,GACzC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,aAAa,GAAU,EAAA;AAE7B,IAAQ,OAAA,CAAA,KAAA,CAAM,IAAI,OAAS,EAAA;AAAA,MACzB,GAAG,GAAI,CAAA,IAAA;AAAA,KACR,CAAA,CAAA;AAAA,GACH;AACF;;;;"}
package/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "@backstage-community/plugin-analytics-module-ga4",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "backstage": {
5
- "role": "frontend-plugin-module"
5
+ "role": "frontend-plugin-module",
6
+ "pluginId": "app",
7
+ "pluginPackage": "@backstage/plugin-app-backend"
6
8
  },
7
9
  "publishConfig": {
8
10
  "access": "public",
@@ -34,14 +36,14 @@
34
36
  },
35
37
  "dependencies": {
36
38
  "@backstage/config": "^1.2.0",
37
- "@backstage/core-components": "^0.14.4",
38
- "@backstage/core-plugin-api": "^1.9.2",
39
- "@backstage/frontend-plugin-api": "^0.6.4",
39
+ "@backstage/core-components": "^0.14.9",
40
+ "@backstage/core-plugin-api": "^1.9.3",
41
+ "@backstage/frontend-plugin-api": "^0.6.7",
40
42
  "react-ga4": "^2.0.0"
41
43
  },
42
44
  "devDependencies": {
43
- "@backstage/cli": "^0.26.3",
44
- "@backstage/dev-utils": "^1.0.31",
45
+ "@backstage/cli": "^0.26.11",
46
+ "@backstage/dev-utils": "^1.0.35",
45
47
  "@testing-library/dom": "^10.0.0",
46
48
  "@testing-library/jest-dom": "^6.0.0",
47
49
  "@testing-library/react": "^15.0.0",