@equinor/fusion-framework-module-analytics 1.0.3-next.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -8
- package/README.md +147 -130
- package/dist/esm/AnalyticsConfigurator.js +22 -17
- package/dist/esm/AnalyticsConfigurator.js.map +1 -1
- package/dist/esm/AnalyticsProvider.js +39 -18
- package/dist/esm/AnalyticsProvider.js.map +1 -1
- package/dist/esm/adapters/ConsoleAnalyticsAdapter.js +15 -1
- package/dist/esm/adapters/ConsoleAnalyticsAdapter.js.map +1 -1
- package/dist/esm/adapters/FusionAnalyticsAdapter.js +32 -3
- package/dist/esm/adapters/FusionAnalyticsAdapter.js.map +1 -1
- package/dist/esm/adapters/index.js.map +1 -1
- package/dist/esm/collectors/AppLoadedCollector.js +21 -5
- package/dist/esm/collectors/AppLoadedCollector.js.map +1 -1
- package/dist/esm/collectors/AppSelectedCollector.js +17 -5
- package/dist/esm/collectors/AppSelectedCollector.js.map +1 -1
- package/dist/esm/collectors/BaseCollector.js +48 -3
- package/dist/esm/collectors/BaseCollector.js.map +1 -1
- package/dist/esm/collectors/ContextSelectedCollector.js +20 -5
- package/dist/esm/collectors/ContextSelectedCollector.js.map +1 -1
- package/dist/esm/collectors/index.js.map +1 -1
- package/dist/esm/collectors/utils/extractAppMetadata.js +25 -4
- package/dist/esm/collectors/utils/extractAppMetadata.js.map +1 -1
- package/dist/esm/collectors/utils/extractContextMetadata.js +13 -2
- package/dist/esm/collectors/utils/extractContextMetadata.js.map +1 -1
- package/dist/esm/enable-analytics.js +18 -3
- package/dist/esm/enable-analytics.js.map +1 -1
- package/dist/esm/index.js +18 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/logExporters/fusionOTLPLogExporter/FusionOTLPLogExporter.js +26 -4
- package/dist/esm/logExporters/fusionOTLPLogExporter/FusionOTLPLogExporter.js.map +1 -1
- package/dist/esm/logExporters/fusionOTLPLogExporter/HttpClientExporterTransport.js +36 -7
- package/dist/esm/logExporters/fusionOTLPLogExporter/HttpClientExporterTransport.js.map +1 -1
- package/dist/esm/logExporters/index.js +8 -0
- package/dist/esm/logExporters/index.js.map +1 -1
- package/dist/esm/module.js +8 -8
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/AnalyticsConfigurator.d.ts +22 -17
- package/dist/types/AnalyticsConfigurator.interface.d.ts +41 -12
- package/dist/types/AnalyticsProvider.d.ts +32 -18
- package/dist/types/AnalyticsProvider.interface.d.ts +28 -6
- package/dist/types/adapters/AnalyticsAdapter.interface.d.ts +15 -2
- package/dist/types/adapters/ConsoleAnalyticsAdapter.d.ts +15 -1
- package/dist/types/adapters/FusionAnalyticsAdapter.d.ts +32 -3
- package/dist/types/adapters/index.d.ts +8 -0
- package/dist/types/collectors/AnalyticsCollector.interface.d.ts +11 -2
- package/dist/types/collectors/AppLoadedCollector.d.ts +20 -2
- package/dist/types/collectors/AppSelectedCollector.d.ts +16 -2
- package/dist/types/collectors/BaseCollector.d.ts +58 -3
- package/dist/types/collectors/ContextSelectedCollector.d.ts +19 -2
- package/dist/types/collectors/index.d.ts +8 -0
- package/dist/types/collectors/utils/extractAppMetadata.d.ts +27 -0
- package/dist/types/collectors/utils/extractContextMetadata.d.ts +14 -0
- package/dist/types/enable-analytics.d.ts +19 -3
- package/dist/types/index.d.ts +18 -0
- package/dist/types/logExporters/fusionOTLPLogExporter/FusionOTLPLogExporter.d.ts +21 -3
- package/dist/types/logExporters/fusionOTLPLogExporter/HttpClientExporterTransport.d.ts +24 -1
- package/dist/types/logExporters/index.d.ts +8 -0
- package/dist/types/module.d.ts +15 -15
- package/dist/types/types.d.ts +38 -7
- package/dist/types/version.d.ts +1 -1
- package/package.json +11 -11
- package/src/AnalyticsConfigurator.interface.ts +41 -12
- package/src/AnalyticsConfigurator.ts +22 -17
- package/src/AnalyticsProvider.interface.ts +28 -6
- package/src/AnalyticsProvider.ts +39 -18
- package/src/adapters/AnalyticsAdapter.interface.ts +15 -2
- package/src/adapters/ConsoleAnalyticsAdapter.ts +15 -1
- package/src/adapters/FusionAnalyticsAdapter.ts +32 -3
- package/src/adapters/index.ts +8 -0
- package/src/collectors/AnalyticsCollector.interface.ts +11 -2
- package/src/collectors/AppLoadedCollector.ts +21 -5
- package/src/collectors/AppSelectedCollector.ts +17 -5
- package/src/collectors/BaseCollector.ts +58 -3
- package/src/collectors/ContextSelectedCollector.ts +20 -5
- package/src/collectors/index.ts +8 -0
- package/src/collectors/utils/extractAppMetadata.ts +27 -4
- package/src/collectors/utils/extractContextMetadata.ts +14 -2
- package/src/enable-analytics.ts +19 -3
- package/src/index.ts +19 -0
- package/src/logExporters/fusionOTLPLogExporter/FusionOTLPLogExporter.ts +26 -4
- package/src/logExporters/fusionOTLPLogExporter/HttpClientExporterTransport.ts +36 -7
- package/src/logExporters/index.ts +8 -0
- package/src/module.ts +15 -15
- package/src/types.ts +39 -8
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,16 +1,38 @@
|
|
|
1
1
|
# @equinor/fusion-framework-module-analytics
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- abffa53: Major version bump for Fusion Framework React 19 release.
|
|
8
|
+
|
|
9
|
+
All packages are bumped to the next major version as part of the React 19 upgrade. This release drops support for React versions below 18 and includes breaking changes across the framework.
|
|
10
|
+
|
|
11
|
+
**Breaking changes:**
|
|
12
|
+
- Peer dependencies now require React 18 or 19 (`^18.0.0 || ^19.0.0`)
|
|
13
|
+
- React Router upgraded from v6 to v7
|
|
14
|
+
- Navigation module refactored with new history API
|
|
15
|
+
- `renderComponent` and `renderApp` now use `createRoot` API
|
|
16
|
+
|
|
17
|
+
**Migration:**
|
|
18
|
+
- Update your React version to 18.0.0 or higher before upgrading
|
|
19
|
+
- Replace `NavigationProvider.createRouter()` with `@equinor/fusion-framework-react-router`
|
|
20
|
+
- See individual package changelogs for package-specific migration steps
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
|
6
23
|
|
|
7
|
-
- Updated dependencies [
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- @equinor/fusion-framework-module@
|
|
24
|
+
- Updated dependencies [abffa53]
|
|
25
|
+
- Updated dependencies [abffa53]
|
|
26
|
+
- Updated dependencies [abffa53]
|
|
27
|
+
- Updated dependencies [abffa53]
|
|
28
|
+
- Updated dependencies [abffa53]
|
|
29
|
+
- Updated dependencies [abffa53]
|
|
30
|
+
- @equinor/fusion-framework-module@6.0.0
|
|
31
|
+
- @equinor/fusion-framework-module-app@8.0.0
|
|
32
|
+
- @equinor/fusion-framework-module-context@8.0.0
|
|
33
|
+
- @equinor/fusion-framework-module-event@6.0.0
|
|
34
|
+
- @equinor/fusion-framework-module-http@8.0.0
|
|
35
|
+
- @equinor/fusion-observable@9.0.0
|
|
14
36
|
|
|
15
37
|
## 1.0.2
|
|
16
38
|
|
package/README.md
CHANGED
|
@@ -1,202 +1,219 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @equinor/fusion-framework-module-analytics
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
adapters and collectors.
|
|
3
|
+
Fusion Framework module for collecting and exporting application analytics using
|
|
4
|
+
OpenTelemetry standards.
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
## Overview
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
The analytics module provides a pluggable **adapter/collector** architecture:
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
- **Collectors** observe application state (context changes, app selection,
|
|
11
|
+
app loads) and emit structured `AnalyticsEvent` objects.
|
|
12
|
+
- **Adapters** receive those events and forward them to a backend — the browser
|
|
13
|
+
console for debugging, or an OTLP-compatible endpoint for production.
|
|
14
|
+
|
|
15
|
+
When a collector emits an event it is delivered to **every** registered adapter.
|
|
16
|
+
|
|
17
|
+
### Entry points
|
|
18
|
+
|
|
19
|
+
| Import path | Contents |
|
|
20
|
+
|---|---|
|
|
21
|
+
| `@equinor/fusion-framework-module-analytics` | Module definition, `enableAnalytics`, core types |
|
|
22
|
+
| `@equinor/fusion-framework-module-analytics/adapters` | `ConsoleAnalyticsAdapter`, `FusionAnalyticsAdapter`, `IAnalyticsAdapter` |
|
|
23
|
+
| `@equinor/fusion-framework-module-analytics/collectors` | `ContextSelectedCollector`, `AppSelectedCollector`, `AppLoadedCollector`, `IAnalyticsCollector` |
|
|
24
|
+
| `@equinor/fusion-framework-module-analytics/logExporters` | `OTLPLogExporter`, `FusionOTLPLogExporter` |
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
Call `enableAnalytics` inside your application or portal configuration callback
|
|
29
|
+
to register adapters and collectors:
|
|
14
30
|
|
|
15
31
|
```typescript
|
|
16
32
|
import { enableAnalytics } from '@equinor/fusion-framework-module-analytics';
|
|
33
|
+
import { ConsoleAnalyticsAdapter } from '@equinor/fusion-framework-module-analytics/adapters';
|
|
34
|
+
import { ContextSelectedCollector } from '@equinor/fusion-framework-module-analytics/collectors';
|
|
17
35
|
|
|
18
|
-
const configure = (configurator
|
|
36
|
+
const configure = (configurator) => {
|
|
19
37
|
enableAnalytics(configurator, (builder) => {
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
builder.setAdapter('console', async () => {
|
|
23
|
-
return new ConsoleAnalyticsAdapter();
|
|
24
|
-
});
|
|
38
|
+
// Register an adapter — receives every event
|
|
39
|
+
builder.setAdapter('console', async () => new ConsoleAnalyticsAdapter());
|
|
25
40
|
|
|
41
|
+
// Register a collector — emits events on context change
|
|
26
42
|
builder.setCollector('context-selected', async (args) => {
|
|
27
43
|
const contextProvider = await args.requireInstance('context');
|
|
28
44
|
const appProvider = await args.requireInstance('app');
|
|
29
45
|
return new ContextSelectedCollector(contextProvider, appProvider);
|
|
30
46
|
});
|
|
31
47
|
});
|
|
32
|
-
}
|
|
48
|
+
};
|
|
33
49
|
```
|
|
34
50
|
|
|
35
|
-
|
|
51
|
+
> **Note:** The analytics module initialises automatically when used inside the
|
|
52
|
+
> Fusion Framework module system. Manual initialisation is only required when
|
|
53
|
+
> accessing the provider directly.
|
|
36
54
|
|
|
37
|
-
|
|
38
|
-
collectors. The provider exposes an `initialize()` method that should be called
|
|
39
|
-
to set up all configured adapters and collectors:
|
|
55
|
+
## Adapters
|
|
40
56
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
57
|
+
Adapters implement `IAnalyticsAdapter` and are responsible for processing and
|
|
58
|
+
sending analytics data to their destinations. All adapters support async
|
|
59
|
+
initialisation and will be initialised automatically when the provider starts.
|
|
44
60
|
|
|
45
|
-
|
|
46
|
-
await provider.initialize();
|
|
61
|
+
### ConsoleAnalyticsAdapter
|
|
47
62
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// Provider is ready for use
|
|
51
|
-
}
|
|
52
|
-
```
|
|
63
|
+
Logs every analytics event to the browser console. Useful for development and
|
|
64
|
+
debugging. No configuration required.
|
|
53
65
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
> accessing the provider directly.
|
|
66
|
+
```typescript
|
|
67
|
+
builder.setAdapter('console', async () => new ConsoleAnalyticsAdapter());
|
|
68
|
+
```
|
|
58
69
|
|
|
59
|
-
|
|
70
|
+
### FusionAnalyticsAdapter
|
|
60
71
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
will automatically be initialized when the analytics provider initializes.
|
|
72
|
+
Forwards analytics events to an OpenTelemetry-compatible log endpoint via a
|
|
73
|
+
bundled `LoggerProvider`.
|
|
64
74
|
|
|
65
|
-
|
|
75
|
+
Configuration options:
|
|
66
76
|
|
|
67
|
-
|
|
68
|
-
|
|
77
|
+
| Option | Type | Description |
|
|
78
|
+
|---|---|---|
|
|
79
|
+
| `portalId` | `string` | Portal identifier included in every log record |
|
|
80
|
+
| `logExporter` | `OTLPExporterBase` | OTLP log exporter for transport |
|
|
69
81
|
|
|
70
|
-
####
|
|
82
|
+
#### Using `OTLPLogExporter` (direct HTTP)
|
|
71
83
|
|
|
72
84
|
```typescript
|
|
73
|
-
import {
|
|
74
|
-
import {
|
|
85
|
+
import { OTLPLogExporter } from '@equinor/fusion-framework-module-analytics/logExporters';
|
|
86
|
+
import { FusionAnalyticsAdapter } from '@equinor/fusion-framework-module-analytics/adapters';
|
|
75
87
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
});
|
|
88
|
+
builder.setAdapter('fusion-log', async () => {
|
|
89
|
+
const logExporter = new OTLPLogExporter({
|
|
90
|
+
url: 'https://example.com/v1/logs',
|
|
91
|
+
headers: { 'Content-Type': 'application/json' },
|
|
81
92
|
});
|
|
82
|
-
}
|
|
93
|
+
return new FusionAnalyticsAdapter({ portalId: 'my-portal', logExporter });
|
|
94
|
+
});
|
|
83
95
|
```
|
|
84
96
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
The `ConsoleAnalyticsAdapter` provides a simple way to log analytics data to the
|
|
88
|
-
console, useful for development and debugging.
|
|
97
|
+
#### Using `FusionOTLPLogExporter` (service discovery HTTP client)
|
|
89
98
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
additional installation.
|
|
99
|
+
```typescript
|
|
100
|
+
import { FusionOTLPLogExporter } from '@equinor/fusion-framework-module-analytics/logExporters';
|
|
101
|
+
import { FusionAnalyticsAdapter } from '@equinor/fusion-framework-module-analytics/adapters';
|
|
94
102
|
|
|
95
|
-
|
|
103
|
+
builder.setAdapter('fusion', async (args) => {
|
|
104
|
+
if (args.hasModule('serviceDiscovery')) {
|
|
105
|
+
const sd = await args.requireInstance('serviceDiscovery');
|
|
106
|
+
const httpClient = await sd.createClient('analytics');
|
|
107
|
+
const logExporter = new FusionOTLPLogExporter(httpClient);
|
|
108
|
+
return new FusionAnalyticsAdapter({ portalId: 'my-portal', logExporter });
|
|
109
|
+
}
|
|
110
|
+
console.error('Service discovery unavailable — analytics adapter not created');
|
|
111
|
+
});
|
|
112
|
+
```
|
|
96
113
|
|
|
97
|
-
|
|
114
|
+
### Creating a Custom Adapter
|
|
98
115
|
|
|
99
|
-
|
|
116
|
+
Implement `IAnalyticsAdapter` and register it with `setAdapter`:
|
|
100
117
|
|
|
101
|
-
|
|
102
|
-
|
|
118
|
+
```typescript
|
|
119
|
+
import type { IAnalyticsAdapter } from '@equinor/fusion-framework-module-analytics/adapters';
|
|
120
|
+
import type { AnalyticsEvent } from '@equinor/fusion-framework-module-analytics';
|
|
103
121
|
|
|
104
|
-
|
|
122
|
+
class MyRemoteAdapter implements IAnalyticsAdapter {
|
|
123
|
+
registerAnalytic(event: AnalyticsEvent): void {
|
|
124
|
+
navigator.sendBeacon('/analytics', JSON.stringify(event));
|
|
125
|
+
}
|
|
105
126
|
|
|
106
|
-
|
|
107
|
-
|
|
127
|
+
[Symbol.dispose](): void {
|
|
128
|
+
// cleanup if needed
|
|
129
|
+
}
|
|
130
|
+
}
|
|
108
131
|
|
|
109
|
-
|
|
132
|
+
builder.setAdapter('remote', async () => new MyRemoteAdapter());
|
|
133
|
+
```
|
|
110
134
|
|
|
111
|
-
|
|
135
|
+
## Collectors
|
|
112
136
|
|
|
113
|
-
|
|
137
|
+
Collectors implement `IAnalyticsCollector` (or extend `BaseCollector`) and emit
|
|
138
|
+
`AnalyticsEvent` objects that are forwarded to all adapters. All collectors
|
|
139
|
+
support async initialisation.
|
|
114
140
|
|
|
115
|
-
|
|
141
|
+
### ContextSelectedCollector
|
|
116
142
|
|
|
117
|
-
|
|
143
|
+
Emits an event when the active Fusion context changes. Includes the new context,
|
|
144
|
+
the previous context, and the current app key in attributes.
|
|
118
145
|
|
|
119
146
|
```typescript
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const logExporter = new OTLPLogExporter({
|
|
125
|
-
url: 'URL_TO_POST_TO',
|
|
126
|
-
headers: {
|
|
127
|
-
'Content-Type': 'application/json',
|
|
128
|
-
},
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
return new FusionAnalyticsAdapter({
|
|
132
|
-
portalId: 'PORTAL_ID',
|
|
133
|
-
logExporter,
|
|
134
|
-
});
|
|
147
|
+
builder.setCollector('context-selected', async (args) => {
|
|
148
|
+
const ctx = await args.requireInstance('context');
|
|
149
|
+
const app = await args.requireInstance('app');
|
|
150
|
+
return new ContextSelectedCollector(ctx, app);
|
|
135
151
|
});
|
|
152
|
+
```
|
|
136
153
|
|
|
137
|
-
|
|
138
|
-
import { FusionOTLPLogExporter } from '@equinor/fusion-framework-module-analytics/logExporters';
|
|
154
|
+
### AppSelectedCollector
|
|
139
155
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const serviceDiscovery = await args.requireInstance<ServiceDiscoveryProvider>(
|
|
143
|
-
'serviceDiscovery'
|
|
144
|
-
);
|
|
145
|
-
const httpClient = await serviceDiscovery.createClient('SERVICE_DISCOVERY_NAME');
|
|
156
|
+
Emits an event when the active application changes. Includes the new and
|
|
157
|
+
previous app key metadata.
|
|
146
158
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
logExporter,
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
console.error('Could not instanziate monitor http client from service-discovery');
|
|
159
|
+
```typescript
|
|
160
|
+
builder.setCollector('app-selected', async (args) => {
|
|
161
|
+
const app = await args.requireInstance('app');
|
|
162
|
+
return new AppSelectedCollector(app);
|
|
155
163
|
});
|
|
156
164
|
```
|
|
157
165
|
|
|
158
|
-
###
|
|
166
|
+
### AppLoadedCollector
|
|
159
167
|
|
|
160
|
-
|
|
161
|
-
|
|
168
|
+
Emits an event when an application's modules finish loading. Includes app
|
|
169
|
+
manifest metadata and the current context (if available).
|
|
162
170
|
|
|
163
|
-
|
|
171
|
+
```typescript
|
|
172
|
+
builder.setCollector('app-loaded', async (args) => {
|
|
173
|
+
const event = await args.requireInstance('event');
|
|
174
|
+
const app = await args.requireInstance('app');
|
|
175
|
+
return new AppLoadedCollector(event, app);
|
|
176
|
+
});
|
|
177
|
+
```
|
|
164
178
|
|
|
165
|
-
|
|
166
|
-
collectors support asynchronous initialization and will automatically be
|
|
167
|
-
initialized when the analytics provider initializes.
|
|
179
|
+
### Creating a Custom Collector
|
|
168
180
|
|
|
169
|
-
|
|
181
|
+
Extend `BaseCollector` with a Zod schema for validation:
|
|
170
182
|
|
|
171
|
-
|
|
172
|
-
|
|
183
|
+
```typescript
|
|
184
|
+
import { BaseCollector, createSchema } from '@equinor/fusion-framework-module-analytics/collectors';
|
|
185
|
+
import { z } from 'zod';
|
|
186
|
+
import { of } from 'rxjs';
|
|
173
187
|
|
|
174
|
-
|
|
188
|
+
const schema = createSchema(z.string(), z.object({ page: z.string() }));
|
|
175
189
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
190
|
+
class PageViewCollector extends BaseCollector<string, { page: string }> {
|
|
191
|
+
constructor() {
|
|
192
|
+
super('page-view', schema);
|
|
193
|
+
}
|
|
179
194
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const contextProvider = await args.requireInstance('context');
|
|
184
|
-
const appProvider = await args.requireInstance('app');
|
|
185
|
-
return new ContextSelectedCollector(contextProvider, appProvider);
|
|
186
|
-
});
|
|
187
|
-
});
|
|
195
|
+
_initialize() {
|
|
196
|
+
return of({ value: window.location.pathname, attributes: { page: document.title } });
|
|
197
|
+
}
|
|
188
198
|
}
|
|
189
199
|
```
|
|
190
200
|
|
|
191
|
-
|
|
201
|
+
## Tracking Events Manually
|
|
192
202
|
|
|
193
|
-
The
|
|
194
|
-
the new and optional previous context.
|
|
203
|
+
The provider exposes methods for ad-hoc event tracking outside of collectors:
|
|
195
204
|
|
|
196
|
-
|
|
205
|
+
```typescript
|
|
206
|
+
// Single event
|
|
207
|
+
provider.trackAnalytic({
|
|
208
|
+
name: 'button-click',
|
|
209
|
+
value: 'save',
|
|
210
|
+
attributes: { section: 'toolbar' },
|
|
211
|
+
});
|
|
197
212
|
|
|
198
|
-
|
|
199
|
-
|
|
213
|
+
// Observable stream
|
|
214
|
+
const subscription = provider.trackAnalytic$(myEvent$);
|
|
215
|
+
// later: subscription.unsubscribe();
|
|
216
|
+
```
|
|
200
217
|
|
|
201
218
|
#### Configuration
|
|
202
219
|
|
|
@@ -2,18 +2,21 @@ import { BaseConfigBuilder, } from '@equinor/fusion-framework-module';
|
|
|
2
2
|
import { from } from 'rxjs';
|
|
3
3
|
import { map, scan, filter, defaultIfEmpty, shareReplay, mergeMap } from 'rxjs/operators';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* The `AnalyticsConfigurator` class extends `BaseConfigBuilder` to provide a fluent API for
|
|
8
|
-
* setting up analytics adapters and collectors.
|
|
5
|
+
* Default {@link IAnalyticsConfigurator} implementation for registering analytics adapters and collectors.
|
|
9
6
|
*
|
|
10
7
|
* @remarks
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
8
|
+
* Extends `BaseConfigBuilder` to resolve adapter and collector factories
|
|
9
|
+
* asynchronously at module-initialisation time using RxJS `mergeMap`. Each
|
|
10
|
+
* registered factory is invoked with the module’s `ConfigBuilderCallbackArgs`
|
|
11
|
+
* so it can resolve dependencies from the framework before returning its
|
|
12
|
+
* adapter or collector instance.
|
|
13
|
+
*
|
|
14
|
+
* Use {@link AnalyticsConfigurator.setAdapter | setAdapter} and
|
|
15
|
+
* {@link AnalyticsConfigurator.setCollector | setCollector} to register
|
|
16
|
+
* components. Both methods return `this` for fluent chaining.
|
|
14
17
|
*
|
|
15
|
-
* @see
|
|
16
|
-
* @see
|
|
18
|
+
* @see {@link IAnalyticsConfigurator}
|
|
19
|
+
* @see {@link BaseConfigBuilder}
|
|
17
20
|
*/
|
|
18
21
|
export class AnalyticsConfigurator extends BaseConfigBuilder {
|
|
19
22
|
#collectorCallbacks = {};
|
|
@@ -36,22 +39,24 @@ export class AnalyticsConfigurator extends BaseConfigBuilder {
|
|
|
36
39
|
});
|
|
37
40
|
}
|
|
38
41
|
/**
|
|
39
|
-
* Registers
|
|
42
|
+
* Registers an analytics collector factory.
|
|
40
43
|
*
|
|
41
|
-
* @
|
|
42
|
-
* @param
|
|
43
|
-
* @
|
|
44
|
+
* @template T - The concrete analytics event type the collector emits.
|
|
45
|
+
* @param identifier - Unique key for the collector.
|
|
46
|
+
* @param callback - Factory that receives module-resolution args and returns a collector.
|
|
47
|
+
* @returns `this` for method chaining.
|
|
44
48
|
*/
|
|
45
49
|
setCollector(identifier, callback) {
|
|
46
50
|
this.#collectorCallbacks[identifier] = callback;
|
|
47
51
|
return this;
|
|
48
52
|
}
|
|
49
53
|
/**
|
|
50
|
-
* Registers
|
|
54
|
+
* Registers an analytics adapter factory.
|
|
51
55
|
*
|
|
52
|
-
* @
|
|
53
|
-
* @param
|
|
54
|
-
* @
|
|
56
|
+
* @template T - The concrete analytics event type the adapter handles.
|
|
57
|
+
* @param identifier - Unique key for the adapter.
|
|
58
|
+
* @param callback - Factory that receives module-resolution args and returns an adapter.
|
|
59
|
+
* @returns `this` for method chaining.
|
|
55
60
|
*/
|
|
56
61
|
setAdapter(identifier, callback) {
|
|
57
62
|
this.#adapterCallbacks[identifier] = callback;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnalyticsConfigurator.js","sourceRoot":"","sources":["../../src/AnalyticsConfigurator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAGlB,MAAM,kCAAkC,CAAC;AAK1C,OAAO,EAAE,IAAI,EAAwB,MAAM,MAAM,CAAC;AAElD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1F
|
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framework-module/provider';
|
|
2
2
|
import { version } from './version.js';
|
|
3
3
|
import { from, Subject, Subscription } from 'rxjs';
|
|
4
|
+
/**
|
|
5
|
+
* An RxJS `Subscription` that also implements the TC39 `Disposable` protocol.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Returned by {@link AnalyticsProvider.trackAnalytic$} so callers can clean up
|
|
9
|
+
* with either `subscription.unsubscribe()` or `using` / `Symbol.dispose`.
|
|
10
|
+
*/
|
|
4
11
|
class DisposableSubscription extends Subscription {
|
|
5
12
|
constructor(subscription) {
|
|
6
13
|
super(subscription.unsubscribe);
|
|
@@ -10,14 +17,22 @@ class DisposableSubscription extends Subscription {
|
|
|
10
17
|
};
|
|
11
18
|
}
|
|
12
19
|
/**
|
|
13
|
-
*
|
|
20
|
+
* Runtime analytics provider that collects events from collectors and dispatches
|
|
21
|
+
* them to adapters.
|
|
14
22
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* Created by the analytics module during initialisation. The provider:
|
|
25
|
+
*
|
|
26
|
+
* 1. Initialises all registered adapters and collectors.
|
|
27
|
+
* 2. Subscribes to every collector and merges their events into a shared stream.
|
|
28
|
+
* 3. Forwards each emitted event to every registered adapter via
|
|
29
|
+
* {@link IAnalyticsAdapter.registerAnalytic}.
|
|
30
|
+
*
|
|
31
|
+
* Consumers can also push ad-hoc events with {@link AnalyticsProvider.trackAnalytic}
|
|
32
|
+
* or subscribe an observable stream with {@link AnalyticsProvider.trackAnalytic$}.
|
|
17
33
|
*
|
|
18
|
-
* @typeParam AnalyticsConfig - The configuration type for analytics.
|
|
19
|
-
* @implements IAnalyticsProvider
|
|
20
34
|
* @extends BaseModuleProvider<AnalyticsConfig>
|
|
35
|
+
* @implements IAnalyticsProvider
|
|
21
36
|
*/
|
|
22
37
|
export class AnalyticsProvider extends BaseModuleProvider {
|
|
23
38
|
#analytics;
|
|
@@ -30,16 +45,21 @@ export class AnalyticsProvider extends BaseModuleProvider {
|
|
|
30
45
|
this.#adapters = config.adapters;
|
|
31
46
|
}
|
|
32
47
|
/**
|
|
33
|
-
*
|
|
48
|
+
* Initialises all adapters and collectors, then wires collector output into
|
|
49
|
+
* the adapter pipeline.
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* Initialisation is idempotent within the module lifecycle — the module calls
|
|
53
|
+
* this once during `module.initialize`. Steps:
|
|
54
|
+
*
|
|
55
|
+
* 1. Initialise all collectors (via `Promise.allSettled`).
|
|
56
|
+
* 2. Initialise all adapters (via `Promise.allSettled`).
|
|
57
|
+
* 3. Subscribe to each collector and forward events into the shared subject.
|
|
58
|
+
* 4. Subscribe to the shared subject and dispatch to every adapter.
|
|
34
59
|
*
|
|
35
|
-
*
|
|
36
|
-
* 1. Storing the provided adapters
|
|
37
|
-
* 2. Initializing all adapters
|
|
38
|
-
* 3. Storing the provided collectors
|
|
39
|
-
* 4. Initializing all collectors
|
|
40
|
-
* 5. Setting up subscription for analytics processing
|
|
60
|
+
* All subscriptions are registered as teardowns on the base provider.
|
|
41
61
|
*
|
|
42
|
-
* @returns A promise that resolves when
|
|
62
|
+
* @returns A promise that resolves when all adapters and collectors are initialised.
|
|
43
63
|
*/
|
|
44
64
|
async initialize() {
|
|
45
65
|
const initializedCollectors = Object.values(this.#collectors).map((collector) => Promise.resolve(collector.initialize?.()));
|
|
@@ -64,19 +84,20 @@ export class AnalyticsProvider extends BaseModuleProvider {
|
|
|
64
84
|
this._addTeardown(adapterSubscription);
|
|
65
85
|
}
|
|
66
86
|
/**
|
|
67
|
-
*
|
|
87
|
+
* Pushes a single analytics event to all registered adapters.
|
|
68
88
|
*
|
|
69
|
-
* @param event - The analytics event to track
|
|
89
|
+
* @param event - The analytics event to track.
|
|
70
90
|
*/
|
|
71
91
|
trackAnalytic(event) {
|
|
72
92
|
// @TODO: Validate AnalyticsEvent includes name, value and attributes
|
|
73
93
|
this.#analytics.next(event);
|
|
74
94
|
}
|
|
75
95
|
/**
|
|
76
|
-
*
|
|
96
|
+
* Subscribes to an observable stream of analytics events and forwards each
|
|
97
|
+
* emission to all registered adapters.
|
|
77
98
|
*
|
|
78
|
-
* @param analytic$ - Observable input stream of
|
|
79
|
-
* @returns
|
|
99
|
+
* @param analytic$ - Observable input stream of analytics events.
|
|
100
|
+
* @returns A {@link DisposableSubscription} supporting both `unsubscribe()` and `Symbol.dispose`.
|
|
80
101
|
*/
|
|
81
102
|
trackAnalytic$(analytic$) {
|
|
82
103
|
const subscription = from(analytic$)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnalyticsProvider.js","sourceRoot":"","sources":["../../src/AnalyticsProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAE/E,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAKvC,OAAO,EAAE,IAAI,EAAwB,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAIzE,MAAM,sBAAuB,SAAQ,YAAY;IAC/C,YAAY,YAA0B;QACpC,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;IAClC,CAAC;IAED,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,GAAG,EAAE;QACtB,IAAI,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC,CAAC;CACH;AAED
|
|
1
|
+
{"version":3,"file":"AnalyticsProvider.js","sourceRoot":"","sources":["../../src/AnalyticsProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAE/E,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAKvC,OAAO,EAAE,IAAI,EAAwB,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAIzE;;;;;;GAMG;AACH,MAAM,sBAAuB,SAAQ,YAAY;IAC/C,YAAY,YAA0B;QACpC,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;IACl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AK,EAAE,EAAE;oBACd,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC9B,CAAC;aACF,CAAC,CAAC;YAEH,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAClC,CAAC;QAED,MAAM,mBAAmB,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;YACpD,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE;gBACd,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;oBACpD,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;gBAClC,CAAC;YACH,CAAC;SACF,CAAC,CAAC;QACH,IAAI,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACH,aAAa,CAAC,KAAqB;QACjC,qEAAqE;QACrE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;OAMG;IACH,cAAc,CAAC,SAA0C;QACvD,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC;YAClC,qEAAqE;aACpE,SAAS,CAAC;YACT,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE;gBACd,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC;SACF,CAAC,CAAC;QAEL,OAAO,IAAI,sBAAsB,CAAC,YAAY,CAAC,CAAC;IAClD,CAAC;CACF"}
|
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Analytics adapter that logs every event to the browser console.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Useful during development and debugging. Each event is logged with the
|
|
6
|
+
* prefix `Analytics::Adapter::Console`.
|
|
7
|
+
*
|
|
8
|
+
* @template T - Analytics event type, defaults to {@link AnalyticsEvent}.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { ConsoleAnalyticsAdapter } from '@equinor/fusion-framework-module-analytics/adapters';
|
|
13
|
+
*
|
|
14
|
+
* builder.setAdapter('console', async () => new ConsoleAnalyticsAdapter());
|
|
15
|
+
* ```
|
|
3
16
|
*/
|
|
4
17
|
export class ConsoleAnalyticsAdapter {
|
|
18
|
+
/** Logs the event to the console. */
|
|
5
19
|
registerAnalytic(event) {
|
|
6
20
|
console.log('Analytics::Adapter::Console', event);
|
|
7
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConsoleAnalyticsAdapter.js","sourceRoot":"","sources":["../../../src/adapters/ConsoleAnalyticsAdapter.ts"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"ConsoleAnalyticsAdapter.js","sourceRoot":"","sources":["../../../src/adapters/ConsoleAnalyticsAdapter.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,uBAAuB;IAGlC,qCAAqC;IACrC,gBAAgB,CAAC,KAAQ;QACvB,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;IAED,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,QAAQ;IACV,CAAC;CACF"}
|