Skip to content

Commit f0c671c

Browse files
committed
feat: add metrics infrustructure to ui
1 parent 252c898 commit f0c671c

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

src/types/window.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@ interface Window {
4444
systemSettings?: import('../services/settings').SettingsObject;
4545

4646
api: import('../services/api/index').YdbEmbeddedAPI;
47+
48+
[key: `yaCounter${number}`]: number;
4749
}

src/uiFactory/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface UIFactory<H extends string = CommonIssueType> {
4343
countHealthcheckIssuesByType: (issueTrees: IssuesTree[]) => Record<H, number>;
4444
};
4545
hasAccess?: boolean;
46+
yaMetricaId?: number;
4647
}
4748

4849
export type HandleCreateDB = (params: {clusterName: string}) => Promise<boolean>;

src/utils/yaMetrica.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import {uiFactory} from '../uiFactory/uiFactory';
2+
3+
const yaMetricaId = uiFactory.yaMetricaId;
4+
5+
class FakeMetrica {
6+
private warnShown = false;
7+
8+
hit() {
9+
this.warnOnce();
10+
}
11+
12+
params() {
13+
this.warnOnce();
14+
}
15+
16+
userParams() {
17+
this.warnOnce();
18+
}
19+
20+
reachGoal() {
21+
this.warnOnce();
22+
}
23+
24+
private warnOnce() {
25+
if (!this.warnShown) {
26+
console.warn('YaMetrica counter is not defined');
27+
this.warnShown = true;
28+
}
29+
}
30+
}
31+
32+
export function getMetrica() {
33+
const metricaInstance = yaMetricaId && window[`yaCounter${yaMetricaId}`];
34+
35+
return metricaInstance ?? new FakeMetrica();
36+
}

0 commit comments

Comments
 (0)