Skip to content

Commit 584122e

Browse files
committed
feat: add service support to analytics mechnism
1 parent 1c1a104 commit 584122e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+744
-66
lines changed

docs/analytics/ANALYTICS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The practice of analytics is there for supporting decision-making by providing t
88
When you generate your component, you can decide to activate the otter analytics structure.
99

1010
### A new file analytic.ts
11-
The otter component generator will create one file suffixed by `analytics.ts`.
11+
The otter component generator will create one file suffixed by `analytics.ts`.
1212
Inside you will find an interface to define all the events that your component can trigger and a const to inject inside your component.
1313

1414
```typescript

docs/analytics/TRACK_EVENTS.md

Lines changed: 72 additions & 48 deletions
Large diffs are not rendered by default.

packages/@o3r/analytics/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@angular/router": "~18.0.0",
3333
"@ngrx/store": "~18.0.0",
3434
"@o3r/core": "workspace:^",
35+
"@o3r/logger": "workspace:^",
3536
"@o3r/schematics": "workspace:^",
3637
"@schematics/angular": "~18.0.0",
3738
"jasmine": "^5.0.0",
@@ -80,6 +81,7 @@
8081
"@o3r/build-helpers": "workspace:^",
8182
"@o3r/core": "workspace:^",
8283
"@o3r/eslint-plugin": "workspace:^",
84+
"@o3r/logger": "workspace:^",
8385
"@o3r/test-helpers": "workspace:^",
8486
"@schematics/angular": "~18.0.0",
8587
"@stylistic/eslint-plugin-ts": "^2.0.0",

packages/@o3r/analytics/schematics/analytics-to-component/templates/__name__.analytics.ts.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {<% if (activateDummy) { %>EventInfo, AnalyticsEvent, Attribute, ConstructorAnalyticsEvent, ConstructorAnalyticsEventParameters,<% } %> AnalyticsEvents} from '@o3r/analytics';
1+
import type {<% if (activateDummy) { %>EventInfo, AnalyticsEvent, Attribute, ConstructorAnalyticsEvent, ConstructorAnalyticsEventParameters,<% } %> AnalyticsEvents} from '@o3r/analytics';
22

33
<% if (activateDummy) { %>/**
44
* Dummy event to show how we can use analytics event
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import type { EventInfo, AnalyticsEvent, Attribute, ConstructorAnalyticsEvent, ConstructorAnalyticsEventParameters, AnalyticsEvents} from '@o3r/analytics';
2+
3+
const dummyEvent = () => {
4+
5+
}
6+
7+
/**
8+
* Dummy event to show how we can use analytics event
9+
*/
10+
export class DummyEvent implements AnalyticsEvent {
11+
/** @inheritdoc */
12+
public eventInfo: EventInfo = {
13+
eventName: 'DummyEvent'
14+
};
15+
}
16+
17+
/**
18+
* Interface to define the inputs that RuntimeDummyEvent needs to be created
19+
*/
20+
export interface RuntimeDummyEventConstructorAnalyticsEventParameters extends ConstructorAnalyticsEventParameters {
21+
/**
22+
* Example of runtime data
23+
*/
24+
runtimeData?: string;
25+
}
26+
27+
/**
28+
* Dummy event with runtime data to show how we can use analytics event
29+
*/
30+
export class RuntimeDummyEvent implements AnalyticsEvent {
31+
/** @inheritdoc */
32+
public eventInfo: EventInfo = {
33+
eventName: 'RuntimeDummyEvent'
34+
};
35+
36+
/** @inheritdoc */
37+
public attributes: Attribute[]
38+
39+
constructor(parameters?: RuntimeDummyEventConstructorAnalyticsEventParameters) {
40+
this.attributes = parameters?.runtimeData ? [{ key: 'runtimeData', value: parameters.runtimeData }] : [];
41+
}
42+
}
43+
44+
/**
45+
* Interface for the analytics of <%= componentName %>
46+
*/
47+
export interface ComponentAnalytics extends AnalyticsEvents {
48+
dummyEvent: ConstructorAnalyticsEvent<DummyEvent>;
49+
runtimeDummyEvent: ConstructorAnalyticsEvent<RuntimeDummyEvent>;
50+
}
51+
52+
/**
53+
* Definition of the analytics of <%= componentName %>
54+
*/
55+
export const analyticsEvents: ComponentAnalytics = {
56+
dummyEvent: DummyEvent,
57+
runtimeDummyEvent: RuntimeDummyEvent
58+
};

packages/@o3r/analytics/src/fixtures/jasmine/event-track.service.fixture.jasmine.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,28 @@ export class EventTrackServiceFixture implements Readonly<Partial<EventTrackServ
3838
/** @inheritdoc */
3939
public addEvent: jasmine.Spy = jasmine.createSpy('addEvent');
4040

41-
/** @inheritdoc */
41+
/**
42+
* @inheritdoc
43+
* @deprecated use {@link AnalyticsEventReporter} instead, will be removed in v12
44+
*/
4245
public addUiEvent: jasmine.Spy = jasmine.createSpy('addUiEvent');
4346

4447
/** @inheritdoc */
4548
public toggleTracking: jasmine.Spy = jasmine.createSpy('toggleTracking');
4649

47-
/** @inheritdoc */
50+
/**
51+
* @inheritdoc
52+
* @deprecated use {@link AnalyticsEventReporter} instead, will be removed in v12
53+
*/
4854
public toggleUiTracking: jasmine.Spy = jasmine.createSpy('toggleUiTracking');
4955

5056
/** @inheritdoc */
5157
public togglePerfTracking: jasmine.Spy = jasmine.createSpy('togglePerfTracking');
5258

53-
/** @inheritdoc */
59+
/**
60+
* @inheritdoc
61+
* @deprecated use {@link AnalyticsEventReporter} instead, will be removed in v12
62+
*/
5463
public addCustomEvent: jasmine.Spy = jasmine.createSpy('addCustomEvent');
5564

5665
}

packages/@o3r/analytics/src/contracts/events-contracts.ts renamed to packages/@o3r/analytics/src/performance/contracts/events-contracts.ts

File renamed without changes.
File renamed without changes.
File renamed without changes.

packages/@o3r/analytics/src/directives/track-events/base-track-events.ts renamed to packages/@o3r/analytics/src/performance/directives/track-events/base-track-events.ts

File renamed without changes.

0 commit comments

Comments
 (0)