From bde317236dd07d1bf1fd044c8dee1c7bf612cd0b Mon Sep 17 00:00:00 2001 From: ngorin Date: Tue, 14 Nov 2023 14:57:02 +0300 Subject: [PATCH 1/7] feat: add userParams prop in yaMetrika init --- README.md | 5 ++++- package.json | 3 ++- src/plugins/yandex-metrika/index.ts | 1 + src/plugins/yandex-metrika/types.ts | 4 ++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d8ba49b..9281771 100644 --- a/README.md +++ b/README.md @@ -328,7 +328,7 @@ app.get((req, res) => { renderLayout({ title: 'Home page', pluginsOptions: { - yandexMetrica: { + yandexMetrika: { counter: { id: 123123123, defer: true, @@ -359,6 +359,9 @@ export interface MetrikaCounter { trackHash?: boolean; ecommerce?: boolean | string; type?: number; + userParams?: { + [x: string]: boolean | string | number; + }; } export type MetrikaOptions = { diff --git a/package.json b/package.json index cc589ec..fd9e179 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,8 @@ "lint": "run-p lint:*", "lint:js": "eslint --report-unused-disable-directives .", "lint:exports": "npm run build && npm pack && attw gravity-ui-app-layout-${npm_package_version}.tgz", - "lint:other": "npm run prettier -- --check", + "lint:prettier": "npm run prettier -- --check", + "lint:prettier:fix": "npm run prettier -- --write", "prettier": "prettier '**/*.{md,yaml,yml,json}'", "typecheck": "tsc --noEmit", "test": "jest", diff --git a/src/plugins/yandex-metrika/index.ts b/src/plugins/yandex-metrika/index.ts index ab82bfe..958f12f 100644 --- a/src/plugins/yandex-metrika/index.ts +++ b/src/plugins/yandex-metrika/index.ts @@ -73,6 +73,7 @@ export function renderMetrika(params: MetrikaPluginOptions, utils: RenderHelpers ecommerce: ${config.ecommerce}, type: ${Number(config.type)}, experiments: "${config.encryptedExperiments || ''}" + userParams: "${config?.userParams || {}}" }); `, ) diff --git a/src/plugins/yandex-metrika/types.ts b/src/plugins/yandex-metrika/types.ts index 411999c..e8eac78 100644 --- a/src/plugins/yandex-metrika/types.ts +++ b/src/plugins/yandex-metrika/types.ts @@ -20,6 +20,10 @@ export interface MetrikaCounter { ecommerce?: boolean | string; /** @default 0 */ type?: number; + /** @default {} */ + userParams?: { + [x: string]: boolean | string | number; + }; } export type MetrikaPluginOptions = { From f5c0b1c2e9e73607470ae05049dfdd2bc007e2b0 Mon Sep 17 00:00:00 2001 From: Nikita Gorin <36075690+NikitaCG@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:56:59 +0300 Subject: [PATCH 2/7] Update src/plugins/yandex-metrika/index.ts commit suggestion Co-authored-by: Valerii Sidorenko --- src/plugins/yandex-metrika/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/yandex-metrika/index.ts b/src/plugins/yandex-metrika/index.ts index 958f12f..dfd49e3 100644 --- a/src/plugins/yandex-metrika/index.ts +++ b/src/plugins/yandex-metrika/index.ts @@ -73,7 +73,7 @@ export function renderMetrika(params: MetrikaPluginOptions, utils: RenderHelpers ecommerce: ${config.ecommerce}, type: ${Number(config.type)}, experiments: "${config.encryptedExperiments || ''}" - userParams: "${config?.userParams || {}}" + userParams: ${JSON.stringify(config?.userParams || {})} }); `, ) From abc307740f9abf9d5c0570714cde614469ab2148 Mon Sep 17 00:00:00 2001 From: ngorin Date: Tue, 14 Nov 2023 17:18:12 +0300 Subject: [PATCH 3/7] feat: update scripts --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fd9e179..41bf968 100644 --- a/package.json +++ b/package.json @@ -35,8 +35,8 @@ "lint:js": "eslint --report-unused-disable-directives .", "lint:exports": "npm run build && npm pack && attw gravity-ui-app-layout-${npm_package_version}.tgz", "lint:prettier": "npm run prettier -- --check", - "lint:prettier:fix": "npm run prettier -- --write", "prettier": "prettier '**/*.{md,yaml,yml,json}'", + "prettier:fix": "npm run prettier -- --write", "typecheck": "tsc --noEmit", "test": "jest", "build": "npm run build:clean && run-p build:compile:*", From 80c2743c421e2fd12b3f5436a8f56c84746a8ad5 Mon Sep 17 00:00:00 2001 From: ngorin Date: Tue, 14 Nov 2023 17:39:21 +0300 Subject: [PATCH 4/7] feat: revert adding scripts --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 41bf968..cc589ec 100644 --- a/package.json +++ b/package.json @@ -34,9 +34,8 @@ "lint": "run-p lint:*", "lint:js": "eslint --report-unused-disable-directives .", "lint:exports": "npm run build && npm pack && attw gravity-ui-app-layout-${npm_package_version}.tgz", - "lint:prettier": "npm run prettier -- --check", + "lint:other": "npm run prettier -- --check", "prettier": "prettier '**/*.{md,yaml,yml,json}'", - "prettier:fix": "npm run prettier -- --write", "typecheck": "tsc --noEmit", "test": "jest", "build": "npm run build:clean && run-p build:compile:*", From ff70a010c2e13d9ba139c882745483d35a2522da Mon Sep 17 00:00:00 2001 From: ngorin Date: Tue, 14 Nov 2023 18:10:58 +0300 Subject: [PATCH 5/7] feat: update types --- src/plugins/yandex-metrika/types.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/plugins/yandex-metrika/types.ts b/src/plugins/yandex-metrika/types.ts index e8eac78..1368a78 100644 --- a/src/plugins/yandex-metrika/types.ts +++ b/src/plugins/yandex-metrika/types.ts @@ -1,3 +1,7 @@ +type UserParams = { + [x: string]: boolean | string | number | null | UserParams; +}; + export interface MetrikaCounter { id: number; /** @default false */ @@ -21,9 +25,7 @@ export interface MetrikaCounter { /** @default 0 */ type?: number; /** @default {} */ - userParams?: { - [x: string]: boolean | string | number; - }; + userParams?: UserParams; } export type MetrikaPluginOptions = { From add45c1cefcb3f46757fc6ecb360b4d06493c52b Mon Sep 17 00:00:00 2001 From: Nikita Gorin <36075690+NikitaCG@users.noreply.github.com> Date: Tue, 14 Nov 2023 18:38:16 +0300 Subject: [PATCH 6/7] Update src/plugins/yandex-metrika/index.ts Co-authored-by: Valerii Sidorenko --- src/plugins/yandex-metrika/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/yandex-metrika/index.ts b/src/plugins/yandex-metrika/index.ts index dfd49e3..48be80a 100644 --- a/src/plugins/yandex-metrika/index.ts +++ b/src/plugins/yandex-metrika/index.ts @@ -73,7 +73,7 @@ export function renderMetrika(params: MetrikaPluginOptions, utils: RenderHelpers ecommerce: ${config.ecommerce}, type: ${Number(config.type)}, experiments: "${config.encryptedExperiments || ''}" - userParams: ${JSON.stringify(config?.userParams || {})} + userParams: ${JSON.stringify(config.userParams || {})} }); `, ) From 284ad8fa76cf36057170a2d75d59f3ebdce92b95 Mon Sep 17 00:00:00 2001 From: ngorin Date: Tue, 14 Nov 2023 19:02:21 +0300 Subject: [PATCH 7/7] feat: add UserParams type in export --- README.md | 8 +++++--- src/index.ts | 6 +++++- src/plugins/yandex-metrika/index.ts | 2 +- src/plugins/yandex-metrika/types.ts | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9281771..f4ca7ef 100644 --- a/README.md +++ b/README.md @@ -346,6 +346,10 @@ app.get((req, res) => { Plugin options: ```typescript +export type UserParams = { + [x: string]: boolean | string | number | null | UserParams; +}; + export interface MetrikaCounter { id: number; defer: boolean; @@ -359,9 +363,7 @@ export interface MetrikaCounter { trackHash?: boolean; ecommerce?: boolean | string; type?: number; - userParams?: { - [x: string]: boolean | string | number; - }; + userParams?: UserParams; } export type MetrikaOptions = { diff --git a/src/index.ts b/src/index.ts index ed30dc1..c6f42e3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,7 +18,11 @@ export type { RenderParams, } from './types.js'; -export type {MetrikaCounter, MetrikaPluginOptions} from './plugins/yandex-metrika/index.js'; +export type { + MetrikaCounter, + MetrikaPluginOptions, + UserParams, +} from './plugins/yandex-metrika/index.js'; export type { GoogleAnalyticsCounter, GoogleAnalyticsPluginOptions, diff --git a/src/plugins/yandex-metrika/index.ts b/src/plugins/yandex-metrika/index.ts index 48be80a..53a9a10 100644 --- a/src/plugins/yandex-metrika/index.ts +++ b/src/plugins/yandex-metrika/index.ts @@ -1,7 +1,7 @@ import type {Plugin, RenderHelpers} from '../../types.js'; import type {MetrikaCounter, MetrikaPluginOptions} from './types.js'; -export type {MetrikaCounter, MetrikaPluginOptions} from './types.js'; +export type {MetrikaCounter, MetrikaPluginOptions, UserParams} from './types.js'; export function createYandexMetrikaPlugin(): Plugin { return { diff --git a/src/plugins/yandex-metrika/types.ts b/src/plugins/yandex-metrika/types.ts index 1368a78..d92cbee 100644 --- a/src/plugins/yandex-metrika/types.ts +++ b/src/plugins/yandex-metrika/types.ts @@ -1,4 +1,4 @@ -type UserParams = { +export type UserParams = { [x: string]: boolean | string | number | null | UserParams; };