diff --git a/README.md b/README.md index d8ba49b..f4ca7ef 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, @@ -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,6 +363,7 @@ export interface MetrikaCounter { trackHash?: boolean; ecommerce?: boolean | string; type?: 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 ab82bfe..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 { @@ -73,6 +73,7 @@ export function renderMetrika(params: MetrikaPluginOptions, utils: RenderHelpers ecommerce: ${config.ecommerce}, type: ${Number(config.type)}, experiments: "${config.encryptedExperiments || ''}" + userParams: ${JSON.stringify(config.userParams || {})} }); `, ) diff --git a/src/plugins/yandex-metrika/types.ts b/src/plugins/yandex-metrika/types.ts index 411999c..d92cbee 100644 --- a/src/plugins/yandex-metrika/types.ts +++ b/src/plugins/yandex-metrika/types.ts @@ -1,3 +1,7 @@ +export type UserParams = { + [x: string]: boolean | string | number | null | UserParams; +}; + export interface MetrikaCounter { id: number; /** @default false */ @@ -20,6 +24,8 @@ export interface MetrikaCounter { ecommerce?: boolean | string; /** @default 0 */ type?: number; + /** @default {} */ + userParams?: UserParams; } export type MetrikaPluginOptions = {