nuxt-yandex-metrika 2.0.0 → 2.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/dist/module.json +1 -1
- package/dist/runtime/composable.d.ts +1 -1
- package/dist/runtime/composable.js +1 -1
- package/dist/runtime/yandex-metrika/index.d.ts +2 -0
- package/dist/runtime/yandex-metrika/index.js +2 -0
- package/dist/runtime/yandex-metrika/metrika.d.ts +3 -0
- package/dist/runtime/yandex-metrika/metrika.js +54 -0
- package/dist/runtime/yandex-metrika/types.d.ts +83 -0
- package/dist/runtime/yandex-metrika/types.js +15 -0
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { YandexMetrikaApi } from '
|
|
1
|
+
import type { YandexMetrikaApi } from './yandex-metrika/index.js';
|
|
2
2
|
export declare function useYandexMetrikaScript<T extends YandexMetrikaApi>(): import("#nuxt-scripts/types").UseScriptContext<T>;
|
|
3
3
|
export declare function useYandexMetrika(): YandexMetrikaApi;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useRuntimeConfig } from "#app";
|
|
2
2
|
import { useHead, useScriptTriggerIdleTimeout } from "#imports";
|
|
3
3
|
import { useRegistryScript } from "#nuxt-scripts/utils";
|
|
4
|
-
import { metrika } from "../yandex-metrika";
|
|
5
4
|
import { YandexMetrikaSchemeOptions } from "./scheme.js";
|
|
5
|
+
import { metrika } from "./yandex-metrika/index.js";
|
|
6
6
|
export function useYandexMetrikaScript() {
|
|
7
7
|
return useRegistryScript(
|
|
8
8
|
"yandex-metrika",
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { consola } from "consola";
|
|
2
|
+
import { Methods } from "./types.js";
|
|
3
|
+
export * from "./types.js";
|
|
4
|
+
export function metrika(id, debug = false) {
|
|
5
|
+
function call(type, ...args) {
|
|
6
|
+
if (debug) {
|
|
7
|
+
consola.info(`[yandex-metrika] ${type}`, ...args);
|
|
8
|
+
}
|
|
9
|
+
if (typeof window !== "undefined" && window.ym) {
|
|
10
|
+
window.ym(id, type, ...args);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
init(options = {}) {
|
|
15
|
+
call(Methods.Init, ...arguments);
|
|
16
|
+
},
|
|
17
|
+
addFileExtension(extensions) {
|
|
18
|
+
call(Methods.AddFileExtension, ...arguments);
|
|
19
|
+
},
|
|
20
|
+
extLink(url, options = {}) {
|
|
21
|
+
call(Methods.ExtLink, ...arguments);
|
|
22
|
+
},
|
|
23
|
+
file(url, options) {
|
|
24
|
+
call(Methods.File, ...arguments);
|
|
25
|
+
},
|
|
26
|
+
firstPartyParams(people) {
|
|
27
|
+
call(Methods.FirstPartyParams, ...arguments);
|
|
28
|
+
},
|
|
29
|
+
firstPartyParamsHashed(people) {
|
|
30
|
+
call(Methods.FirstPartyParamsHashed, ...arguments);
|
|
31
|
+
},
|
|
32
|
+
getClientID(cb) {
|
|
33
|
+
call(Methods.GetClientID, ...arguments);
|
|
34
|
+
},
|
|
35
|
+
hit(url = "", options) {
|
|
36
|
+
call(Methods.Hit, ...arguments);
|
|
37
|
+
},
|
|
38
|
+
notBounce(options = {}) {
|
|
39
|
+
call(Methods.NotBounce, ...arguments);
|
|
40
|
+
},
|
|
41
|
+
params(params = {}) {
|
|
42
|
+
call(Methods.Params, ...arguments);
|
|
43
|
+
},
|
|
44
|
+
reachGoal(target, params, callback, ctx) {
|
|
45
|
+
call(Methods.ReachGoal, ...arguments);
|
|
46
|
+
},
|
|
47
|
+
setUserID(userId) {
|
|
48
|
+
call(Methods.SetUserID, ...arguments);
|
|
49
|
+
},
|
|
50
|
+
userParams(params = {}) {
|
|
51
|
+
call(Methods.UserParams, ...arguments);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
ym: ((...args: any[]) => void) & {
|
|
4
|
+
a: any[];
|
|
5
|
+
l: number;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export interface VisitParameters {
|
|
10
|
+
order_price?: number;
|
|
11
|
+
currency?: string;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
14
|
+
export interface UserParameters {
|
|
15
|
+
UserID?: number;
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}
|
|
18
|
+
export interface InitParameters {
|
|
19
|
+
accurateTrackBounce?: boolean | number;
|
|
20
|
+
childIframe?: boolean;
|
|
21
|
+
clickmap?: boolean;
|
|
22
|
+
ecommerce?: boolean | string | any[];
|
|
23
|
+
params?: VisitParameters | VisitParameters[];
|
|
24
|
+
userParams?: UserParameters;
|
|
25
|
+
trackHash?: boolean;
|
|
26
|
+
trackLinks?: boolean;
|
|
27
|
+
trustedDomains?: string[];
|
|
28
|
+
type?: number;
|
|
29
|
+
webvisor?: boolean;
|
|
30
|
+
triggerEvent?: boolean;
|
|
31
|
+
sendTitle?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface HitOptions<CTX> {
|
|
34
|
+
callback?: (this: CTX) => void;
|
|
35
|
+
ctx?: CTX;
|
|
36
|
+
params?: VisitParameters;
|
|
37
|
+
referer?: string;
|
|
38
|
+
title?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface People {
|
|
41
|
+
email?: string;
|
|
42
|
+
phone_number?: string;
|
|
43
|
+
first_name?: string;
|
|
44
|
+
last_name?: string;
|
|
45
|
+
yandex_cid?: number;
|
|
46
|
+
home_address?: {
|
|
47
|
+
street?: string;
|
|
48
|
+
city?: string;
|
|
49
|
+
region?: string;
|
|
50
|
+
postal_code?: number;
|
|
51
|
+
country?: string;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export declare const Methods: {
|
|
55
|
+
readonly Init: "init";
|
|
56
|
+
readonly AddFileExtension: "addFileExtension";
|
|
57
|
+
readonly ExtLink: "extLink";
|
|
58
|
+
readonly File: "file";
|
|
59
|
+
readonly FirstPartyParams: "firstPartyParams";
|
|
60
|
+
readonly FirstPartyParamsHashed: "firstPartyParamsHashed";
|
|
61
|
+
readonly GetClientID: "getClientID";
|
|
62
|
+
readonly Hit: "hit";
|
|
63
|
+
readonly NotBounce: "notBounce";
|
|
64
|
+
readonly Params: "params";
|
|
65
|
+
readonly ReachGoal: "reachGoal";
|
|
66
|
+
readonly SetUserID: "setUserID";
|
|
67
|
+
readonly UserParams: "userParams";
|
|
68
|
+
};
|
|
69
|
+
export interface YandexMetrikaApi {
|
|
70
|
+
init: (options: Partial<InitParameters>) => void;
|
|
71
|
+
addFileExtension: (extensions?: string | string[]) => void;
|
|
72
|
+
extLink: <CTX>(url: string, options: Omit<HitOptions<CTX>, 'referer'>) => void;
|
|
73
|
+
file: <CTX>(url: string, options?: HitOptions<CTX>) => void;
|
|
74
|
+
firstPartyParams: (people: People) => void;
|
|
75
|
+
firstPartyParamsHashed: (people: People) => void;
|
|
76
|
+
getClientID: (cb: (clientID: number) => void) => void;
|
|
77
|
+
hit: <CTX>(url: string, options?: HitOptions<CTX>) => void;
|
|
78
|
+
notBounce: <CTX>(options: Pick<HitOptions<CTX>, 'ctx' | 'callback'>) => void;
|
|
79
|
+
params: (params: VisitParameters) => void;
|
|
80
|
+
reachGoal: <CTX>(target: string, params: VisitParameters, callback?: (this: CTX) => void, ctx?: CTX) => void;
|
|
81
|
+
setUserID: (userId: string) => void;
|
|
82
|
+
userParams: (params: UserParameters) => void;
|
|
83
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const Methods = {
|
|
2
|
+
Init: "init",
|
|
3
|
+
AddFileExtension: "addFileExtension",
|
|
4
|
+
ExtLink: "extLink",
|
|
5
|
+
File: "file",
|
|
6
|
+
FirstPartyParams: "firstPartyParams",
|
|
7
|
+
FirstPartyParamsHashed: "firstPartyParamsHashed",
|
|
8
|
+
GetClientID: "getClientID",
|
|
9
|
+
Hit: "hit",
|
|
10
|
+
NotBounce: "notBounce",
|
|
11
|
+
Params: "params",
|
|
12
|
+
ReachGoal: "reachGoal",
|
|
13
|
+
SetUserID: "setUserID",
|
|
14
|
+
UserParams: "userParams"
|
|
15
|
+
};
|