Skip to content

Commit 75bafc4

Browse files
authored
feat: add analytics to icons-block (#561)
* feat: add analytics to icons-block * fix: separate events for icons * fix: add analyticsEvents to schema * fix: fix after review
1 parent e8a2567 commit 75bafc4

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

src/blocks/Icons/Icons.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import React, {Fragment, useContext} from 'react';
1+
import React, {Fragment, useCallback, useContext} from 'react';
22

33
import {Image, Title} from '../../components';
44
import {LocationContext} from '../../context/locationContext';
5-
import {IconsBlockProps} from '../../models';
5+
import {useAnalytics} from '../../hooks';
6+
import {IconsBlockItemProps, IconsBlockProps} from '../../models';
67
import {block, getLinkProps} from '../../utils';
78

89
import './Icons.scss';
@@ -18,6 +19,14 @@ const getItemContent = (item: IconsBlockProps['items'][number]) => (
1819

1920
const Icons = ({title, size = 's', items}: IconsBlockProps) => {
2021
const {hostname} = useContext(LocationContext);
22+
const handleAnalytics = useAnalytics();
23+
24+
const onClick = useCallback(
25+
({analyticsEvents, url}: IconsBlockItemProps) => {
26+
handleAnalytics(analyticsEvents, {url});
27+
},
28+
[handleAnalytics],
29+
);
2130

2231
return (
2332
<div className={b({size})}>
@@ -33,6 +42,7 @@ const Icons = ({title, size = 's', items}: IconsBlockProps) => {
3342
aria-label={text}
3443
title={text}
3544
{...getLinkProps(url, hostname)}
45+
onClick={() => onClick(item)}
3646
>
3747
{itemContent}
3848
</a>

src/blocks/Icons/schema.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {AnimatableProps, BlockBaseProps} from '../../schema/validators/common';
2+
import {AnalyticsEventSchema} from '../../schema/validators/event';
23

34
export const IconsProps = {
45
additionalProperties: false,
@@ -33,6 +34,19 @@ export const IconsProps = {
3334
type: 'string',
3435
},
3536
},
37+
analyticsEvents: {
38+
oneOf: [
39+
{
40+
...AnalyticsEventSchema,
41+
optionName: 'single',
42+
},
43+
{
44+
type: 'array',
45+
items: AnalyticsEventSchema,
46+
optionName: 'list',
47+
},
48+
],
49+
},
3650
},
3751
},
3852
},

src/models/constructor-items/blocks.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {ButtonSize} from '@gravity-ui/uikit';
22

33
import {GridColumnSize, GridColumnSizesType} from '../../grid/types';
44
import {ThemeSupporting} from '../../utils';
5+
import {AnalyticsEventsBase} from '../common';
56

67
import {
78
AnchorProps,
@@ -312,14 +313,16 @@ export interface FilterBlockProps extends Animatable, LoadableChildren {
312313
centered?: boolean;
313314
}
314315

316+
export interface IconsBlockItemProps extends AnalyticsEventsBase {
317+
url: string;
318+
text: string;
319+
src: string;
320+
}
321+
315322
export interface IconsBlockProps {
316323
title?: string;
317324
size?: 's' | 'm' | 'l';
318-
items: {
319-
url: string;
320-
text: string;
321-
src: string;
322-
}[];
325+
items: IconsBlockItemProps[];
323326
}
324327

325328
interface ContentLayoutBlockParams {

0 commit comments

Comments
 (0)