@artginzburg/next-ym 1.3.0 → 1.3.2
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 +25 -2
- package/dist/components/MetricaPixel.js +1 -2
- package/dist/components/MetricaPixel.js.map +1 -1
- package/dist/components/YandexMetricaProvider.js +1 -1
- package/dist/components/YandexMetricaProvider.js.map +1 -1
- package/dist/constants/defaults.d.ts +3 -0
- package/dist/constants/defaults.js +3 -0
- package/dist/constants/defaults.js.map +1 -1
- package/dist/lib/types/parameters.d.ts +16 -0
- package/package.json +12 -11
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Next.js Yandex Metrica
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/next-yandex-metrica)
|
|
4
|
-
[](https://codecov.io/gh/artginzburg/next-ym)
|
|
5
5
|
|
|
6
6
|
Yandex Metrica integration for Next.js v14+ (App Router)
|
|
7
7
|
|
|
@@ -17,11 +17,32 @@ Yandex Metrica integration for Next.js v14+ (App Router)
|
|
|
17
17
|
|
|
18
18
|
### Add the provider
|
|
19
19
|
|
|
20
|
+
#### App Router
|
|
21
|
+
|
|
22
|
+
```jsx
|
|
23
|
+
// app/layout.tsx
|
|
24
|
+
import { YandexMetricaProvider, standardYMInitParameters } from '@artginzburg/next-ym';
|
|
25
|
+
|
|
26
|
+
export default function RootLayout({ children }) {
|
|
27
|
+
return (
|
|
28
|
+
<html lang="en">
|
|
29
|
+
<body>
|
|
30
|
+
<YandexMetricaProvider initParameters={standardYMInitParameters}>
|
|
31
|
+
{children}
|
|
32
|
+
</YandexMetricaProvider>
|
|
33
|
+
</body>
|
|
34
|
+
</html>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### Pages Router
|
|
40
|
+
|
|
20
41
|
To enable analytics, include `YandexMetricaProvider` in the custom [`_app`](https://nextjs.org/docs/advanced-features/custom-app) component.
|
|
21
42
|
|
|
22
43
|
```jsx
|
|
23
44
|
// pages/_app.tsx
|
|
24
|
-
import { YandexMetricaProvider } from 'next-
|
|
45
|
+
import { YandexMetricaProvider } from '@artginzburg/next-ym';
|
|
25
46
|
|
|
26
47
|
export default function MyApp({ Component, pageProps }) {
|
|
27
48
|
return (
|
|
@@ -35,6 +56,8 @@ export default function MyApp({ Component, pageProps }) {
|
|
|
35
56
|
}
|
|
36
57
|
```
|
|
37
58
|
|
|
59
|
+
> **Note:** `YandexMetricaProvider` uses the `"use client"` directive.
|
|
60
|
+
|
|
38
61
|
#### `YandexMetricaProvider` Props
|
|
39
62
|
|
|
40
63
|
| Name | Description |
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import Image from 'next/image';
|
|
3
2
|
/** @todo shouldUseAlternativeCDN */
|
|
4
|
-
export const MetricaPixel = ({ tagID }) => (_jsx("div", { children: _jsx(
|
|
3
|
+
export const MetricaPixel = ({ tagID }) => (_jsx("div", { children: _jsx("img", { src: `https://mc.yandex.ru/watch/${tagID}`, style: { position: 'absolute', left: -9999 }, alt: "" }) }));
|
|
5
4
|
//# sourceMappingURL=MetricaPixel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetricaPixel.js","sourceRoot":"","sources":["../../src/components/MetricaPixel.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"MetricaPixel.js","sourceRoot":"","sources":["../../src/components/MetricaPixel.tsx"],"names":[],"mappings":";AAMA,oCAAoC;AACpC,MAAM,CAAC,MAAM,YAAY,GAA0B,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAChE,wBACE,cACE,GAAG,EAAE,8BAA8B,KAAK,EAAE,EAC1C,KAAK,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,EAC5C,GAAG,EAAC,EAAE,GACN,GACE,CACP,CAAC"}
|
|
@@ -19,7 +19,7 @@ export const YandexMetricaProvider = ({ children, tagID, strategy = 'afterIntera
|
|
|
19
19
|
? 'https://cdn.jsdelivr.net/npm/yandex-metrica-watch/tag.js'
|
|
20
20
|
: 'https://mc.yandex.ru/metrika/tag.js';
|
|
21
21
|
const sharedInit = `
|
|
22
|
-
ym(${id}, "init", ${JSON.stringify(initParameters !== null && initParameters !== void 0 ? initParameters : {})});
|
|
22
|
+
ym(${id}, "init", Object.assign({referrer: document.referrer, url: location.href}, ${JSON.stringify(initParameters !== null && initParameters !== void 0 ? initParameters : {})}));
|
|
23
23
|
${initEcommerce(initParameters === null || initParameters === void 0 ? void 0 : initParameters.ecommerce)}
|
|
24
24
|
`;
|
|
25
25
|
return (_jsxs(_Fragment, { children: [(experimental === null || experimental === void 0 ? void 0 : experimental.nextJsNativeLoading) ? (_jsxs(_Fragment, { children: [_jsx(Script, { id: "yandex-metrika-init", strategy: "beforeInteractive", children: `
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"YandexMetricaProvider.js","sourceRoot":"","sources":["../../src/components/YandexMetricaProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,MAAuB,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,aAAa,EAAiB,OAAO,EAAE,MAAM,OAAO,CAAC;AAI9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,CAAC,MAAM,mBAAmB,GAAG,aAAa,CAAgB,IAAI,CAAC,CAAC;AACtE,MAAM,CAAC,MAAM,uBAAuB,GAAG,aAAa,CAAgB,IAAI,CAAC,CAAC;AAmB1E,4RAA4R;AAC5R,MAAM,CAAC,MAAM,qBAAqB,GAAmC,CAAC,EACpE,QAAQ,EACR,KAAK,EACL,QAAQ,GAAG,kBAAkB,EAC7B,cAAc,EACd,uBAAuB,GAAG,KAAK,EAC/B,YAAY,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YAC3C;;;;;0CAK+B,SAAS;YACvC,UAAU;SACb,GACQ,CACV,EACD,mBAAU,EAAE,EAAC,sBAAsB,YACjC,KAAC,YAAY,IAAC,KAAK,EAAE,EAAE,GAAI,GAClB,EACX,KAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,YACpC,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,SAAS,EAAC,CAAC,CAAC,CAC3B,KAAC,uBAAuB,CAAC,QAAQ,IAC/B,KAAK,EACH,OAAO,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,SAAS,CAAA,KAAK,QAAQ;wBAC3C,CAAC,CAAC,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,SAAS;wBAC3B,CAAC,CAAC,WAAW,YAGhB,QAAQ,GACwB,CACpC,CAAC,CAAC,CAAC,CACF,QAAQ,CACT,GAC4B,IAC9B,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,SAAS,aAAa,CAAC,cAA2C;IAChE,IAAI,CAAC,cAAc;QAAE,OAAO,EAAE,CAAC;IAE/B,MAAM,aAAa,GAAG,OAAO,cAAc,KAAK,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,WAAW,CAAC;IACxF,OAAO,UAAU,aAAa,aAAa,aAAa,SAAS,CAAC;AACpE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/constants/defaults.ts"],"names":[],"mappings":"AAEA,wFAAwF;AACxF,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE,IAAI;IAChB,mBAAmB,EAAE,IAAI;
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/constants/defaults.ts"],"names":[],"mappings":"AAEA,wFAAwF;AACxF,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE,IAAI;IAChB,mBAAmB,EAAE,IAAI;IACzB,QAAQ,EAAE,IAAI;IACd,GAAG,EAAE,IAAI;IACT,SAAS,EAAE,WAAW;CACE,CAAC"}
|
|
@@ -86,6 +86,22 @@ export interface InitParameters {
|
|
|
86
86
|
* @default false
|
|
87
87
|
*/
|
|
88
88
|
triggerEvent?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Enable SSR-compatible mode. The tag won't send a pageview on init,
|
|
91
|
+
* relying on SPA navigation events instead.
|
|
92
|
+
* @default false
|
|
93
|
+
*/
|
|
94
|
+
ssr?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Override the referrer sent with the init hit.
|
|
97
|
+
* Useful for SSR where `document.referrer` may not be available at init time.
|
|
98
|
+
*/
|
|
99
|
+
referrer?: string;
|
|
100
|
+
/**
|
|
101
|
+
* Override the URL sent with the init hit.
|
|
102
|
+
* Useful for SSR where `location.href` may not reflect the correct page.
|
|
103
|
+
*/
|
|
104
|
+
url?: string;
|
|
89
105
|
}
|
|
90
106
|
export interface FirstPartyParamsParameters {
|
|
91
107
|
email?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artginzburg/next-ym",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Yandex Metrica integration for Next.js v14",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -29,6 +29,16 @@
|
|
|
29
29
|
"metrika",
|
|
30
30
|
"analytics"
|
|
31
31
|
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "del-cli dist && tsc",
|
|
34
|
+
"prepublishOnly": "pnpm build",
|
|
35
|
+
"lint": "eslint src --fix --max-warnings 0",
|
|
36
|
+
"lint:ts": "tsc --noEmit",
|
|
37
|
+
"test": "jest",
|
|
38
|
+
"test:ci": "jest --ci --coverage",
|
|
39
|
+
"format": "prettier --write --log-level silent .",
|
|
40
|
+
"format:check": "prettier --check ."
|
|
41
|
+
},
|
|
32
42
|
"devDependencies": {
|
|
33
43
|
"@artginzburg/experimental": "^0.1.6",
|
|
34
44
|
"@testing-library/jest-dom": "^6.1.5",
|
|
@@ -61,14 +71,5 @@
|
|
|
61
71
|
},
|
|
62
72
|
"publishConfig": {
|
|
63
73
|
"access": "public"
|
|
64
|
-
},
|
|
65
|
-
"scripts": {
|
|
66
|
-
"build": "del-cli dist && tsc",
|
|
67
|
-
"lint": "eslint src --fix --max-warnings 0",
|
|
68
|
-
"lint:ts": "tsc --noEmit",
|
|
69
|
-
"test": "jest",
|
|
70
|
-
"test:ci": "jest --ci --coverage",
|
|
71
|
-
"format": "prettier --write --log-level silent .",
|
|
72
|
-
"format:check": "prettier --check ."
|
|
73
74
|
}
|
|
74
|
-
}
|
|
75
|
+
}
|