@backstage-community/plugin-analytics-module-ga4 0.2.5

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 ADDED
@@ -0,0 +1,540 @@
1
+ # @backstage-community/plugin-analytics-module-ga4
2
+
3
+ ## 0.2.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 193a2a3: Migrated from the [backstage/backstage](https://github.com/backstage/backstage) monorepo.
8
+
9
+ ## 0.2.4
10
+
11
+ ### Patch Changes
12
+
13
+ - abfbcfc: Updated dependency `@testing-library/react` to `^15.0.0`.
14
+ - cb1e3b0: Updated dependency `@testing-library/dom` to `^10.0.0`.
15
+ - Updated dependencies
16
+ - @backstage/core-components@0.14.4
17
+ - @backstage/core-plugin-api@1.9.2
18
+ - @backstage/frontend-plugin-api@0.6.4
19
+ - @backstage/config@1.2.0
20
+
21
+ ## 0.2.4-next.1
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies
26
+ - @backstage/frontend-plugin-api@0.6.4-next.1
27
+ - @backstage/config@1.2.0
28
+ - @backstage/core-components@0.14.4-next.0
29
+ - @backstage/core-plugin-api@1.9.1
30
+
31
+ ## 0.2.4-next.0
32
+
33
+ ### Patch Changes
34
+
35
+ - Updated dependencies
36
+ - @backstage/core-components@0.14.4-next.0
37
+ - @backstage/config@1.2.0
38
+ - @backstage/core-plugin-api@1.9.1
39
+ - @backstage/frontend-plugin-api@0.6.4-next.0
40
+
41
+ ## 0.2.3
42
+
43
+ ### Patch Changes
44
+
45
+ - Updated dependencies
46
+ - @backstage/core-components@0.14.3
47
+ - @backstage/frontend-plugin-api@0.6.3
48
+ - @backstage/core-plugin-api@1.9.1
49
+ - @backstage/config@1.2.0
50
+
51
+ ## 0.2.2
52
+
53
+ ### Patch Changes
54
+
55
+ - Updated dependencies
56
+ - @backstage/core-components@0.14.2
57
+ - @backstage/frontend-plugin-api@0.6.2
58
+ - @backstage/core-plugin-api@1.9.1
59
+ - @backstage/config@1.2.0
60
+
61
+ ## 0.2.1
62
+
63
+ ### Patch Changes
64
+
65
+ - Updated dependencies
66
+ - @backstage/config@1.2.0
67
+ - @backstage/core-components@0.14.1
68
+ - @backstage/core-plugin-api@1.9.1
69
+ - @backstage/frontend-plugin-api@0.6.1
70
+
71
+ ## 0.2.1-next.2
72
+
73
+ ### Patch Changes
74
+
75
+ - Updated dependencies
76
+ - @backstage/core-components@0.14.1-next.2
77
+ - @backstage/frontend-plugin-api@0.6.1-next.2
78
+ - @backstage/config@1.2.0-next.1
79
+ - @backstage/core-plugin-api@1.9.1-next.1
80
+
81
+ ## 0.2.1-next.1
82
+
83
+ ### Patch Changes
84
+
85
+ - Updated dependencies
86
+ - @backstage/config@1.2.0-next.1
87
+ - @backstage/core-components@0.14.1-next.1
88
+ - @backstage/core-plugin-api@1.9.1-next.1
89
+ - @backstage/frontend-plugin-api@0.6.1-next.1
90
+
91
+ ## 0.2.1-next.0
92
+
93
+ ### Patch Changes
94
+
95
+ - Updated dependencies
96
+ - @backstage/core-components@0.14.1-next.0
97
+ - @backstage/config@1.1.2-next.0
98
+ - @backstage/core-plugin-api@1.9.1-next.0
99
+ - @backstage/frontend-plugin-api@0.6.1-next.0
100
+
101
+ ## 0.2.0
102
+
103
+ ### Minor Changes
104
+
105
+ - e586f79: Add support to the new analytics api.
106
+
107
+ ### Patch Changes
108
+
109
+ - 9aac2b0: Use `--cwd` as the first `yarn` argument
110
+ - 8472188: Added or fixed the `repository` field in `package.json`.
111
+ - Updated dependencies
112
+ - @backstage/frontend-plugin-api@0.6.0
113
+ - @backstage/core-components@0.14.0
114
+ - @backstage/core-plugin-api@1.9.0
115
+ - @backstage/config@1.1.1
116
+
117
+ ## 0.2.0-next.2
118
+
119
+ ### Patch Changes
120
+
121
+ - 8472188: Added or fixed the `repository` field in `package.json`.
122
+ - Updated dependencies
123
+ - @backstage/core-components@0.14.0-next.2
124
+ - @backstage/config@1.1.1
125
+ - @backstage/core-plugin-api@1.9.0-next.1
126
+ - @backstage/frontend-plugin-api@0.6.0-next.3
127
+
128
+ ## 0.2.0-next.1
129
+
130
+ ### Patch Changes
131
+
132
+ - 9aac2b0: Use `--cwd` as the first `yarn` argument
133
+ - Updated dependencies
134
+ - @backstage/core-components@0.14.0-next.1
135
+ - @backstage/core-plugin-api@1.9.0-next.1
136
+ - @backstage/frontend-plugin-api@0.6.0-next.2
137
+ - @backstage/config@1.1.1
138
+
139
+ ## 0.2.0-next.0
140
+
141
+ ### Minor Changes
142
+
143
+ - e586f79: Add support to the new analytics api.
144
+
145
+ ### Patch Changes
146
+
147
+ - Updated dependencies
148
+ - @backstage/frontend-plugin-api@0.6.0-next.1
149
+ - @backstage/core-components@0.14.0-next.0
150
+ - @backstage/core-plugin-api@1.8.3-next.0
151
+ - @backstage/config@1.1.1
152
+
153
+ ## 0.1.8
154
+
155
+ ### Patch Changes
156
+
157
+ - 4016f21: Remove some unused dependencies
158
+ - Updated dependencies
159
+ - @backstage/core-components@0.13.10
160
+ - @backstage/core-plugin-api@1.8.2
161
+ - @backstage/config@1.1.1
162
+
163
+ ## 0.1.8-next.1
164
+
165
+ ### Patch Changes
166
+
167
+ - Updated dependencies
168
+ - @backstage/core-plugin-api@1.8.2-next.0
169
+ - @backstage/core-components@0.13.10-next.1
170
+ - @backstage/config@1.1.1
171
+
172
+ ## 0.1.8-next.0
173
+
174
+ ### Patch Changes
175
+
176
+ - 4016f21: Remove some unused dependencies
177
+ - Updated dependencies
178
+ - @backstage/core-components@0.13.10-next.0
179
+ - @backstage/config@1.1.1
180
+ - @backstage/core-plugin-api@1.8.1
181
+
182
+ ## 0.1.7
183
+
184
+ ### Patch Changes
185
+
186
+ - af6f227: Disabled `send_page_view` to get rid of events duplication
187
+ - Updated dependencies
188
+ - @backstage/core-plugin-api@1.8.1
189
+ - @backstage/core-components@0.13.9
190
+ - @backstage/theme@0.5.0
191
+ - @backstage/config@1.1.1
192
+
193
+ ## 0.1.7-next.3
194
+
195
+ ### Patch Changes
196
+
197
+ - Updated dependencies
198
+ - @backstage/core-components@0.13.9-next.3
199
+ - @backstage/config@1.1.1
200
+ - @backstage/core-plugin-api@1.8.1-next.1
201
+ - @backstage/theme@0.5.0-next.1
202
+
203
+ ## 0.1.7-next.2
204
+
205
+ ### Patch Changes
206
+
207
+ - Updated dependencies
208
+ - @backstage/theme@0.5.0-next.1
209
+ - @backstage/config@1.1.1
210
+ - @backstage/core-components@0.13.9-next.2
211
+ - @backstage/core-plugin-api@1.8.1-next.1
212
+
213
+ ## 0.1.7-next.1
214
+
215
+ ### Patch Changes
216
+
217
+ - Updated dependencies
218
+ - @backstage/core-components@0.13.9-next.1
219
+ - @backstage/core-plugin-api@1.8.1-next.1
220
+ - @backstage/config@1.1.1
221
+ - @backstage/theme@0.5.0-next.0
222
+
223
+ ## 0.1.7-next.0
224
+
225
+ ### Patch Changes
226
+
227
+ - Updated dependencies
228
+ - @backstage/core-plugin-api@1.8.1-next.0
229
+ - @backstage/core-components@0.13.9-next.0
230
+ - @backstage/theme@0.5.0-next.0
231
+ - @backstage/config@1.1.1
232
+
233
+ ## 0.1.6
234
+
235
+ ### Patch Changes
236
+
237
+ - 6c2b872153: Add official support for React 18.
238
+ - 504614d313: Updated dependency `@types/jest` to `^29.0.0`.
239
+ - Updated dependencies
240
+ - @backstage/core-components@0.13.8
241
+ - @backstage/core-plugin-api@1.8.0
242
+ - @backstage/theme@0.4.4
243
+ - @backstage/config@1.1.1
244
+
245
+ ## 0.1.6-next.2
246
+
247
+ ### Patch Changes
248
+
249
+ - Updated dependencies
250
+ - @backstage/core-components@0.13.8-next.2
251
+
252
+ ## 0.1.6-next.1
253
+
254
+ ### Patch Changes
255
+
256
+ - Updated dependencies
257
+ - @backstage/core-components@0.13.8-next.1
258
+ - @backstage/config@1.1.1
259
+ - @backstage/core-plugin-api@1.8.0-next.0
260
+ - @backstage/theme@0.4.4-next.0
261
+
262
+ ## 0.1.6-next.0
263
+
264
+ ### Patch Changes
265
+
266
+ - 6c2b872153: Add official support for React 18.
267
+ - Updated dependencies
268
+ - @backstage/core-components@0.13.7-next.0
269
+ - @backstage/core-plugin-api@1.8.0-next.0
270
+ - @backstage/theme@0.4.4-next.0
271
+ - @backstage/config@1.1.1
272
+
273
+ ## 0.1.5
274
+
275
+ ### Patch Changes
276
+
277
+ - 9a1fce352e: Updated dependency `@testing-library/jest-dom` to `^6.0.0`.
278
+ - f95af4e540: Updated dependency `@testing-library/dom` to `^9.0.0`.
279
+ - Updated dependencies
280
+ - @backstage/core-plugin-api@1.7.0
281
+ - @backstage/core-components@0.13.6
282
+ - @backstage/theme@0.4.3
283
+ - @backstage/config@1.1.1
284
+
285
+ ## 0.1.5-next.2
286
+
287
+ ### Patch Changes
288
+
289
+ - Updated dependencies
290
+ - @backstage/core-components@0.13.6-next.2
291
+ - @backstage/core-plugin-api@1.7.0-next.1
292
+ - @backstage/theme@0.4.3-next.0
293
+ - @backstage/config@1.1.1-next.0
294
+
295
+ ## 0.1.5-next.1
296
+
297
+ ### Patch Changes
298
+
299
+ - Updated dependencies
300
+ - @backstage/core-components@0.13.6-next.1
301
+ - @backstage/core-plugin-api@1.7.0-next.0
302
+ - @backstage/config@1.1.0
303
+ - @backstage/theme@0.4.2
304
+
305
+ ## 0.1.5-next.0
306
+
307
+ ### Patch Changes
308
+
309
+ - Updated dependencies
310
+ - @backstage/core-plugin-api@1.7.0-next.0
311
+ - @backstage/core-components@0.13.6-next.0
312
+ - @backstage/config@1.1.0
313
+ - @backstage/theme@0.4.2
314
+
315
+ ## 0.1.4
316
+
317
+ ### Patch Changes
318
+
319
+ - 406b786a2a2c: Mark package as being free of side effects, allowing more optimized Webpack builds.
320
+ - 8cec7664e146: Removed `@types/node` dependency
321
+ - Updated dependencies
322
+ - @backstage/core-components@0.13.5
323
+ - @backstage/config@1.1.0
324
+ - @backstage/core-plugin-api@1.6.0
325
+ - @backstage/theme@0.4.2
326
+
327
+ ## 0.1.4-next.3
328
+
329
+ ### Patch Changes
330
+
331
+ - 406b786a2a2c: Mark package as being free of side effects, allowing more optimized Webpack builds.
332
+ - Updated dependencies
333
+ - @backstage/config@1.1.0-next.2
334
+ - @backstage/core-components@0.13.5-next.3
335
+ - @backstage/core-plugin-api@1.6.0-next.3
336
+ - @backstage/theme@0.4.2-next.0
337
+
338
+ ## 0.1.4-next.2
339
+
340
+ ### Patch Changes
341
+
342
+ - 8cec7664e146: Removed `@types/node` dependency
343
+ - Updated dependencies
344
+ - @backstage/core-components@0.13.5-next.2
345
+ - @backstage/core-plugin-api@1.6.0-next.2
346
+ - @backstage/config@1.1.0-next.1
347
+ - @backstage/theme@0.4.1
348
+
349
+ ## 0.1.4-next.1
350
+
351
+ ### Patch Changes
352
+
353
+ - Updated dependencies
354
+ - @backstage/core-components@0.13.5-next.1
355
+ - @backstage/config@1.1.0-next.0
356
+ - @backstage/core-plugin-api@1.6.0-next.1
357
+ - @backstage/theme@0.4.1
358
+
359
+ ## 0.1.4-next.0
360
+
361
+ ### Patch Changes
362
+
363
+ - Updated dependencies
364
+ - @backstage/core-plugin-api@1.6.0-next.0
365
+ - @backstage/core-components@0.13.5-next.0
366
+ - @backstage/config@1.0.8
367
+ - @backstage/theme@0.4.1
368
+
369
+ ## 0.1.3
370
+
371
+ ### Patch Changes
372
+
373
+ - 12a8c94eda8d: Add package repository and homepage metadata
374
+ - Updated dependencies
375
+ - @backstage/core-components@0.13.4
376
+ - @backstage/core-plugin-api@1.5.3
377
+ - @backstage/config@1.0.8
378
+ - @backstage/theme@0.4.1
379
+
380
+ ## 0.1.3-next.1
381
+
382
+ ### Patch Changes
383
+
384
+ - 12a8c94eda8d: Add package repository and homepage metadata
385
+ - Updated dependencies
386
+ - @backstage/config@1.0.8
387
+ - @backstage/core-components@0.13.4-next.0
388
+ - @backstage/core-plugin-api@1.5.3
389
+ - @backstage/theme@0.4.1
390
+
391
+ ## 0.1.3-next.0
392
+
393
+ ### Patch Changes
394
+
395
+ - Updated dependencies
396
+ - @backstage/core-components@0.13.4-next.0
397
+ - @backstage/core-plugin-api@1.5.3
398
+ - @backstage/config@1.0.8
399
+ - @backstage/theme@0.4.1
400
+
401
+ ## 0.1.2
402
+
403
+ ### Patch Changes
404
+
405
+ - Updated dependencies
406
+ - @backstage/theme@0.4.1
407
+ - @backstage/core-components@0.13.3
408
+ - @backstage/core-plugin-api@1.5.3
409
+ - @backstage/config@1.0.8
410
+
411
+ ## 0.1.2-next.2
412
+
413
+ ### Patch Changes
414
+
415
+ - Updated dependencies
416
+ - @backstage/theme@0.4.1-next.1
417
+ - @backstage/core-plugin-api@1.5.3-next.1
418
+ - @backstage/core-components@0.13.3-next.2
419
+ - @backstage/config@1.0.8
420
+
421
+ ## 0.1.2-next.1
422
+
423
+ ### Patch Changes
424
+
425
+ - Updated dependencies
426
+ - @backstage/theme@0.4.1-next.0
427
+ - @backstage/core-components@0.13.3-next.1
428
+ - @backstage/core-plugin-api@1.5.3-next.0
429
+ - @backstage/config@1.0.8
430
+
431
+ ## 0.1.2-next.0
432
+
433
+ ### Patch Changes
434
+
435
+ - Updated dependencies
436
+ - @backstage/core-components@0.13.3-next.0
437
+ - @backstage/config@1.0.8
438
+ - @backstage/core-plugin-api@1.5.2
439
+ - @backstage/theme@0.4.0
440
+
441
+ ## 0.1.1
442
+
443
+ ### Patch Changes
444
+
445
+ - 99056db6169e: Fixed configuration visibility settings for `allowedContexts` and `allowedAttributes`
446
+ - 3d11596a72b5: Update plugin installation docs to be more consistent across documentations
447
+ - Updated dependencies
448
+ - @backstage/core-plugin-api@1.5.2
449
+ - @backstage/core-components@0.13.2
450
+ - @backstage/theme@0.4.0
451
+ - @backstage/config@1.0.8
452
+
453
+ ## 0.1.1-next.3
454
+
455
+ ### Patch Changes
456
+
457
+ - Updated dependencies
458
+ - @backstage/core-components@0.13.2-next.3
459
+ - @backstage/config@1.0.7
460
+ - @backstage/core-plugin-api@1.5.2-next.0
461
+ - @backstage/theme@0.4.0-next.1
462
+
463
+ ## 0.1.1-next.2
464
+
465
+ ### Patch Changes
466
+
467
+ - Updated dependencies
468
+ - @backstage/theme@0.4.0-next.1
469
+ - @backstage/core-components@0.13.2-next.2
470
+ - @backstage/config@1.0.7
471
+ - @backstage/core-plugin-api@1.5.2-next.0
472
+
473
+ ## 0.1.1-next.1
474
+
475
+ ### Patch Changes
476
+
477
+ - 99056db6169e: Fixed configuration visibility settings for `allowedContexts` and `allowedAttributes`
478
+ - Updated dependencies
479
+ - @backstage/core-components@0.13.2-next.1
480
+ - @backstage/core-plugin-api@1.5.2-next.0
481
+ - @backstage/config@1.0.7
482
+ - @backstage/theme@0.4.0-next.0
483
+
484
+ ## 0.1.1-next.0
485
+
486
+ ### Patch Changes
487
+
488
+ - 3d11596a72b5: Update plugin installation docs to be more consistent across documentations
489
+ - Updated dependencies
490
+ - @backstage/theme@0.4.0-next.0
491
+ - @backstage/config@1.0.7
492
+ - @backstage/core-components@0.13.2-next.0
493
+ - @backstage/core-plugin-api@1.5.1
494
+
495
+ ## 0.1.0
496
+
497
+ ### Minor Changes
498
+
499
+ - 22b46f7f562: Plugin provides Backstage Analytics API for Google Analytics 4. Once installed and configured, analytics events will be sent to GA4 as your users navigate and use your Backstage instance
500
+
501
+ ### Patch Changes
502
+
503
+ - Updated dependencies
504
+ - @backstage/theme@0.3.0
505
+ - @backstage/core-components@0.13.1
506
+ - @backstage/config@1.0.7
507
+ - @backstage/core-plugin-api@1.5.1
508
+
509
+ ## 0.1.0-next.2
510
+
511
+ ### Patch Changes
512
+
513
+ - Updated dependencies
514
+ - @backstage/theme@0.3.0-next.0
515
+ - @backstage/core-components@0.13.1-next.1
516
+ - @backstage/config@1.0.7
517
+ - @backstage/core-plugin-api@1.5.1
518
+
519
+ ## 0.1.0-next.1
520
+
521
+ ### Patch Changes
522
+
523
+ - Updated dependencies
524
+ - @backstage/core-components@0.13.1-next.0
525
+ - @backstage/core-plugin-api@1.5.1
526
+ - @backstage/config@1.0.7
527
+
528
+ ## 0.1.0-next.0
529
+
530
+ ### Minor Changes
531
+
532
+ - 22b46f7f562: Plugin provides Backstage Analytics API for Google Analytics 4. Once installed and configured, analytics events will be sent to GA4 as your users navigate and use your Backstage instance
533
+
534
+ ### Patch Changes
535
+
536
+ - Updated dependencies
537
+ - @backstage/core-components@0.13.0
538
+ - @backstage/core-plugin-api@1.5.1
539
+ - @backstage/config@1.0.7
540
+ - @backstage/theme@0.2.19
package/README.md ADDED
@@ -0,0 +1,233 @@
1
+ # Analytics Module: Google Analytics 4
2
+
3
+ This plugin provides an opinionated implementation of the Backstage Analytics
4
+ API for Google Analytics 4. Once installed and configured, analytics events will
5
+ be sent to GA as your users navigate and use your Backstage instance.
6
+
7
+ This plugin contains no other functionality.
8
+
9
+ ## Installation
10
+
11
+ 1. Install the plugin package in your Backstage app:
12
+
13
+ ```sh
14
+ # From your Backstage root directory
15
+ yarn --cwd packages/app add @backstage-community/plugin-analytics-module-ga4
16
+ ```
17
+
18
+ 2. Wire up the API implementation to your App:
19
+
20
+ ```tsx
21
+ // packages/app/src/apis.ts
22
+ import {
23
+ analyticsApiRef,
24
+ configApiRef,
25
+ identityApiRef,
26
+ } from '@backstage/core-plugin-api';
27
+ import { GoogleAnalytics4 } from '@backstage-community/plugin-analytics-module-ga4';
28
+
29
+ export const apis: AnyApiFactory[] = [
30
+ // Instantiate and register the GA Analytics API Implementation.
31
+ createApiFactory({
32
+ api: analyticsApiRef,
33
+ deps: { configApi: configApiRef, identityApi: identityApiRef },
34
+ factory: ({ configApi, identityApi }) =>
35
+ GoogleAnalytics4.fromConfig(configApi, {
36
+ identityApi,
37
+ }),
38
+ }),
39
+ ];
40
+ ```
41
+
42
+ 3. Configure the plugin in your `app-config.yaml`:
43
+
44
+ The following is the minimum configuration required to start sending analytics
45
+ events to GA. All that's needed is your GA4 measurement ID:
46
+
47
+ ```yaml
48
+ # app-config.yaml
49
+ app:
50
+ analytics:
51
+ ga4:
52
+ measurementId: G-0000000-0
53
+ ```
54
+
55
+ 4. Update CSP in your `app-config.yaml`:
56
+
57
+ The following is the minimal content security policy required to load scripts from GA.
58
+
59
+ ```yaml
60
+ backend:
61
+ csp:
62
+ connect-src: ["'self'", 'http:', 'https:']
63
+ # Add these two lines below
64
+ script-src:
65
+ [
66
+ "'self'",
67
+ "'unsafe-eval'",
68
+ 'https://www.google-analytics.com',
69
+ 'https://www.googletagmanager.com',
70
+ ]
71
+ img-src: ["'self'", 'data:', 'https://www.google-analytics.com']
72
+ ```
73
+
74
+ ## Configuration
75
+
76
+ In order to be able to analyze usage of your Backstage instance by plugin, we recommend configuring [a content grouping](#enabling-content-grouping).
77
+ Additional dimensional data can be captured using custom dimensions, like this:
78
+
79
+ 1. First, [configure the custom dimension in GA] [configure-custom-dimension].
80
+ Be sure to set the Scope to `Event`, and name it `dimension1`.
81
+ 2. Then, add a mapping to your `app.analytics.ga4` configuration that instructs
82
+ the plugin to capture Plugin IDs on the custom dimension you just created.
83
+ It should look like this:
84
+ 3. `allowedContexts` config accepts array of string, where each entry is a context parameter that will be sent in the event.
85
+ context names will be prefixed by `c_`.
86
+ 4. `allowedAttributes` config accepts array of string, where each entry is an attribute that will be sent in the event.
87
+ attribute names will be prefixed by `a_`.
88
+ 5. `allowedContexts` and `allowedAttributes` are optional, if not provided, no additional context and attributes will be sent.
89
+ 6. if `allowedContexts` or `allowedAttributes` is set to '\*', all context and attributes will be sent.
90
+ 7. `enableSendPageView` is used to send default events and is disabled by default.
91
+
92
+ ```yaml
93
+ app:
94
+ analytics:
95
+ ga4:
96
+ measurementId: G-0000000-0
97
+ allowedContexts: ['pluginId']
98
+ ```
99
+
100
+ ```yaml
101
+ app:
102
+ analytics:
103
+ ga4:
104
+ allowedContexts: ['pluginId']
105
+ allowedAttributes: ['someEventContextAttr']
106
+ ```
107
+
108
+ ### User IDs
109
+
110
+ This plugin supports accurately deriving user-oriented metrics (like monthly
111
+ active users) using Google Analytics' [user ID views][ga-user-id-view]. To
112
+ enable this...
113
+
114
+ 1. Be sure you've gone through the process of setting up a user ID view in your
115
+ Backstage instance's Google Analytics property (see docs linked above).
116
+ 2. Make sure you instantiate `GoogleAnalytics` with an `identityApi` instance
117
+ passed to it, as shown in the installation section above.
118
+ 3. Set `app.analytics.ga4.identity` to either `required` or `optional` in your
119
+ `app.config.yaml`, like this:
120
+
121
+ ```yaml
122
+ app:
123
+ analytics:
124
+ ga4:
125
+ measurementId: G-0000000-0
126
+ identity: optional
127
+ ```
128
+
129
+ Set `identity` to `optional` if you need accurate session counts, including
130
+ cases where users do not sign in at all. Use `required` if you need all hits
131
+ to be associated with a user ID without exception (and don't mind if some
132
+ sessions are not captured, such as those where no sign in occur).
133
+
134
+ Note that, to comply with GA policies, the value of the User ID is
135
+ pseudonymized before being sent to GA. By default, it is a `sha256` hash of the
136
+ current user's `userEntityRef` as returned by the `identityApi`. To set a
137
+ different value, provide a `userIdTransform` function alongside `identityApi`
138
+ when you instantiate `GoogleAnalytics`. This function will be passed the
139
+ `userEntityRef` as an argument and should resolve to the value you wish to set
140
+ as the user ID. For example:
141
+
142
+ ```typescript
143
+ import {
144
+ analyticsApiRef,
145
+ configApiRef,
146
+ identityApiRef,
147
+ } from '@backstage/core-plugin-api';
148
+ import { GoogleAnalytics } from '@backstage-community/plugin-analytics-module-ga';
149
+
150
+ export const apis: AnyApiFactory[] = [
151
+ createApiFactory({
152
+ api: analyticsApiRef,
153
+ deps: { configApi: configApiRef, identityApi: identityApiRef },
154
+ factory: ({ configApi, identityApi }) =>
155
+ GoogleAnalytics4.fromConfig(configApi, {
156
+ identityApi,
157
+ userIdTransform: async (userEntityRef: string): Promise<string> => {
158
+ return customHashingFunction(userEntityRef);
159
+ },
160
+ }),
161
+ }),
162
+ ];
163
+ ```
164
+
165
+ ### Enabling content grouping
166
+
167
+ Content groups enable you to categorize pages and screens into custom buckets which you can see
168
+ metrics for related groups of information.
169
+ More about content grouping here [content groups][content-grouping].
170
+ It's recommended to enable content grouping by PluginId. `contentGrouping` supports `routeRef` and extension.
171
+
172
+ ```yaml
173
+ app:
174
+ analytics:
175
+ ga4:
176
+ contentGrouping: pluginId
177
+ ```
178
+
179
+ Please note, content grouping takes 24hrs to show up in the Google Analytics dashboard.
180
+
181
+ ### Debugging and Testing
182
+
183
+ In pre-production environments, you may wish to set additional configurations
184
+ to turn off reporting to Analytics and/or print debug statements to the
185
+ console. You can do so like this:
186
+
187
+ ```yaml
188
+ app:
189
+ analytics:
190
+ ga4:
191
+ testMode: true # Prevents data being sent to GA
192
+ debug: true # Logs analytics event to the web console
193
+ ```
194
+
195
+ You might commonly set the above in an `app-config.local.yaml` file, which is
196
+ normally `gitignore`'d but loaded and merged in when Backstage is bootstrapped.
197
+
198
+ ## Development
199
+
200
+ If you would like to contribute improvements to this plugin, the easiest way to
201
+ make and test changes is to do the following:
202
+
203
+ 1. Clone the main Backstage monorepo `git clone git@github.com:backstage/backstage.git`
204
+ 2. Install all dependencies `yarn install`
205
+ 3. If one does not exist, create an `app-config.local.yaml` file in the root of
206
+ the monorepo and add config for this plugin (see below)
207
+ 4. Enter this plugin's working directory: `cd plugins/analytics-provider-ga4`
208
+ 5. Start the plugin in isolation: `yarn start`
209
+ 6. Navigate to the playground page at `http://localhost:3000/ga4`
210
+ 7. Open the web console to see events fire when you navigate or when you
211
+ interact with instrumented components.
212
+
213
+ Code for the isolated version of the plugin can be found inside the [/dev](./dev)
214
+ directory. Changes to the plugin are hot-reloaded.
215
+
216
+ #### Recommended Dev Config
217
+
218
+ Paste this into your `app-config.local.yaml` while developing this plugin:
219
+
220
+ ```yaml
221
+ app:
222
+ analytics:
223
+ ga4:
224
+ measurementId: G-0000000-0
225
+ debug: true
226
+ testMode: true
227
+ allowedContexts: ['pluginId']
228
+ ```
229
+
230
+ [what-is-a-custom-dimension]: https://support.google.com/analytics/answer/2709828
231
+ [configure-custom-dimension]: https://support.google.com/analytics/answer/10075209?hl=en#
232
+ [ga-user-id-view]: https://support.google.com/analytics/answer/3123669
233
+ [content-grouping]: https://support.google.com/analytics/answer/11523339?hl=en
package/config.d.ts ADDED
@@ -0,0 +1,104 @@
1
+ /*
2
+ * Copyright 2020 The Backstage Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ export interface Config {
18
+ app: {
19
+ // TODO: Only marked as optional because backstage-cli config:check in the
20
+ // context of the monorepo is too strict. Ideally, this would be marked as
21
+ // required.
22
+ analytics?: {
23
+ ga4: {
24
+ /**
25
+ * Google Analytics measurement ID, e.g. G-000000-0
26
+ * @visibility frontend
27
+ */
28
+ measurementId: string;
29
+
30
+ /**
31
+ * Controls how the identityApi is used when sending data to GA:
32
+ *
33
+ * - `disabled`: (Default) Explicitly prevents a user's identity from
34
+ * being used when capturing events in GA.
35
+ * - `optional`: Pageviews and hits are forwarded to GA as they happen
36
+ * and only include user identity metadata once known. Guarantees
37
+ * that hits are captured for all sessions, even if no sign in
38
+ * occurs, but may result in dropped hits in User ID views.
39
+ * - `required`: All pageviews and hits are deferred until an identity
40
+ * is known. Guarantees that all data sent to GA correlates to a user
41
+ * identity, but prevents GA from receiving events for sessions in
42
+ * which a user does not sign in. An `identityApi` instance must be
43
+ * passed during instantiation when set to this value.
44
+ *
45
+ * @visibility frontend
46
+ */
47
+ identity?: 'disabled' | 'optional' | 'required';
48
+
49
+ /**
50
+ * Whether to log analytics debug statements to the console.
51
+ * Defaults to false.
52
+ *
53
+ * @visibility frontend
54
+ */
55
+ debug?: boolean;
56
+
57
+ /**
58
+ * Whether to send default send_page_view event.
59
+ * Defaults to false.
60
+ *
61
+ * @visibility frontend
62
+ */
63
+ enableSendPageView?: boolean;
64
+
65
+ /**
66
+ * Prevents events from actually being sent when set to true. Defaults
67
+ * to false.
68
+ *
69
+ * @visibility frontend
70
+ */
71
+ testMode?: boolean;
72
+
73
+ /**
74
+ * Content grouping definition
75
+ * Feature available in Google Analytics 4
76
+ * More information https://support.google.com/analytics/answer/11523339?hl=en
77
+ * Data can be grouped by pluginId, routeRef
78
+ * Takes 24 hours before metrics shows up in GA dashboard
79
+ * Specifies the dimension to be used for content grouping
80
+ * Can be one of pluginId, extension or routeRef
81
+ * @visibility frontend
82
+ *
83
+ */
84
+ contentGrouping?: 'pluginId' | 'extension' | 'routeRef';
85
+
86
+ /**
87
+ * Configuration informing how Analytics Context and Event Attributes
88
+ * metadata will be captured in Google Analytics.
89
+ * Contexts that will be sent as parameters in the event.
90
+ * context-name will be prefixed by c_, for example, pluginId will be c_pluginId in the event.
91
+ * @visibility frontend
92
+ */
93
+ allowedContexts?: string[] | ['*'];
94
+ /**
95
+ *
96
+ * Attributes that will be sent as parameters in the event
97
+ * attribute-name will be prefixed by a_, for example , testAttribute will be c_testAttribute in the event.
98
+ * @visibility frontend
99
+ */
100
+ allowedAttributes?: string[] | ['*'];
101
+ };
102
+ };
103
+ };
104
+ }
@@ -0,0 +1,75 @@
1
+ import { AnalyticsApi, IdentityApi, AnalyticsEvent } from '@backstage/core-plugin-api';
2
+ import { AnalyticsApi as AnalyticsApi$1, AnalyticsEvent as AnalyticsEvent$1 } from '@backstage/frontend-plugin-api';
3
+ import { Config } from '@backstage/config';
4
+
5
+ /**
6
+ * Google Analytics API provider for the Backstage Analytics API.
7
+ * @public
8
+ */
9
+ declare class GoogleAnalytics4 implements AnalyticsApi, AnalyticsApi$1 {
10
+ private readonly customUserIdTransform?;
11
+ private readonly capture;
12
+ private readonly contentGroupBy?;
13
+ private readonly allowedContexts?;
14
+ private readonly allowedAttributes?;
15
+ /**
16
+ * Instantiate the implementation and initialize ReactGA.
17
+ * @param options initializes Google Analytics module with the config
18
+ */
19
+ private constructor();
20
+ /**
21
+ * Instantiate a fully configured GA Analytics API implementation.
22
+ * @param config - Config object from app config
23
+ * @param options - options with identityApi and userIdTransform config
24
+ */
25
+ static fromConfig(config: Config, options?: {
26
+ identityApi?: IdentityApi;
27
+ userIdTransform?: 'sha-256' | ((userEntityRef: string) => Promise<string>);
28
+ }): GoogleAnalytics4;
29
+ /**
30
+ * Primary event capture implementation. Handles core navigate event as a
31
+ * pageview and the rest as custom events. All custom dimensions/metrics are
32
+ * applied as they should be (set on pageview, merged object on events).
33
+ * @param event - AnalyticsEvent type captured
34
+ */
35
+ captureEvent(event: AnalyticsEvent | AnalyticsEvent$1): void;
36
+ /**
37
+ * Returns an object of dimensions/metrics given an Analytics Context and an
38
+ * Event Attributes, e.g. { c_pluginId: "some value", a_attribute1: 42 }
39
+ * @param context analytics context object
40
+ * @param attributes additional analytics event attributes
41
+ */
42
+ private setEventParameters;
43
+ /**
44
+ * Sets the GA userId, based on the `userEntityRef` set on the backstage
45
+ * identity loaded from a given Backstage Identity API instance. Because
46
+ * Google forbids sending any PII (including on the userId field), we hash
47
+ * the entire `userEntityRef` on behalf of integrators:
48
+ *
49
+ * - With value `User:default/name`, userId becomes `sha256(User:default/name)`
50
+ *
51
+ * If an integrator wishes to use an alternative hashing mechanism or an
52
+ * entirely different value, they may do so by passing a `userIdTransform`
53
+ * function alongside the `identityApi` to `GoogleAnalytics.fromConfig()`.
54
+ * This function receives the `userEntityRef` as an argument and should
55
+ * resolve to a hashed version of whatever identifier they choose.
56
+ *
57
+ * Note: this feature requires that an integrator has set up a Google
58
+ * Analytics User ID view in the property used to track Backstage.
59
+ * @param identityApi IdentityApi object
60
+ */
61
+ private setUserFrom;
62
+ /**
63
+ * Returns a PII-free (according to Google's terms of service) user ID for
64
+ * use in Google Analytics.
65
+ * @param userEntityRef user entity as string
66
+ */
67
+ private getPrivateUserId;
68
+ /**
69
+ * Simple hash function; relies on web cryptography + the sha-256 algorithm.
70
+ * @param value value to be hashed
71
+ */
72
+ private hash;
73
+ }
74
+
75
+ export { GoogleAnalytics4 };
@@ -0,0 +1,267 @@
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]) {
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]) {
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 };
267
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +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]) {\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]) {\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;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,C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AAA;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;;;;"}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@backstage-community/plugin-analytics-module-ga4",
3
+ "version": "0.2.5",
4
+ "backstage": {
5
+ "role": "frontend-plugin-module"
6
+ },
7
+ "publishConfig": {
8
+ "access": "public",
9
+ "main": "dist/index.esm.js",
10
+ "types": "dist/index.d.ts"
11
+ },
12
+ "homepage": "https://backstage.io",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/backstage/community-plugins",
16
+ "directory": "workspaces/analytics/plugins/analytics-module-ga4"
17
+ },
18
+ "license": "Apache-2.0",
19
+ "sideEffects": false,
20
+ "main": "dist/index.esm.js",
21
+ "types": "dist/index.d.ts",
22
+ "files": [
23
+ "dist",
24
+ "config.d.ts"
25
+ ],
26
+ "scripts": {
27
+ "build": "backstage-cli package build",
28
+ "clean": "backstage-cli package clean",
29
+ "lint": "backstage-cli package lint",
30
+ "prepack": "backstage-cli package prepack",
31
+ "postpack": "backstage-cli package postpack",
32
+ "start": "backstage-cli package start",
33
+ "test": "backstage-cli package test"
34
+ },
35
+ "dependencies": {
36
+ "@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",
40
+ "react-ga4": "^2.0.0"
41
+ },
42
+ "devDependencies": {
43
+ "@backstage/cli": "^0.26.3",
44
+ "@backstage/dev-utils": "^1.0.31",
45
+ "@testing-library/dom": "^10.0.0",
46
+ "@testing-library/jest-dom": "^6.0.0",
47
+ "@testing-library/react": "^15.0.0",
48
+ "@types/jest": "^29.0.0",
49
+ "@types/react": "^16.13.1 || ^17.0.0",
50
+ "@types/react-dom": "^18.2.19",
51
+ "canvas": "^2.11.2",
52
+ "react": "^16.13.1 || ^17.0.0 || ^18.0.0",
53
+ "react-dom": "^16.13.1 || ^17.0.0 || ^18.0.0",
54
+ "react-router-dom": "6.0.0-beta.0 || ^6.3.0"
55
+ },
56
+ "peerDependencies": {
57
+ "react": "^16.13.1 || ^17.0.0 || ^18.0.0",
58
+ "react-dom": "^16.13.1 || ^17.0.0 || ^18.0.0",
59
+ "react-router-dom": "6.0.0-beta.0 || ^6.3.0"
60
+ },
61
+ "configSchema": "config.d.ts",
62
+ "module": "./dist/index.esm.js"
63
+ }