@gravity-ui/page-constructor 1.15.0-alpha.7 → 1.15.0-alpha.9
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/README.md +75 -5
- package/build/cjs/blocks/Share/Share.js +1 -2
- package/build/cjs/components/BackLink/BackLink.js +2 -2
- package/build/cjs/components/Button/Button.js +2 -2
- package/build/cjs/components/ButtonTabs/ButtonTabs.js +2 -2
- package/build/cjs/components/CardBase/CardBase.js +2 -2
- package/build/cjs/components/HeaderBreadcrumbs/HeaderBreadcrumbs.js +2 -2
- package/build/cjs/components/Link/Link.js +2 -2
- package/build/cjs/components/ReactPlayer/ReactPlayer.js +3 -4
- package/build/cjs/components/YandexForm/YandexForm.js +2 -2
- package/build/cjs/constants.d.ts +0 -1
- package/build/cjs/constants.js +1 -2
- package/build/cjs/hooks/useAnalytics.js +4 -6
- package/build/cjs/models/common.d.ts +5 -0
- package/build/cjs/models/common.js +7 -1
- package/build/cjs/sub-blocks/HubspotForm/index.js +1 -2
- package/build/cjs/sub-blocks/Quote/Quote.js +1 -2
- package/build/esm/blocks/Share/Share.js +2 -3
- package/build/esm/components/BackLink/BackLink.js +2 -2
- package/build/esm/components/Button/Button.js +2 -2
- package/build/esm/components/ButtonTabs/ButtonTabs.js +2 -2
- package/build/esm/components/CardBase/CardBase.js +2 -2
- package/build/esm/components/HeaderBreadcrumbs/HeaderBreadcrumbs.js +2 -2
- package/build/esm/components/Link/Link.js +2 -2
- package/build/esm/components/ReactPlayer/ReactPlayer.js +4 -5
- package/build/esm/components/YandexForm/YandexForm.js +2 -2
- package/build/esm/constants.d.ts +0 -1
- package/build/esm/constants.js +0 -1
- package/build/esm/hooks/useAnalytics.js +4 -6
- package/build/esm/models/common.d.ts +5 -0
- package/build/esm/models/common.js +6 -0
- package/build/esm/sub-blocks/HubspotForm/index.js +2 -3
- package/build/esm/sub-blocks/Quote/Quote.js +2 -3
- package/package.json +1 -1
- package/server/models/common.d.ts +5 -0
- package/server/models/common.js +7 -1
package/README.md
CHANGED
|
@@ -43,7 +43,8 @@ interface PageConstructorProviderProps {
|
|
|
43
43
|
isMobile?: boolean; //A flag indicating that the code is executed in mobile mode.
|
|
44
44
|
locale?: LocaleContextProps; //Info about the language and domain (used when generating and formatting links).
|
|
45
45
|
location?: Location; //API of the browser or router history, the page URL.
|
|
46
|
-
|
|
46
|
+
analytics?: AnalyticsContextProps; // function to handle analytics event
|
|
47
|
+
|
|
47
48
|
ssrConfig?: SSR; //A flag indicating that the code is run on the server size.
|
|
48
49
|
theme?: 'light' | 'dark'; //Theme to render the page with.
|
|
49
50
|
}
|
|
@@ -81,10 +82,17 @@ interface SSR {
|
|
|
81
82
|
isServer?: boolean;
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
85
|
+
type AnalyticsCounters = {
|
|
86
|
+
include?: string[];
|
|
87
|
+
exclude?: string[];
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
type AnalyticsEvent<T = {}> = T & {
|
|
91
|
+
name: string;
|
|
92
|
+
type?: string;
|
|
93
|
+
counters?: AnalyticsCounters;
|
|
94
|
+
blockName?: string;
|
|
95
|
+
};
|
|
88
96
|
|
|
89
97
|
interface NavigationData {
|
|
90
98
|
logo: NavigationLogo;
|
|
@@ -211,6 +219,68 @@ import {configure, Lang} from '@gravity-ui/page-constructor';
|
|
|
211
219
|
configure({lang: Lang.En});
|
|
212
220
|
```
|
|
213
221
|
|
|
222
|
+
### Analytics
|
|
223
|
+
|
|
224
|
+
#### Init
|
|
225
|
+
|
|
226
|
+
To start use any Analytics it is necessary to pass a handler to the constructor. The handler will receive `default` and `custom` event objects.
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
function sendEvents(event: AnalyticsEvent | AnalyticsEvent []) {
|
|
230
|
+
...
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
<PageConstructorProvider
|
|
234
|
+
...
|
|
235
|
+
|
|
236
|
+
analytics={{sendEvents}}
|
|
237
|
+
|
|
238
|
+
...
|
|
239
|
+
/>,
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
An event object has only one required option - `name`. It also has predefined fields, which serve to help manage complex logic. For example, `counter.include` can help to send event in a particular counter if several are used in a project. The handler must be created on a project side.
|
|
243
|
+
|
|
244
|
+
```ts
|
|
245
|
+
type AnalyticsCounters = {
|
|
246
|
+
include?: string[];
|
|
247
|
+
exclude?: string[];
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
type AnalyticsEvent<T = {}> = T & {
|
|
251
|
+
name: string;
|
|
252
|
+
type?: string;
|
|
253
|
+
counters?: AnalyticsCounters;
|
|
254
|
+
blockName?: string;
|
|
255
|
+
};
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
```ts
|
|
259
|
+
const isCounterAllowed = (counter: Counter, counters?: AnalyticsCounters) => {
|
|
260
|
+
if (!counters) {
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (counters.exclude?.includes(counter)) {
|
|
265
|
+
return false;
|
|
266
|
+
} else if (counters.include?.includes(counter)) {
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return false;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
if (isCounterAllowed(counterName, counters)) {
|
|
274
|
+
analyticsCounter.reachGoal(counterName, name, parameters);
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
#### Reserved types
|
|
279
|
+
|
|
280
|
+
`default` - fires on every click
|
|
281
|
+
`play` - fires on
|
|
282
|
+
`stop` - fires on
|
|
283
|
+
|
|
214
284
|
## Development
|
|
215
285
|
|
|
216
286
|
```bash
|
|
@@ -13,7 +13,6 @@ const Twitter_1 = require("../../icons/Twitter");
|
|
|
13
13
|
const Linkedin_1 = require("../../icons/Linkedin");
|
|
14
14
|
const Vk_1 = require("../../icons/Vk");
|
|
15
15
|
const Telegram_1 = require("../../icons/Telegram");
|
|
16
|
-
const constants_1 = require("../../constants");
|
|
17
16
|
const icons = {
|
|
18
17
|
facebook: Facebook_1.Facebook,
|
|
19
18
|
twitter: Twitter_1.Twitter,
|
|
@@ -26,7 +25,7 @@ const Share = ({ items, title, blockName = models_1.BlockType.ShareBlock }) => {
|
|
|
26
25
|
const { pathname, hostname } = (0, react_1.useContext)(locationContext_1.LocationContext);
|
|
27
26
|
const handleAnalytics = (0, hooks_1.useAnalytics)({
|
|
28
27
|
name: 'share-button-click',
|
|
29
|
-
type:
|
|
28
|
+
type: models_1.PredefinedEventTypes.Default,
|
|
30
29
|
blockName: blockName,
|
|
31
30
|
});
|
|
32
31
|
const handleButtonClick = (0, react_1.useCallback)(() => handleAnalytics === null || handleAnalytics === void 0 ? void 0 : handleAnalytics(), [handleAnalytics]);
|
|
@@ -6,14 +6,14 @@ const uikit_1 = require("@gravity-ui/uikit");
|
|
|
6
6
|
const icons_1 = require("../../icons");
|
|
7
7
|
const locationContext_1 = require("../../context/locationContext");
|
|
8
8
|
const hooks_1 = require("../../hooks");
|
|
9
|
-
const
|
|
9
|
+
const models_1 = require("../../models");
|
|
10
10
|
const COMPONENT_NAME = 'backlink';
|
|
11
11
|
function BackLink(props) {
|
|
12
12
|
const { history } = (0, react_1.useContext)(locationContext_1.LocationContext);
|
|
13
13
|
const { url, title, theme = 'default', size = 'l', className, shouldHandleBackAction = false, onClick, blockName = COMPONENT_NAME, } = props;
|
|
14
14
|
const handleAnalytics = (0, hooks_1.useAnalytics)({
|
|
15
15
|
name: 'back-link-click',
|
|
16
|
-
type:
|
|
16
|
+
type: models_1.PredefinedEventTypes.Default,
|
|
17
17
|
blockName: blockName,
|
|
18
18
|
});
|
|
19
19
|
const backActionHandler = (0, react_1.useCallback)(async () => {
|
|
@@ -4,12 +4,12 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const react_1 = tslib_1.__importStar(require("react"));
|
|
5
5
|
const uikit_1 = require("@gravity-ui/uikit");
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
|
+
const models_1 = require("../../models");
|
|
7
8
|
const utils_2 = require("./utils");
|
|
8
9
|
const localeContext_1 = require("../../context/localeContext/localeContext");
|
|
9
10
|
const useMetrika_1 = require("../../hooks/useMetrika");
|
|
10
11
|
const hooks_1 = require("../../hooks");
|
|
11
12
|
const icons_1 = require("../../icons");
|
|
12
|
-
const constants_1 = require("../../constants");
|
|
13
13
|
const COMPONENT_NAME = 'button';
|
|
14
14
|
const b = (0, utils_1.block)('button-block');
|
|
15
15
|
const Button = (props) => {
|
|
@@ -19,7 +19,7 @@ const Button = (props) => {
|
|
|
19
19
|
const defaultImgPosition = 'left';
|
|
20
20
|
const handleAnalytics = (0, hooks_1.useAnalytics)({
|
|
21
21
|
name: 'button-click',
|
|
22
|
-
type:
|
|
22
|
+
type: models_1.PredefinedEventTypes.Default,
|
|
23
23
|
blockName: blockName,
|
|
24
24
|
});
|
|
25
25
|
const onClick = (0, react_1.useCallback)(() => {
|
|
@@ -3,16 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const react_1 = tslib_1.__importStar(require("react"));
|
|
5
5
|
const utils_1 = require("../../utils");
|
|
6
|
+
const models_1 = require("../../models");
|
|
6
7
|
const index_1 = require("../index");
|
|
7
8
|
const hooks_1 = require("../../hooks");
|
|
8
|
-
const constants_1 = require("../../constants");
|
|
9
9
|
const b = (0, utils_1.block)('button-tabs');
|
|
10
10
|
const COMPONENT_NAME = 'button-tabs';
|
|
11
11
|
const ButtonTabs = (props) => {
|
|
12
12
|
const { className, items, activeTab, onSelectTab, blockName = COMPONENT_NAME } = props;
|
|
13
13
|
const handleAnalytics = (0, hooks_1.useAnalytics)({
|
|
14
14
|
name: 'button-tabs-click',
|
|
15
|
-
type:
|
|
15
|
+
type: models_1.PredefinedEventTypes.Default,
|
|
16
16
|
blockName: blockName,
|
|
17
17
|
});
|
|
18
18
|
const activeTabId = (0, react_1.useMemo)(() => {
|
|
@@ -7,8 +7,8 @@ const utils_1 = require("../../utils");
|
|
|
7
7
|
const BackgroundImage_1 = tslib_1.__importDefault(require("../BackgroundImage/BackgroundImage"));
|
|
8
8
|
const RouterLink_1 = tslib_1.__importDefault(require("../RouterLink/RouterLink"));
|
|
9
9
|
const useMetrika_1 = require("../../hooks/useMetrika");
|
|
10
|
+
const common_1 = require("../../models/common");
|
|
10
11
|
const hooks_1 = require("../../hooks");
|
|
11
|
-
const constants_1 = require("../../constants");
|
|
12
12
|
const COMPONENT_NAME = 'card-base';
|
|
13
13
|
const b = (0, utils_1.block)('card-base-block');
|
|
14
14
|
const Header = () => null;
|
|
@@ -19,7 +19,7 @@ const Layout = (props) => {
|
|
|
19
19
|
const handleMetrika = (0, useMetrika_1.useMetrika)();
|
|
20
20
|
const handleAnalytics = (0, hooks_1.useAnalytics)({
|
|
21
21
|
name: 'card-base-click',
|
|
22
|
-
type:
|
|
22
|
+
type: common_1.PredefinedEventTypes.Default,
|
|
23
23
|
blockName: blockName,
|
|
24
24
|
});
|
|
25
25
|
let header, content, footer, image, headerClass, footerClass;
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
5
5
|
const utils_1 = require("../../utils");
|
|
6
|
+
const models_1 = require("../../models");
|
|
6
7
|
const useMetrika_1 = require("../../hooks/useMetrika");
|
|
7
8
|
const hooks_1 = require("../../hooks");
|
|
8
|
-
const constants_1 = require("../../constants");
|
|
9
9
|
const b = (0, utils_1.block)('header-breadcrumbs');
|
|
10
10
|
const COMPONENT_NAME = 'header-breadcrumbs';
|
|
11
11
|
function HeaderBreadcrumbs(props) {
|
|
@@ -13,7 +13,7 @@ function HeaderBreadcrumbs(props) {
|
|
|
13
13
|
const handleMetrika = (0, useMetrika_1.useMetrika)();
|
|
14
14
|
const handleAnalytics = (0, hooks_1.useAnalytics)({
|
|
15
15
|
name: 'header-breadcrumbs-click',
|
|
16
|
-
type:
|
|
16
|
+
type: models_1.PredefinedEventTypes.Default,
|
|
17
17
|
blockName: blockName,
|
|
18
18
|
});
|
|
19
19
|
const onClick = () => {
|
|
@@ -4,6 +4,7 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const react_1 = tslib_1.__importStar(require("react"));
|
|
5
5
|
const uikit_1 = require("@gravity-ui/uikit");
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
|
+
const models_1 = require("../../models");
|
|
7
8
|
const icons_1 = require("../../icons");
|
|
8
9
|
const FileLink_1 = tslib_1.__importDefault(require("../FileLink/FileLink"));
|
|
9
10
|
const BackLink_1 = tslib_1.__importDefault(require("../BackLink/BackLink"));
|
|
@@ -11,7 +12,6 @@ const localeContext_1 = require("../../context/localeContext/localeContext");
|
|
|
11
12
|
const locationContext_1 = require("../../context/locationContext/locationContext");
|
|
12
13
|
const useMetrika_1 = require("../../hooks/useMetrika");
|
|
13
14
|
const hooks_1 = require("../../hooks");
|
|
14
|
-
const constants_1 = require("../../constants");
|
|
15
15
|
const b = (0, utils_1.block)('link-block');
|
|
16
16
|
const WORD_JOINER_SYM = '\u200b';
|
|
17
17
|
const COMPONENT_NAME = 'link';
|
|
@@ -32,7 +32,7 @@ const LinkBlock = (props) => {
|
|
|
32
32
|
const handleMetrika = (0, useMetrika_1.useMetrika)();
|
|
33
33
|
const handleAnalytics = (0, hooks_1.useAnalytics)({
|
|
34
34
|
name: 'link-click',
|
|
35
|
-
type:
|
|
35
|
+
type: models_1.PredefinedEventTypes.Default,
|
|
36
36
|
blockName: blockName,
|
|
37
37
|
});
|
|
38
38
|
const { hostname } = (0, react_1.useContext)(locationContext_1.LocationContext);
|
|
@@ -14,7 +14,6 @@ const metrikaContext_1 = require("../../context/metrikaContext");
|
|
|
14
14
|
const mobileContext_1 = require("../../context/mobileContext");
|
|
15
15
|
const icons_1 = require("../../icons");
|
|
16
16
|
const hooks_1 = require("../../hooks");
|
|
17
|
-
const constants_1 = require("../../constants");
|
|
18
17
|
const b = (0, utils_1.block)('ReactPlayer');
|
|
19
18
|
const FPS = 60;
|
|
20
19
|
const COMPONENT_NAME = 'react-player';
|
|
@@ -39,7 +38,7 @@ exports.ReactPlayerBlock = react_1.default.forwardRef((props, originRef) => {
|
|
|
39
38
|
const [ended, setEnded] = (0, react_1.useState)(false);
|
|
40
39
|
const handleAnalytics = (0, hooks_1.useAnalytics)({
|
|
41
40
|
name: 'react-player-controls-click',
|
|
42
|
-
type:
|
|
41
|
+
type: models_1.PredefinedEventTypes.Default,
|
|
43
42
|
blockName: blockName,
|
|
44
43
|
});
|
|
45
44
|
(0, react_1.useImperativeHandle)(originRef, () => ({
|
|
@@ -90,8 +89,8 @@ exports.ReactPlayerBlock = react_1.default.forwardRef((props, originRef) => {
|
|
|
90
89
|
window.removeEventListener('resize', updateSize);
|
|
91
90
|
};
|
|
92
91
|
}, []);
|
|
93
|
-
const playEvents = (0, react_1.useMemo)(() => analyticsEvents === null || analyticsEvents === void 0 ? void 0 : analyticsEvents.filter((e) => e.type ===
|
|
94
|
-
const stopEvents = (0, react_1.useMemo)(() => analyticsEvents === null || analyticsEvents === void 0 ? void 0 : analyticsEvents.filter((e) => e.type ===
|
|
92
|
+
const playEvents = (0, react_1.useMemo)(() => analyticsEvents === null || analyticsEvents === void 0 ? void 0 : analyticsEvents.filter((e) => e.type === models_1.PredefinedEventTypes.Play), [analyticsEvents]);
|
|
93
|
+
const stopEvents = (0, react_1.useMemo)(() => analyticsEvents === null || analyticsEvents === void 0 ? void 0 : analyticsEvents.filter((e) => e.type === models_1.PredefinedEventTypes.Stop), [analyticsEvents]);
|
|
95
94
|
const playIcon = (0, react_1.useMemo)(() => {
|
|
96
95
|
let playButtonContent;
|
|
97
96
|
switch (type) {
|
|
@@ -8,8 +8,8 @@ const localeContext_1 = require("../../context/localeContext");
|
|
|
8
8
|
const mobileContext_1 = require("../../context/mobileContext");
|
|
9
9
|
const utils_1 = require("../../utils");
|
|
10
10
|
const useMetrika_1 = require("../../hooks/useMetrika");
|
|
11
|
+
const common_1 = require("../../models/common");
|
|
11
12
|
const hooks_1 = require("../../hooks");
|
|
12
|
-
const constants_2 = require("../../constants");
|
|
13
13
|
exports.YANDEX_FORM_ORIGIN = 'https://forms.yandex.ru';
|
|
14
14
|
const CONTAINER_ID = 'pc-yandex-form-container';
|
|
15
15
|
const COMPONENT_NAME = 'yandex-form';
|
|
@@ -22,7 +22,7 @@ const YandexForm = (props) => {
|
|
|
22
22
|
const handleMetrika = (0, useMetrika_1.useMetrika)();
|
|
23
23
|
const handleAnalytics = (0, hooks_1.useAnalytics)({
|
|
24
24
|
name: 'yndex-form-submit',
|
|
25
|
-
type:
|
|
25
|
+
type: common_1.PredefinedEventTypes.Default,
|
|
26
26
|
blockName: blockName,
|
|
27
27
|
});
|
|
28
28
|
const isMobile = (0, react_1.useContext)(mobileContext_1.MobileContext);
|
package/build/cjs/constants.d.ts
CHANGED
package/build/cjs/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.BREAKPOINTS = void 0;
|
|
4
4
|
exports.BREAKPOINTS = {
|
|
5
5
|
xs: 0,
|
|
6
6
|
sm: 577,
|
|
@@ -8,4 +8,3 @@ exports.BREAKPOINTS = {
|
|
|
8
8
|
lg: 1081,
|
|
9
9
|
xl: 1185,
|
|
10
10
|
};
|
|
11
|
-
exports.DEFAULT_EVENT_TYPE = 'default-event';
|
|
@@ -8,13 +8,11 @@ const useAnalytics = (defaultEvent) => {
|
|
|
8
8
|
if (!sendEvents) {
|
|
9
9
|
return undefined;
|
|
10
10
|
}
|
|
11
|
+
const defaultEvents = defaultEvent ? [defaultEvent] : [];
|
|
11
12
|
return (e) => {
|
|
12
|
-
let events =
|
|
13
|
-
if (
|
|
14
|
-
events = Array.isArray(e) ? [...
|
|
15
|
-
}
|
|
16
|
-
else if (e) {
|
|
17
|
-
events = e;
|
|
13
|
+
let events = defaultEvents;
|
|
14
|
+
if (e) {
|
|
15
|
+
events = Array.isArray(e) ? [...events, ...e] : [...events, e];
|
|
18
16
|
}
|
|
19
17
|
if (!events) {
|
|
20
18
|
return;
|
|
@@ -68,6 +68,11 @@ export type AnalyticsParameter = {
|
|
|
68
68
|
key: string;
|
|
69
69
|
value: string | number | boolean;
|
|
70
70
|
};
|
|
71
|
+
export declare enum PredefinedEventTypes {
|
|
72
|
+
Default = "default-event",
|
|
73
|
+
Play = "play",
|
|
74
|
+
Stop = "stop"
|
|
75
|
+
}
|
|
71
76
|
export type AnalyticsCounters = {
|
|
72
77
|
include?: string[];
|
|
73
78
|
exclude?: string[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PixelEventType = exports.Theme = void 0;
|
|
3
|
+
exports.PredefinedEventTypes = exports.PixelEventType = exports.Theme = void 0;
|
|
4
4
|
var Theme;
|
|
5
5
|
(function (Theme) {
|
|
6
6
|
Theme["Light"] = "light";
|
|
@@ -30,3 +30,9 @@ var PixelEventType;
|
|
|
30
30
|
PixelEventType["Subscribe"] = "Subscribe";
|
|
31
31
|
PixelEventType["ViewContent"] = "ViewContent";
|
|
32
32
|
})(PixelEventType = exports.PixelEventType || (exports.PixelEventType = {}));
|
|
33
|
+
var PredefinedEventTypes;
|
|
34
|
+
(function (PredefinedEventTypes) {
|
|
35
|
+
PredefinedEventTypes["Default"] = "default-event";
|
|
36
|
+
PredefinedEventTypes["Play"] = "play";
|
|
37
|
+
PredefinedEventTypes["Stop"] = "stop";
|
|
38
|
+
})(PredefinedEventTypes = exports.PredefinedEventTypes || (exports.PredefinedEventTypes = {}));
|
|
@@ -9,7 +9,6 @@ const useMetrika_1 = require("../../hooks/useMetrika");
|
|
|
9
9
|
const models_1 = require("../../models");
|
|
10
10
|
const hooks_1 = require("../../hooks");
|
|
11
11
|
const HubspotFormContainer_1 = tslib_1.__importDefault(require("./HubspotFormContainer"));
|
|
12
|
-
const constants_1 = require("../../constants");
|
|
13
12
|
const b = (0, utils_1.block)('hubspot-form');
|
|
14
13
|
const HubspotForm = (props) => {
|
|
15
14
|
const { className, theme: themeProp, isMobile: isMobileProp, formId, formInstanceId, portalId, region, formClassName, pixelEvents,
|
|
@@ -18,7 +17,7 @@ const HubspotForm = (props) => {
|
|
|
18
17
|
const handleMetrika = (0, useMetrika_1.useMetrika)();
|
|
19
18
|
const handleAnalytics = (0, hooks_1.useAnalytics)({
|
|
20
19
|
name: 'hubspot-form-submit',
|
|
21
|
-
type:
|
|
20
|
+
type: models_1.PredefinedEventTypes.Default,
|
|
22
21
|
blockName: blockName,
|
|
23
22
|
});
|
|
24
23
|
const { themeValue } = (0, react_1.useContext)(ThemeValueContext_1.ThemeValueContext);
|
|
@@ -9,7 +9,6 @@ const components_1 = require("../../components");
|
|
|
9
9
|
const ThemeValueContext_1 = require("../../context/theme/ThemeValueContext");
|
|
10
10
|
const utils_2 = require("../../components/Media/Image/utils");
|
|
11
11
|
const hooks_1 = require("../../hooks");
|
|
12
|
-
const constants_1 = require("../../constants");
|
|
13
12
|
const b = (0, utils_1.block)('quote');
|
|
14
13
|
const Quote = (props) => {
|
|
15
14
|
const { theme: textTheme = 'light', color, image, border = 'shadow', text, logo, author, url, buttonText, blockName = models_1.SubBlockType.Quote, } = props;
|
|
@@ -18,7 +17,7 @@ const Quote = (props) => {
|
|
|
18
17
|
const imageData = (0, utils_2.getMediaImage)(imageThemed);
|
|
19
18
|
const handleAnalytics = (0, hooks_1.useAnalytics)({
|
|
20
19
|
name: 'quote-button-click',
|
|
21
|
-
type:
|
|
20
|
+
type: models_1.PredefinedEventTypes.Default,
|
|
22
21
|
blockName: blockName,
|
|
23
22
|
});
|
|
24
23
|
const handleButtonClick = (0, react_1.useCallback)(() => handleAnalytics === null || handleAnalytics === void 0 ? void 0 : handleAnalytics(), [handleAnalytics]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useContext, useCallback } from 'react';
|
|
2
2
|
import { Icon, Button } from '@gravity-ui/uikit';
|
|
3
3
|
import { block, getAbsolutePath, getShareLink } from '../../utils';
|
|
4
|
-
import { BlockType } from '../../models';
|
|
4
|
+
import { BlockType, PredefinedEventTypes } from '../../models';
|
|
5
5
|
import { LocationContext } from '../../context/locationContext';
|
|
6
6
|
import i18n from './i18n';
|
|
7
7
|
import { useAnalytics } from '../../hooks';
|
|
@@ -10,7 +10,6 @@ import { Twitter } from '../../icons/Twitter';
|
|
|
10
10
|
import { Linkedin } from '../../icons/Linkedin';
|
|
11
11
|
import { Vk } from '../../icons/Vk';
|
|
12
12
|
import { Telegram } from '../../icons/Telegram';
|
|
13
|
-
import { DEFAULT_EVENT_TYPE } from '../../constants';
|
|
14
13
|
import './Share.css';
|
|
15
14
|
const icons = {
|
|
16
15
|
facebook: Facebook,
|
|
@@ -24,7 +23,7 @@ const Share = ({ items, title, blockName = BlockType.ShareBlock }) => {
|
|
|
24
23
|
const { pathname, hostname } = useContext(LocationContext);
|
|
25
24
|
const handleAnalytics = useAnalytics({
|
|
26
25
|
name: 'share-button-click',
|
|
27
|
-
type:
|
|
26
|
+
type: PredefinedEventTypes.Default,
|
|
28
27
|
blockName: blockName,
|
|
29
28
|
});
|
|
30
29
|
const handleButtonClick = useCallback(() => handleAnalytics === null || handleAnalytics === void 0 ? void 0 : handleAnalytics(), [handleAnalytics]);
|
|
@@ -3,14 +3,14 @@ import { Button, Icon } from '@gravity-ui/uikit';
|
|
|
3
3
|
import { ArrowSidebar } from '../../icons';
|
|
4
4
|
import { LocationContext } from '../../context/locationContext';
|
|
5
5
|
import { useAnalytics } from '../../hooks';
|
|
6
|
-
import {
|
|
6
|
+
import { PredefinedEventTypes } from '../../models';
|
|
7
7
|
const COMPONENT_NAME = 'backlink';
|
|
8
8
|
export default function BackLink(props) {
|
|
9
9
|
const { history } = useContext(LocationContext);
|
|
10
10
|
const { url, title, theme = 'default', size = 'l', className, shouldHandleBackAction = false, onClick, blockName = COMPONENT_NAME, } = props;
|
|
11
11
|
const handleAnalytics = useAnalytics({
|
|
12
12
|
name: 'back-link-click',
|
|
13
|
-
type:
|
|
13
|
+
type: PredefinedEventTypes.Default,
|
|
14
14
|
blockName: blockName,
|
|
15
15
|
});
|
|
16
16
|
const backActionHandler = useCallback(async () => {
|
|
@@ -2,12 +2,12 @@ import { __rest } from "tslib";
|
|
|
2
2
|
import React, { useCallback, useContext } from 'react';
|
|
3
3
|
import { Platform, Button as CommonButton, Icon, StoreBadge } from '@gravity-ui/uikit';
|
|
4
4
|
import { block, setUrlTld } from '../../utils';
|
|
5
|
+
import { PredefinedEventTypes } from '../../models';
|
|
5
6
|
import { toCommonSize, toCommonView } from './utils';
|
|
6
7
|
import { LocaleContext } from '../../context/localeContext/localeContext';
|
|
7
8
|
import { useMetrika } from '../../hooks/useMetrika';
|
|
8
9
|
import { useAnalytics } from '../../hooks';
|
|
9
10
|
import { Github } from '../../icons';
|
|
10
|
-
import { DEFAULT_EVENT_TYPE } from '../../constants';
|
|
11
11
|
import './Button.css';
|
|
12
12
|
const COMPONENT_NAME = 'button';
|
|
13
13
|
const b = block('button-block');
|
|
@@ -18,7 +18,7 @@ const Button = (props) => {
|
|
|
18
18
|
const defaultImgPosition = 'left';
|
|
19
19
|
const handleAnalytics = useAnalytics({
|
|
20
20
|
name: 'button-click',
|
|
21
|
-
type:
|
|
21
|
+
type: PredefinedEventTypes.Default,
|
|
22
22
|
blockName: blockName,
|
|
23
23
|
});
|
|
24
24
|
const onClick = useCallback(() => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React, { useCallback, useMemo } from 'react';
|
|
2
2
|
import { block } from '../../utils';
|
|
3
|
+
import { PredefinedEventTypes } from '../../models';
|
|
3
4
|
import { Button } from '../index';
|
|
4
5
|
import { useAnalytics } from '../../hooks';
|
|
5
|
-
import { DEFAULT_EVENT_TYPE } from '../../constants';
|
|
6
6
|
import './ButtonTabs.css';
|
|
7
7
|
const b = block('button-tabs');
|
|
8
8
|
const COMPONENT_NAME = 'button-tabs';
|
|
@@ -10,7 +10,7 @@ const ButtonTabs = (props) => {
|
|
|
10
10
|
const { className, items, activeTab, onSelectTab, blockName = COMPONENT_NAME } = props;
|
|
11
11
|
const handleAnalytics = useAnalytics({
|
|
12
12
|
name: 'button-tabs-click',
|
|
13
|
-
type:
|
|
13
|
+
type: PredefinedEventTypes.Default,
|
|
14
14
|
blockName: blockName,
|
|
15
15
|
});
|
|
16
16
|
const activeTabId = useMemo(() => {
|
|
@@ -3,8 +3,8 @@ import { block } from '../../utils';
|
|
|
3
3
|
import BackgroundImage from '../BackgroundImage/BackgroundImage';
|
|
4
4
|
import RouterLink from '../RouterLink/RouterLink';
|
|
5
5
|
import { useMetrika } from '../../hooks/useMetrika';
|
|
6
|
+
import { PredefinedEventTypes } from '../../models/common';
|
|
6
7
|
import { useAnalytics } from '../../hooks';
|
|
7
|
-
import { DEFAULT_EVENT_TYPE } from '../../constants';
|
|
8
8
|
import './CardBase.css';
|
|
9
9
|
const COMPONENT_NAME = 'card-base';
|
|
10
10
|
const b = block('card-base-block');
|
|
@@ -16,7 +16,7 @@ export const Layout = (props) => {
|
|
|
16
16
|
const handleMetrika = useMetrika();
|
|
17
17
|
const handleAnalytics = useAnalytics({
|
|
18
18
|
name: 'card-base-click',
|
|
19
|
-
type:
|
|
19
|
+
type: PredefinedEventTypes.Default,
|
|
20
20
|
blockName: blockName,
|
|
21
21
|
});
|
|
22
22
|
let header, content, footer, image, headerClass, footerClass;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { block } from '../../utils';
|
|
3
|
+
import { PredefinedEventTypes } from '../../models';
|
|
3
4
|
import { useMetrika } from '../../hooks/useMetrika';
|
|
4
5
|
import { useAnalytics } from '../../hooks';
|
|
5
|
-
import { DEFAULT_EVENT_TYPE } from '../../constants';
|
|
6
6
|
import './HeaderBreadcrumbs.css';
|
|
7
7
|
const b = block('header-breadcrumbs');
|
|
8
8
|
const COMPONENT_NAME = 'header-breadcrumbs';
|
|
@@ -11,7 +11,7 @@ export default function HeaderBreadcrumbs(props) {
|
|
|
11
11
|
const handleMetrika = useMetrika();
|
|
12
12
|
const handleAnalytics = useAnalytics({
|
|
13
13
|
name: 'header-breadcrumbs-click',
|
|
14
|
-
type:
|
|
14
|
+
type: PredefinedEventTypes.Default,
|
|
15
15
|
blockName: blockName,
|
|
16
16
|
});
|
|
17
17
|
const onClick = () => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { Fragment, useContext } from 'react';
|
|
2
2
|
import { Icon } from '@gravity-ui/uikit';
|
|
3
3
|
import { block, getLinkProps, setUrlTld } from '../../utils';
|
|
4
|
+
import { PredefinedEventTypes, } from '../../models';
|
|
4
5
|
import { Chevron } from '../../icons';
|
|
5
6
|
import FileLink from '../FileLink/FileLink';
|
|
6
7
|
import BackLink from '../BackLink/BackLink';
|
|
@@ -8,7 +9,6 @@ import { LocaleContext } from '../../context/localeContext/localeContext';
|
|
|
8
9
|
import { LocationContext } from '../../context/locationContext/locationContext';
|
|
9
10
|
import { useMetrika } from '../../hooks/useMetrika';
|
|
10
11
|
import { useAnalytics } from '../../hooks';
|
|
11
|
-
import { DEFAULT_EVENT_TYPE } from '../../constants';
|
|
12
12
|
import './Link.css';
|
|
13
13
|
const b = block('link-block');
|
|
14
14
|
const WORD_JOINER_SYM = '\u200b';
|
|
@@ -30,7 +30,7 @@ const LinkBlock = (props) => {
|
|
|
30
30
|
const handleMetrika = useMetrika();
|
|
31
31
|
const handleAnalytics = useAnalytics({
|
|
32
32
|
name: 'link-click',
|
|
33
|
-
type:
|
|
33
|
+
type: PredefinedEventTypes.Default,
|
|
34
34
|
blockName: blockName,
|
|
35
35
|
});
|
|
36
36
|
const { hostname } = useContext(LocationContext);
|
|
@@ -3,14 +3,13 @@ import ReactPlayer from 'react-player';
|
|
|
3
3
|
import React, { useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState, } from 'react';
|
|
4
4
|
import { Icon } from '@gravity-ui/uikit';
|
|
5
5
|
import { block } from '../../utils';
|
|
6
|
-
import { PlayButtonThemes, PlayButtonType, MediaVideoControlsType, } from '../../models';
|
|
6
|
+
import { PlayButtonThemes, PlayButtonType, MediaVideoControlsType, PredefinedEventTypes, } from '../../models';
|
|
7
7
|
import CustomBarControls from './CustomBarControls';
|
|
8
8
|
import { VideoContext } from '../../context/videoContext';
|
|
9
9
|
import { MetrikaContext } from '../../context/metrikaContext';
|
|
10
10
|
import { MobileContext } from '../../context/mobileContext';
|
|
11
11
|
import { PlayVideo } from '../../icons';
|
|
12
12
|
import { useAnalytics } from '../../hooks';
|
|
13
|
-
import { DEFAULT_EVENT_TYPE } from '../../constants';
|
|
14
13
|
import './ReactPlayer.css';
|
|
15
14
|
const b = block('ReactPlayer');
|
|
16
15
|
const FPS = 60;
|
|
@@ -36,7 +35,7 @@ export const ReactPlayerBlock = React.forwardRef((props, originRef) => {
|
|
|
36
35
|
const [ended, setEnded] = useState(false);
|
|
37
36
|
const handleAnalytics = useAnalytics({
|
|
38
37
|
name: 'react-player-controls-click',
|
|
39
|
-
type:
|
|
38
|
+
type: PredefinedEventTypes.Default,
|
|
40
39
|
blockName: blockName,
|
|
41
40
|
});
|
|
42
41
|
useImperativeHandle(originRef, () => ({
|
|
@@ -87,8 +86,8 @@ export const ReactPlayerBlock = React.forwardRef((props, originRef) => {
|
|
|
87
86
|
window.removeEventListener('resize', updateSize);
|
|
88
87
|
};
|
|
89
88
|
}, []);
|
|
90
|
-
const playEvents = useMemo(() => analyticsEvents === null || analyticsEvents === void 0 ? void 0 : analyticsEvents.filter((e) => e.type ===
|
|
91
|
-
const stopEvents = useMemo(() => analyticsEvents === null || analyticsEvents === void 0 ? void 0 : analyticsEvents.filter((e) => e.type ===
|
|
89
|
+
const playEvents = useMemo(() => analyticsEvents === null || analyticsEvents === void 0 ? void 0 : analyticsEvents.filter((e) => e.type === PredefinedEventTypes.Play), [analyticsEvents]);
|
|
90
|
+
const stopEvents = useMemo(() => analyticsEvents === null || analyticsEvents === void 0 ? void 0 : analyticsEvents.filter((e) => e.type === PredefinedEventTypes.Stop), [analyticsEvents]);
|
|
92
91
|
const playIcon = useMemo(() => {
|
|
93
92
|
let playButtonContent;
|
|
94
93
|
switch (type) {
|
|
@@ -4,8 +4,8 @@ import { LocaleContext } from '../../context/localeContext';
|
|
|
4
4
|
import { MobileContext } from '../../context/mobileContext';
|
|
5
5
|
import { block } from '../../utils';
|
|
6
6
|
import { useMetrika } from '../../hooks/useMetrika';
|
|
7
|
+
import { PredefinedEventTypes } from '../../models/common';
|
|
7
8
|
import { useAnalytics } from '../../hooks';
|
|
8
|
-
import { DEFAULT_EVENT_TYPE } from '../../constants';
|
|
9
9
|
export const YANDEX_FORM_ORIGIN = 'https://forms.yandex.ru';
|
|
10
10
|
const CONTAINER_ID = 'pc-yandex-form-container';
|
|
11
11
|
const COMPONENT_NAME = 'yandex-form';
|
|
@@ -18,7 +18,7 @@ const YandexForm = (props) => {
|
|
|
18
18
|
const handleMetrika = useMetrika();
|
|
19
19
|
const handleAnalytics = useAnalytics({
|
|
20
20
|
name: 'yndex-form-submit',
|
|
21
|
-
type:
|
|
21
|
+
type: PredefinedEventTypes.Default,
|
|
22
22
|
blockName: blockName,
|
|
23
23
|
});
|
|
24
24
|
const isMobile = useContext(MobileContext);
|
package/build/esm/constants.d.ts
CHANGED
package/build/esm/constants.js
CHANGED
|
@@ -5,13 +5,11 @@ export const useAnalytics = (defaultEvent) => {
|
|
|
5
5
|
if (!sendEvents) {
|
|
6
6
|
return undefined;
|
|
7
7
|
}
|
|
8
|
+
const defaultEvents = defaultEvent ? [defaultEvent] : [];
|
|
8
9
|
return (e) => {
|
|
9
|
-
let events =
|
|
10
|
-
if (
|
|
11
|
-
events = Array.isArray(e) ? [...
|
|
12
|
-
}
|
|
13
|
-
else if (e) {
|
|
14
|
-
events = e;
|
|
10
|
+
let events = defaultEvents;
|
|
11
|
+
if (e) {
|
|
12
|
+
events = Array.isArray(e) ? [...events, ...e] : [...events, e];
|
|
15
13
|
}
|
|
16
14
|
if (!events) {
|
|
17
15
|
return;
|
|
@@ -68,6 +68,11 @@ export type AnalyticsParameter = {
|
|
|
68
68
|
key: string;
|
|
69
69
|
value: string | number | boolean;
|
|
70
70
|
};
|
|
71
|
+
export declare enum PredefinedEventTypes {
|
|
72
|
+
Default = "default-event",
|
|
73
|
+
Play = "play",
|
|
74
|
+
Stop = "stop"
|
|
75
|
+
}
|
|
71
76
|
export type AnalyticsCounters = {
|
|
72
77
|
include?: string[];
|
|
73
78
|
exclude?: string[];
|
|
@@ -27,3 +27,9 @@ export var PixelEventType;
|
|
|
27
27
|
PixelEventType["Subscribe"] = "Subscribe";
|
|
28
28
|
PixelEventType["ViewContent"] = "ViewContent";
|
|
29
29
|
})(PixelEventType || (PixelEventType = {}));
|
|
30
|
+
export var PredefinedEventTypes;
|
|
31
|
+
(function (PredefinedEventTypes) {
|
|
32
|
+
PredefinedEventTypes["Default"] = "default-event";
|
|
33
|
+
PredefinedEventTypes["Play"] = "play";
|
|
34
|
+
PredefinedEventTypes["Stop"] = "stop";
|
|
35
|
+
})(PredefinedEventTypes || (PredefinedEventTypes = {}));
|
|
@@ -3,10 +3,9 @@ import { block } from '../../utils';
|
|
|
3
3
|
import { ThemeValueContext } from '../../context/theme/ThemeValueContext';
|
|
4
4
|
import { MobileContext } from '../../context/mobileContext';
|
|
5
5
|
import { useMetrika } from '../../hooks/useMetrika';
|
|
6
|
-
import { SubBlockType } from '../../models';
|
|
6
|
+
import { PredefinedEventTypes, SubBlockType } from '../../models';
|
|
7
7
|
import { useHandleHubspotEvents, useAnalytics } from '../../hooks';
|
|
8
8
|
import HubspotFormContainer from './HubspotFormContainer';
|
|
9
|
-
import { DEFAULT_EVENT_TYPE } from '../../constants';
|
|
10
9
|
import './HubspotForm.css';
|
|
11
10
|
const b = block('hubspot-form');
|
|
12
11
|
const HubspotForm = (props) => {
|
|
@@ -16,7 +15,7 @@ const HubspotForm = (props) => {
|
|
|
16
15
|
const handleMetrika = useMetrika();
|
|
17
16
|
const handleAnalytics = useAnalytics({
|
|
18
17
|
name: 'hubspot-form-submit',
|
|
19
|
-
type:
|
|
18
|
+
type: PredefinedEventTypes.Default,
|
|
20
19
|
blockName: blockName,
|
|
21
20
|
});
|
|
22
21
|
const { themeValue } = useContext(ThemeValueContext);
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import React, { useCallback, useContext } from 'react';
|
|
2
2
|
import { Button } from '@gravity-ui/uikit';
|
|
3
3
|
import { block, getThemedValue } from '../../utils';
|
|
4
|
-
import { AuthorType, SubBlockType } from '../../models';
|
|
4
|
+
import { AuthorType, SubBlockType, PredefinedEventTypes } from '../../models';
|
|
5
5
|
import { Author, Image, HTML } from '../../components';
|
|
6
6
|
import { ThemeValueContext } from '../../context/theme/ThemeValueContext';
|
|
7
7
|
import { getMediaImage } from '../../components/Media/Image/utils';
|
|
8
8
|
import { useAnalytics } from '../../hooks';
|
|
9
|
-
import { DEFAULT_EVENT_TYPE } from '../../constants';
|
|
10
9
|
import './Quote.css';
|
|
11
10
|
const b = block('quote');
|
|
12
11
|
const Quote = (props) => {
|
|
@@ -16,7 +15,7 @@ const Quote = (props) => {
|
|
|
16
15
|
const imageData = getMediaImage(imageThemed);
|
|
17
16
|
const handleAnalytics = useAnalytics({
|
|
18
17
|
name: 'quote-button-click',
|
|
19
|
-
type:
|
|
18
|
+
type: PredefinedEventTypes.Default,
|
|
20
19
|
blockName: blockName,
|
|
21
20
|
});
|
|
22
21
|
const handleButtonClick = useCallback(() => handleAnalytics === null || handleAnalytics === void 0 ? void 0 : handleAnalytics(), [handleAnalytics]);
|
package/package.json
CHANGED
|
@@ -68,6 +68,11 @@ export type AnalyticsParameter = {
|
|
|
68
68
|
key: string;
|
|
69
69
|
value: string | number | boolean;
|
|
70
70
|
};
|
|
71
|
+
export declare enum PredefinedEventTypes {
|
|
72
|
+
Default = "default-event",
|
|
73
|
+
Play = "play",
|
|
74
|
+
Stop = "stop"
|
|
75
|
+
}
|
|
71
76
|
export type AnalyticsCounters = {
|
|
72
77
|
include?: string[];
|
|
73
78
|
exclude?: string[];
|
package/server/models/common.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PixelEventType = exports.Theme = void 0;
|
|
3
|
+
exports.PredefinedEventTypes = exports.PixelEventType = exports.Theme = void 0;
|
|
4
4
|
var Theme;
|
|
5
5
|
(function (Theme) {
|
|
6
6
|
Theme["Light"] = "light";
|
|
@@ -30,3 +30,9 @@ var PixelEventType;
|
|
|
30
30
|
PixelEventType["Subscribe"] = "Subscribe";
|
|
31
31
|
PixelEventType["ViewContent"] = "ViewContent";
|
|
32
32
|
})(PixelEventType = exports.PixelEventType || (exports.PixelEventType = {}));
|
|
33
|
+
var PredefinedEventTypes;
|
|
34
|
+
(function (PredefinedEventTypes) {
|
|
35
|
+
PredefinedEventTypes["Default"] = "default-event";
|
|
36
|
+
PredefinedEventTypes["Play"] = "play";
|
|
37
|
+
PredefinedEventTypes["Stop"] = "stop";
|
|
38
|
+
})(PredefinedEventTypes = exports.PredefinedEventTypes || (exports.PredefinedEventTypes = {}));
|