-
Notifications
You must be signed in to change notification settings - Fork 17
feat: add metrics infrustructure to ui #2698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,52 @@ | ||||||||||||||||||||
| import {uiFactory} from '../uiFactory/uiFactory'; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export interface Counter { | ||||||||||||||||||||
| hit: (...args: unknown[]) => void; | ||||||||||||||||||||
| params: (...args: unknown[]) => void; | ||||||||||||||||||||
| userParams: (...args: unknown[]) => void; | ||||||||||||||||||||
| reachGoal: (...args: unknown[]) => void; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const yaMetricaMap = uiFactory.yaMetricaMap; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| class FakeMetrica implements Counter { | ||||||||||||||||||||
| name: string; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| private warnShown = false; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| constructor(name: string) { | ||||||||||||||||||||
| this.name = name; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| hit() { | ||||||||||||||||||||
| this.warnOnce(); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| params() { | ||||||||||||||||||||
| this.warnOnce(); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| userParams() { | ||||||||||||||||||||
| this.warnOnce(); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| reachGoal() { | ||||||||||||||||||||
| this.warnOnce(); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| private warnOnce() { | ||||||||||||||||||||
| if (!this.warnShown) { | ||||||||||||||||||||
| console.warn(`YaMetrica counter "${this.name}" is not defined\n`); | ||||||||||||||||||||
|
||||||||||||||||||||
| console.warn(`YaMetrica counter "${this.name}" is not defined\n`); | |
| console.warn(`Yandex.Metrica counter "${this.name}" is not defined\n`); |
Copilot
AI
Aug 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getMetrica function lacks documentation. Consider adding JSDoc to explain its purpose, parameters, and return value, especially the fallback behavior to FakeMetrica.
| /** | |
| * Retrieves a YaMetrica counter instance by name. | |
| * | |
| * @param {string} name - The name of the YaMetrica counter to retrieve. | |
| * @returns {Counter} The YaMetrica counter instance if found, otherwise a FakeMetrica instance. | |
| * If the counter is not defined, FakeMetrica will log a warning once when its methods are called. | |
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Metrica ID Check Fails on Zero
The getMetrica function's truthiness check on yaMetricaId (e.g., yaMetricaId ? ...) incorrectly treats 0 as falsy. Since 0 is a valid Yandex Metrica counter ID, this causes the function to return a FakeMetrica instance instead of the real window['yaCounter0']. The condition should use yaMetricaId !== undefined or yaMetricaId != null to correctly identify valid IDs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Counter interface and its methods lack documentation. Consider adding JSDoc comments to explain the purpose of each method and their parameters.