nuxt-yandex-metrika 1.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) TakNePoidet <yakin95@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,158 @@
1
+ <!--
2
+ Find and replace all on all files (CMD+SHIFT+F):
3
+ - Name: Yandex Metrika
4
+ - Package name: nuxt-yandex-metrika
5
+ - Description: Yandex Metrika for Nuxt 3
6
+ -->
7
+
8
+ # Yandex Metrika for Nuxt 3
9
+
10
+ [![npm version][npm-version-src]][npm-version-href]
11
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
12
+ [![License][license-src]][license-href]
13
+ [![Nuxt][nuxt-src]][nuxt-href]
14
+
15
+ ## Quick Setup
16
+
17
+ 1. Add `nuxt-yandex-metrika` dependency to your project
18
+
19
+ ```bash
20
+ # Using pnpm
21
+ pnpm add -D nuxt-yandex-metrika
22
+
23
+ # Using yarn
24
+ yarn add --dev nuxt-yandex-metrika
25
+
26
+ # Using npm
27
+ npm install --save-dev nuxt-yandex-metrika
28
+ ```
29
+
30
+ 2. Add `nuxt-yandex-metrika` to the `modules` section of `nuxt.config.ts`
31
+
32
+ ```ts
33
+ export default defineNuxtConfig({
34
+ modules: ["nuxt-yandex-metrika"],
35
+ });
36
+ ```
37
+
38
+ ## Configure
39
+
40
+ ```ts
41
+ {
42
+ modules: ["nuxt-yandex-metrika"],
43
+ yandexMetrika: {
44
+ id: 'XXXXXX',
45
+ // debug: process.env.NODE_ENV !== "production",
46
+ // delay: 0,
47
+ // cdn: false,
48
+ // options: {
49
+ // webvisor: true
50
+ // },
51
+ }
52
+ }
53
+ ```
54
+
55
+ ## Options
56
+
57
+ | Name | Default value | Type | Description |
58
+ |---------------------|---------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------|
59
+ | accurateTrackBounce | true | Boolean | Number | Accurate bounce rate The parameter can accept these values: true — Enable the accurate bounce rate, with a non-bounce event registered after 15000 ms (15 s). false — Don't enable the accurate bounce rate. <N> (integer) — Enable the accurate bounce rate. Non-bounce events are recorded after <N> ms. |
60
+ | childIframe | false | Boolean | Whether to record iframe contents without a tag in a child window |
61
+ | clickmap | true | Boolean | Whether to collect data for a click map |
62
+ | defer | false | Boolean | Whether to disable automatically sending data during tag initialization |
63
+ | ecommerce | false | Boolean | String | Array | Collect data for e-commerce — Ecommerce. true — Enable e-commerce data collection. Data is transmitted via a JavaScript array named dataLayer in the global namespace (window.dataLayer) false — Disable Ecommerce data collection. <objectName> (String) — Enable Ecommerce data collection. Data is transmitted via a JavaScript array named <objectName> in the global namespace (window.<objectName>) <array> (Array) — Enable Ecommerce data collection. Data is transmitted via a JavaScript <array> |
64
+ | params | — | Object | Array | Session parameters transmitted during tag initialization To transmit session parameters at any other time, use the params method |
65
+ | userParams | — | Object | Parameters of site users that are transmitted when initializing the tag To transmit user parameters at any other time, use the userParams method |
66
+ | trackHash | false | Boolean | Hash tracking in the browser's address bar |
67
+ | trackLinks | true | Boolean | Track clicks on outbound links |
68
+ | trustedDomains | — | Array | Indicates a trusted domain for recording the contents of a child iframe. Contains the domain address of the parent window |
69
+ | type | 0 | Number | Tag type. 1 for YAN |
70
+ | webvisor | false | Boolean | Whether to use Session Replay |
71
+ | triggerEvent | false | Boolean | Whether to check if the tag is ready |
72
+
73
+ For more information:
74
+
75
+ - [Documentation for Ya.Metrika](https://yandex.com/support/metrica/code/counter-initialize.html)
76
+
77
+ ## Usage
78
+
79
+ | Component Name | Auto Imported | Description |
80
+ |-----------------------------|---------------|----------------|
81
+ | `<YandexMetrikaInformer />` | ✅ | Shows informer |
82
+
83
+ ### Methods
84
+
85
+ ```vue
86
+ <template>
87
+ <button @click.prevent.stop="reachGoal('click', {})">click</button>
88
+ </template>
89
+
90
+ <script setup lang="ts">
91
+ import { useYandexMetrika } from "#imports";
92
+
93
+ const { reachGoal } = useYandexMetrika();
94
+ </script>
95
+ ```
96
+
97
+ - [For more information](https://yandex.com/support/metrica/objects/method-reference.html?lang=en)
98
+
99
+ ## Development
100
+
101
+ ```bash
102
+ # Install dependencies
103
+ npm install
104
+
105
+ # Generate type stubs
106
+ npm run dev:prepare
107
+
108
+ # Develop with the playground
109
+ npm run dev
110
+
111
+ # Build the playground
112
+ npm run dev:build
113
+
114
+ # Run ESLint
115
+ npm run lint
116
+
117
+ # Run Vitest
118
+ npm run test
119
+ npm run test:watch
120
+
121
+ # Release new version
122
+ npm run release
123
+ ```
124
+
125
+ ## Contributing
126
+
127
+ Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.
128
+
129
+ 1. Fork the Project
130
+ 2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
131
+ 3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
132
+ 4. Push to the Branch (`git push origin feature/AmazingFeature`)
133
+ 5. Open a Pull Request
134
+
135
+ # Contact
136
+
137
+ Yakin Nikita - [@TakNePoidet](https://t.me/TakNePoidet)
138
+
139
+ # Contributors
140
+
141
+ <a href="https://github.com/TakNePoidet/nuxt-yandex-metrika/graphs/contributors">
142
+ <img src="https://contrib.rocks/image?repo=TakNePoidet/nuxt-yandex-metrika" />
143
+ </a>
144
+
145
+ ## License
146
+
147
+ [MIT License](./LICENSE)
148
+
149
+ <!-- Badges -->
150
+
151
+ [npm-version-src]: https://img.shields.io/npm/v/nuxt-yandex-metrika/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
152
+ [npm-version-href]: https://npmjs.com/package/nuxt-yandex-metrika
153
+ [npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-yandex-metrika.svg?style=flat&colorA=18181B&colorB=28CF8D
154
+ [npm-downloads-href]: https://npmjs.com/package/nuxt-yandex-metrika
155
+ [license-src]: https://img.shields.io/npm/l/nuxt-yandex-metrika.svg?style=flat&colorA=18181B&colorB=28CF8D
156
+ [license-href]: https://npmjs.com/package/nuxt-yandex-metrika
157
+ [nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js
158
+ [nuxt-href]: https://nuxt.com
@@ -0,0 +1,5 @@
1
+ module.exports = function(...args) {
2
+ return import('./module.mjs').then(m => m.default.call(this, ...args))
3
+ }
4
+ const _meta = module.exports.meta = require('./module.json')
5
+ module.exports.getMeta = () => Promise.resolve(_meta)
@@ -0,0 +1,46 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+
3
+ declare global {
4
+ interface Window {
5
+ ym: ((...args: any[]) => void) & {
6
+ a: any[];
7
+ l: number;
8
+ };
9
+ }
10
+ }
11
+ interface VisitParameters {
12
+ order_price?: number;
13
+ currency?: string;
14
+ [key: string]: any;
15
+ }
16
+ interface UserParameters {
17
+ UserID?: number;
18
+ [key: string]: any;
19
+ }
20
+ interface InitParameters {
21
+ accurateTrackBounce?: boolean | number;
22
+ childIframe?: boolean;
23
+ clickmap?: boolean;
24
+ defer?: boolean;
25
+ ecommerce?: boolean | string | any[];
26
+ params?: VisitParameters | VisitParameters[];
27
+ userParams?: UserParameters;
28
+ trackHash?: boolean;
29
+ trackLinks?: boolean;
30
+ trustedDomains?: string[];
31
+ type?: number;
32
+ webvisor?: boolean;
33
+ triggerEvent?: boolean;
34
+ }
35
+
36
+ type YandexMetrikaModuleOptions = {
37
+ id: string;
38
+ debug: boolean;
39
+ cdn: boolean;
40
+ delay: number;
41
+ options: Partial<InitParameters>;
42
+ };
43
+
44
+ declare const _default: _nuxt_schema.NuxtModule<YandexMetrikaModuleOptions>;
45
+
46
+ export { _default as default };
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "nuxt-yandex-metrika",
3
+ "version": "1.0.1",
4
+ "configKey": "yandexMetrika",
5
+ "compatibility": {
6
+ "nuxt": "^3"
7
+ }
8
+ }
@@ -0,0 +1,42 @@
1
+ import { defineNuxtModule, createResolver, addPlugin, addComponent, addImportsDir } from '@nuxt/kit';
2
+ import { defu } from 'defu';
3
+
4
+ const name = "nuxt-yandex-metrika";
5
+ const version = "1.0.1";
6
+
7
+ const module = defineNuxtModule({
8
+ meta: {
9
+ name,
10
+ version,
11
+ configKey: "yandexMetrika",
12
+ compatibility: {
13
+ nuxt: "^3"
14
+ }
15
+ },
16
+ // Default configuration options of the Nuxt module
17
+ defaults: {
18
+ id: "xxx",
19
+ debug: process.env.NODE_ENV !== "production",
20
+ delay: 0,
21
+ cdn: false,
22
+ options: {}
23
+ },
24
+ setup(options, nuxt) {
25
+ nuxt.options.runtimeConfig.public.yandexMetrika = defu(
26
+ nuxt.options.runtimeConfig.public.yandexMetrika ?? {},
27
+ options
28
+ );
29
+ const resolver = createResolver(import.meta.url);
30
+ addPlugin({
31
+ mode: "all",
32
+ src: resolver.resolve("./runtime/plugin")
33
+ });
34
+ void addComponent({
35
+ name: "yandex-metrika-informer",
36
+ filePath: resolver.resolve("./runtime/yandex-metrika-informer.vue")
37
+ });
38
+ addImportsDir(resolver.resolve("runtime/composables"));
39
+ }
40
+ });
41
+
42
+ export { module as default };
@@ -0,0 +1,2 @@
1
+ import { YandexMetrika } from "../../yandex-metrika";
2
+ export declare function useYandexMetrika(): YandexMetrika;
@@ -0,0 +1,5 @@
1
+ import { useNuxtApp } from "#imports";
2
+ export function useYandexMetrika() {
3
+ const { $yandexMetrika } = useNuxtApp();
4
+ return $yandexMetrika;
5
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,90 @@
1
+ import {
2
+ defineNuxtPlugin,
3
+ useHead,
4
+ useRouter,
5
+ useRuntimeConfig
6
+ } from "#imports";
7
+ import { Methods, YandexMetrika } from "../yandex-metrika";
8
+ export default defineNuxtPlugin({
9
+ parallel: true,
10
+ setup() {
11
+ const config = useRuntimeConfig().public.yandexMetrika;
12
+ const { id, cdn = false, delay = 0, debug, options = {} } = config;
13
+ if (!debug) {
14
+ useHead({
15
+ noscript: [
16
+ {
17
+ innerHTML: `<div><img src="https://mc.yandex.ru/watch/${id}" style="position:absolute; left:-9999px;" alt="" />`
18
+ }
19
+ ]
20
+ });
21
+ }
22
+ function useYandexMetrikaHead() {
23
+ }
24
+ if (debug || delay) {
25
+ useHead({
26
+ script: [
27
+ {
28
+ innerHTML: `window.ym=window.ym||function(){(window.ym.a=window.ym.a||[]).push(arguments)};window.ym.l=(new Date).getTime();`
29
+ },
30
+ {
31
+ innerHTML: `ym("${id}","${Methods.Init}", ${JSON.stringify(
32
+ options
33
+ )});`
34
+ }
35
+ ]
36
+ });
37
+ } else {
38
+ useHead({
39
+ script: [
40
+ {
41
+ innerHTML: `(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)}; m[i].l=1*new Date(); for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }} k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)}) (window, document, "script", "${YandexMetrika.src(
42
+ cdn
43
+ )}", "ym");`
44
+ }
45
+ ]
46
+ });
47
+ }
48
+ if (!debug && delay && process.client) {
49
+ setTimeout(() => {
50
+ useHead({
51
+ script: [
52
+ {
53
+ defer: true,
54
+ src: YandexMetrika.src(cdn)
55
+ }
56
+ ]
57
+ });
58
+ }, delay);
59
+ }
60
+ const yandexMetrika = new YandexMetrika(id);
61
+ yandexMetrika.debug = debug;
62
+ if (process.client) {
63
+ let ready = false;
64
+ const router = useRouter();
65
+ void router.isReady().then(() => {
66
+ ready = true;
67
+ });
68
+ router.afterEach((to, from) => {
69
+ if (!ready) {
70
+ return;
71
+ }
72
+ yandexMetrika.hit(to.fullPath, {
73
+ referer: from.fullPath
74
+ });
75
+ });
76
+ }
77
+ return {
78
+ provide: {
79
+ yandexMetrika: new Proxy(yandexMetrika, {
80
+ get(target, name) {
81
+ if (typeof target[name] === "function") {
82
+ return target[name].bind(target);
83
+ }
84
+ return target[name];
85
+ }
86
+ })
87
+ }
88
+ };
89
+ }
90
+ });
@@ -0,0 +1,22 @@
1
+ <script setup lang="ts">
2
+ import { useYandexMetrika } from "./composables/useYandexMetrika";
3
+ const { id } = useYandexMetrika();
4
+ </script>
5
+
6
+ <template>
7
+ <!-- Yandex.Metrika informer -->
8
+ <a
9
+ :href="`https://metrika.yandex.ru/stat/?id=${id}&amp;from=informer`"
10
+ target="_blank"
11
+ rel="nofollow"
12
+ ><img
13
+ :src="`https://informer.yandex.ru/informer/${id}/3_1_FFFFFFFF_EFEFEFFF_0_pageviews`"
14
+ style="width: 88px; height: 31px; border: 0"
15
+ alt="Яндекс.Метрика"
16
+ title="Яндекс.Метрика: данные за сегодня (просмотры, визиты и уникальные посетители)"
17
+ class="ym-advanced-informer"
18
+ :data-cid="id"
19
+ data-lang="ru"
20
+ ></a>
21
+ <!-- /Yandex.Metrika informer -->
22
+ </template>
@@ -0,0 +1,7 @@
1
+
2
+ import { } from './module'
3
+
4
+
5
+
6
+
7
+ export { default } from './module'
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "nuxt-yandex-metrika",
3
+ "version": "1.0.1",
4
+ "description": "Add Yandex Metrika to your Nuxt 3 application.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/TakNePoidet/nuxt-yandex-metrika.git"
8
+ },
9
+ "homepage": "TakNePoidet/nuxt-yandex-metrika",
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "author": {
13
+ "name": "TakNePoidet <https://taknepoidet.xyz/>",
14
+ "url": "https://github.com/TakNePoidet"
15
+ },
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/types.d.ts",
19
+ "import": "./dist/module.mjs",
20
+ "require": "./dist/module.cjs"
21
+ }
22
+ },
23
+ "main": "./dist/module.cjs",
24
+ "types": "./dist/types.d.ts",
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "scripts": {
29
+ "prepack": "nuxt-module-build",
30
+ "dev": "nuxi dev playground",
31
+ "dev:build": "nuxi build playground",
32
+ "dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
33
+ "release": "npm run lint && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
34
+ "prettier": "prettier --write .",
35
+ "lint": "eslint --fix .",
36
+ "prepare": "husky install"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "dependencies": {
42
+ "@nuxt/kit": "^3.7.0",
43
+ "chalk": "^5.3.0",
44
+ "defu": "^6.1.2"
45
+ },
46
+ "devDependencies": {
47
+ "@nuxt/devtools": "latest",
48
+ "@nuxt/eslint-config": "^0.2.0",
49
+ "@nuxt/module-builder": "^0.4.0",
50
+ "@nuxt/schema": "^3.7.0",
51
+ "@taknepoidet-config/prettier": "^2.1.0",
52
+ "@types/node": "^18.17.3",
53
+ "changelogen": "^0.5.4",
54
+ "eslint": "^8.48.0",
55
+ "eslint-config-prettier": "^9.0.0",
56
+ "eslint-plugin-prettier": "^5.0.0",
57
+ "husky": "^8.0.3",
58
+ "lint-staged": "^14.0.1",
59
+ "nuxt": "^3.7.0",
60
+ "prettier": "^3.0.3"
61
+ },
62
+ "packageManager": "pnpm@7.17.1",
63
+ "lint-staged": {
64
+ "**/*.(ts|vue)": [
65
+ "eslint --fix",
66
+ "git add"
67
+ ],
68
+ "**/*.*": [
69
+ "prettier --write",
70
+ "git add"
71
+ ]
72
+ }
73
+ }