@vestigemetrics/vue 0.0.0-stage → 1.0.0
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 +24 -2
- package/dist/createVestige.d.ts +51 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +95 -0
- package/dist/index.js.map +7 -0
- package/dist/useVestige.d.ts +3 -0
- package/package.json +23 -4
package/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vestigemetrics/vue
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Adapter Vue para a tag compilada do Vestige Metrics.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
yarn add @vestigemetrics/vue
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
app.use(createVestige({
|
|
11
|
+
accountId: '5-0',
|
|
12
|
+
router,
|
|
13
|
+
preset: 'auto'
|
|
14
|
+
}));
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Para leads:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
await vestige.identifyLead('EMAIL', 'user@example.com');
|
|
21
|
+
await vestige.identifyLead('PHONE', '5511999999999');
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
- [Documentação da plataforma](https://docs.vestigemetrics.com.br/)
|
|
25
|
+
- [Site do Vestige Metrics](https://vestigemetrics.com.br/)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Plugin } from 'vue';
|
|
2
|
+
export interface VestigeBrowserTag {
|
|
3
|
+
init(accountId: string): void;
|
|
4
|
+
buildPageview(data?: {
|
|
5
|
+
url?: string;
|
|
6
|
+
referrer?: string;
|
|
7
|
+
}): unknown;
|
|
8
|
+
registerPageview(context?: unknown): void;
|
|
9
|
+
pageview(data?: {
|
|
10
|
+
url?: string;
|
|
11
|
+
referrer?: string;
|
|
12
|
+
}): void;
|
|
13
|
+
event(data: string | Record<string, unknown>): void;
|
|
14
|
+
identifyLead(type: 'EMAIL' | 'PHONE', value: string): void;
|
|
15
|
+
getVdaCode(): string | null;
|
|
16
|
+
updateElementWithVda(element?: Element, parameter?: string, urlPattern?: string): void;
|
|
17
|
+
}
|
|
18
|
+
export interface VestigeRouter {
|
|
19
|
+
currentRoute: {
|
|
20
|
+
value: {
|
|
21
|
+
fullPath: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
afterEach(callback: (to: {
|
|
25
|
+
fullPath: string;
|
|
26
|
+
}) => void): void;
|
|
27
|
+
}
|
|
28
|
+
export interface VestigeVueOptions {
|
|
29
|
+
accountId: string;
|
|
30
|
+
scriptUrl?: string;
|
|
31
|
+
preset?: 'auto' | 'manual';
|
|
32
|
+
router?: VestigeRouter;
|
|
33
|
+
}
|
|
34
|
+
export interface VestigeVueClient {
|
|
35
|
+
readonly ready: Promise<VestigeBrowserTag>;
|
|
36
|
+
buildPageview(data?: {
|
|
37
|
+
url?: string;
|
|
38
|
+
referrer?: string;
|
|
39
|
+
}): Promise<unknown>;
|
|
40
|
+
registerPageview(): Promise<void>;
|
|
41
|
+
pageview(data?: {
|
|
42
|
+
url?: string;
|
|
43
|
+
referrer?: string;
|
|
44
|
+
}): Promise<void>;
|
|
45
|
+
event(data: string | Record<string, unknown>): Promise<void>;
|
|
46
|
+
identifyLead(type: 'EMAIL' | 'PHONE', value: string): Promise<void>;
|
|
47
|
+
getVdaCode(): Promise<string | null>;
|
|
48
|
+
updateElementWithVda(element?: Element, parameter?: string, urlPattern?: string): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
export declare function loadVestigeTag(options: VestigeVueOptions): VestigeVueClient;
|
|
51
|
+
export declare function createVestige(options: VestigeVueOptions): Plugin;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// src/vue/useVestige.ts
|
|
2
|
+
import { inject } from "vue";
|
|
3
|
+
var VESTIGE_INJECTION_KEY = Symbol("vestige");
|
|
4
|
+
function useVestige() {
|
|
5
|
+
const tag = inject(VESTIGE_INJECTION_KEY);
|
|
6
|
+
if (!tag) throw new Error("VestigeTag has not been installed");
|
|
7
|
+
return tag;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// src/vue/createVestige.ts
|
|
11
|
+
function loadScript(documentRef, url) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
var _a;
|
|
14
|
+
const existing = documentRef.querySelector(`script[src="${url}"]`);
|
|
15
|
+
if (existing) {
|
|
16
|
+
existing.addEventListener("load", () => resolve(), { once: true });
|
|
17
|
+
if ((_a = window.lt) == null ? void 0 : _a.tag) resolve();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const script = documentRef.createElement("script");
|
|
21
|
+
script.async = true;
|
|
22
|
+
script.src = url;
|
|
23
|
+
script.onload = () => resolve();
|
|
24
|
+
script.onerror = () => reject(new Error(`Unable to load Vestige tag: ${url}`));
|
|
25
|
+
documentRef.head.appendChild(script);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function loadVestigeTag(options) {
|
|
29
|
+
var _a;
|
|
30
|
+
const browserWindow = window;
|
|
31
|
+
const scriptUrl = (_a = options.scriptUrl) != null ? _a : `//tag.ltrck.com.br/lt${options.accountId}.js`;
|
|
32
|
+
if (!browserWindow.lt) browserWindow.lt = { _c: [] };
|
|
33
|
+
if (!browserWindow.lt._c) browserWindow.lt._c = [];
|
|
34
|
+
if (options.preset) browserWindow.lt._c.push(["tag_config", { preset: options.preset }]);
|
|
35
|
+
const ready = (async () => {
|
|
36
|
+
var _a2, _b;
|
|
37
|
+
if (!((_a2 = browserWindow.lt) == null ? void 0 : _a2.tag)) await loadScript(document, scriptUrl);
|
|
38
|
+
const tag = (_b = browserWindow.lt) == null ? void 0 : _b.tag;
|
|
39
|
+
if (!tag) throw new Error("Vestige tag loaded without exposing window.lt.tag");
|
|
40
|
+
tag.init(options.accountId);
|
|
41
|
+
return tag;
|
|
42
|
+
})();
|
|
43
|
+
const call = async (method, ...args) => {
|
|
44
|
+
const tag = await ready;
|
|
45
|
+
const fn = tag[method];
|
|
46
|
+
return fn.apply(tag, args);
|
|
47
|
+
};
|
|
48
|
+
let currentPageview;
|
|
49
|
+
const client = {
|
|
50
|
+
ready,
|
|
51
|
+
buildPageview: (data) => {
|
|
52
|
+
if (options.router) return Promise.reject(new Error("buildPageview() \xE9 controlado pelo router configurado."));
|
|
53
|
+
return call("buildPageview", data).then((context) => {
|
|
54
|
+
currentPageview = context;
|
|
55
|
+
return context;
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
registerPageview: () => {
|
|
59
|
+
if (options.preset !== "manual") return Promise.reject(new Error("registerPageview() s\xF3 pode ser chamado no preset manual."));
|
|
60
|
+
return call("registerPageview", currentPageview);
|
|
61
|
+
},
|
|
62
|
+
pageview: (data) => call("pageview", data),
|
|
63
|
+
event: (data) => call("event", data),
|
|
64
|
+
identifyLead: (type, value) => call("identifyLead", type, value),
|
|
65
|
+
getVdaCode: () => call("getVdaCode"),
|
|
66
|
+
updateElementWithVda: (element, parameter, urlPattern) => call("updateElementWithVda", element, parameter, urlPattern)
|
|
67
|
+
};
|
|
68
|
+
if (options.router) {
|
|
69
|
+
ready.then((tag) => {
|
|
70
|
+
const buildAndMaybeRegister = (url) => {
|
|
71
|
+
const context = tag.buildPageview({ url });
|
|
72
|
+
currentPageview = context;
|
|
73
|
+
if (options.preset !== "manual") tag.registerPageview(context);
|
|
74
|
+
};
|
|
75
|
+
buildAndMaybeRegister(options.router.currentRoute.value.fullPath);
|
|
76
|
+
options.router.afterEach((to) => buildAndMaybeRegister(to.fullPath));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return client;
|
|
80
|
+
}
|
|
81
|
+
function createVestige(options) {
|
|
82
|
+
const client = loadVestigeTag(options);
|
|
83
|
+
return {
|
|
84
|
+
install(app) {
|
|
85
|
+
app.provide(VESTIGE_INJECTION_KEY, client);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export {
|
|
90
|
+
VESTIGE_INJECTION_KEY,
|
|
91
|
+
createVestige,
|
|
92
|
+
loadVestigeTag,
|
|
93
|
+
useVestige
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/vue/useVestige.ts", "../../../src/vue/createVestige.ts"],
|
|
4
|
+
"sourcesContent": ["import { inject } from 'vue';\nimport type { VestigeVueClient } from './createVestige';\n\nexport const VESTIGE_INJECTION_KEY = Symbol('vestige');\n\nexport function useVestige(): VestigeVueClient {\n const tag = inject<VestigeVueClient>(VESTIGE_INJECTION_KEY);\n if (!tag) throw new Error('VestigeTag has not been installed');\n return tag;\n}\n", "import type { App, Plugin } from 'vue';\nimport { VESTIGE_INJECTION_KEY } from './useVestige';\n\nexport interface VestigeBrowserTag {\n init(accountId: string): void;\n buildPageview(data?: { url?: string; referrer?: string }): unknown;\n registerPageview(context?: unknown): void;\n pageview(data?: { url?: string; referrer?: string }): void;\n event(data: string | Record<string, unknown>): void;\n identifyLead(type: 'EMAIL' | 'PHONE', value: string): void;\n getVdaCode(): string | null;\n updateElementWithVda(element?: Element, parameter?: string, urlPattern?: string): void;\n}\n\ninterface BrowserWindow extends Window {\n lt?: { tag?: VestigeBrowserTag; _c?: Array<[string, unknown]> };\n}\n\nexport interface VestigeRouter {\n currentRoute: { value: { fullPath: string } };\n afterEach(callback: (to: { fullPath: string }) => void): void;\n}\n\nexport interface VestigeVueOptions {\n accountId: string;\n scriptUrl?: string;\n preset?: 'auto' | 'manual';\n router?: VestigeRouter;\n}\n\nexport interface VestigeVueClient {\n readonly ready: Promise<VestigeBrowserTag>;\n buildPageview(data?: { url?: string; referrer?: string }): Promise<unknown>;\n registerPageview(): Promise<void>;\n pageview(data?: { url?: string; referrer?: string }): Promise<void>;\n event(data: string | Record<string, unknown>): Promise<void>;\n identifyLead(type: 'EMAIL' | 'PHONE', value: string): Promise<void>;\n getVdaCode(): Promise<string | null>;\n updateElementWithVda(element?: Element, parameter?: string, urlPattern?: string): Promise<void>;\n}\n\nfunction loadScript(documentRef: Document, url: string): Promise<void> {\n return new Promise((resolve, reject) => {\n const existing = documentRef.querySelector(`script[src=\"${url}\"]`);\n if (existing) {\n existing.addEventListener('load', () => resolve(), { once: true });\n if ((window as BrowserWindow).lt?.tag) resolve();\n return;\n }\n const script = documentRef.createElement('script');\n script.async = true;\n script.src = url;\n script.onload = () => resolve();\n script.onerror = () => reject(new Error(`Unable to load Vestige tag: ${url}`));\n documentRef.head.appendChild(script);\n });\n}\n\nexport function loadVestigeTag(options: VestigeVueOptions): VestigeVueClient {\n const browserWindow = window as BrowserWindow;\n const scriptUrl = options.scriptUrl ?? `//tag.ltrck.com.br/lt${options.accountId}.js`;\n if (!browserWindow.lt) browserWindow.lt = { _c: [] };\n if (!browserWindow.lt._c) browserWindow.lt._c = [];\n if (options.preset) browserWindow.lt._c.push(['tag_config', { preset: options.preset }]);\n const ready = (async () => {\n if (!browserWindow.lt?.tag) await loadScript(document, scriptUrl);\n const tag = browserWindow.lt?.tag;\n if (!tag) throw new Error('Vestige tag loaded without exposing window.lt.tag');\n tag.init(options.accountId);\n return tag;\n })();\n\n const call = async <K extends keyof VestigeBrowserTag>(method: K, ...args: Parameters<NonNullable<VestigeBrowserTag[K]>>): Promise<ReturnType<NonNullable<VestigeBrowserTag[K]>>> => {\n const tag = await ready;\n const fn = tag[method] as (...values: Parameters<NonNullable<VestigeBrowserTag[K]>>) => ReturnType<NonNullable<VestigeBrowserTag[K]>>;\n return fn.apply(tag, args);\n };\n\n let currentPageview: unknown;\n\n const client: VestigeVueClient = {\n ready,\n buildPageview: (data) => {\n if (options.router) return Promise.reject(new Error('buildPageview() \u00E9 controlado pelo router configurado.'));\n return call('buildPageview', data).then((context) => {\n currentPageview = context;\n return context;\n });\n },\n registerPageview: () => {\n if (options.preset !== 'manual') return Promise.reject(new Error('registerPageview() s\u00F3 pode ser chamado no preset manual.'));\n return call('registerPageview', currentPageview);\n },\n pageview: (data) => call('pageview', data),\n event: (data) => call('event', data),\n identifyLead: (type, value) => call('identifyLead', type, value),\n getVdaCode: () => call('getVdaCode'),\n updateElementWithVda: (element, parameter, urlPattern) => call('updateElementWithVda', element, parameter, urlPattern)\n };\n\n if (options.router) {\n ready.then((tag) => {\n const buildAndMaybeRegister = (url: string): void => {\n const context = tag.buildPageview({ url });\n currentPageview = context;\n if (options.preset !== 'manual') tag.registerPageview(context);\n };\n buildAndMaybeRegister(options.router!.currentRoute.value.fullPath);\n options.router!.afterEach((to) => buildAndMaybeRegister(to.fullPath));\n });\n }\n\n return client;\n}\n\nexport function createVestige(options: VestigeVueOptions): Plugin {\n const client = loadVestigeTag(options);\n return {\n install(app: App) {\n app.provide(VESTIGE_INJECTION_KEY, client);\n }\n };\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,cAAc;AAGhB,IAAM,wBAAwB,OAAO,SAAS;AAE9C,SAAS,aAA+B;AAC7C,QAAM,MAAM,OAAyB,qBAAqB;AAC1D,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,mCAAmC;AAC7D,SAAO;AACT;;;ACgCA,SAAS,WAAW,aAAuB,KAA4B;AACrE,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AA1C1C;AA2CI,UAAM,WAAW,YAAY,cAAc,eAAe,GAAG,IAAI;AACjE,QAAI,UAAU;AACZ,eAAS,iBAAiB,QAAQ,MAAM,QAAQ,GAAG,EAAE,MAAM,KAAK,CAAC;AACjE,WAAK,YAAyB,OAAzB,mBAA6B,IAAK,SAAQ;AAC/C;AAAA,IACF;AACA,UAAM,SAAS,YAAY,cAAc,QAAQ;AACjD,WAAO,QAAQ;AACf,WAAO,MAAM;AACb,WAAO,SAAS,MAAM,QAAQ;AAC9B,WAAO,UAAU,MAAM,OAAO,IAAI,MAAM,+B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oB,eAAe;AAAA,IACjD;AAAA,IACA,UAAU,CAAC,SAAS,KAAK,YAAY,IAAI;AAAA,IACzC,OAAO,CAAC,SAAS,KAAK,SAAS,IAAI;AAAA,IACnC,cAAc,CAAC,MAAM,UAAU,KAAK,gBAAgB,MAAM,KAAK;AAAA,IAC/D,YAAY,MAAM,KAAK,YAAY;AAAA,IACnC,sBAAsB,CAAC,SAAS,WAAW,eAAe,KAAK,wBAAwB,SAAS,WAAW,UAAU;AAAA,EACvH;AAEA,MAAI,QAAQ,QAAQ;AAClB,UAAM,KAAK,CAAC,QAAQ;AAClB,YAAM,wBAAwB,CAAC,QAAsB;AACnD,cAAM,UAAU,IAAI,cAAc,EAAE,IAAI,CAAC;AACzC,0BAAkB;AAClB,YAAI,QAAQ,WAAW,SAAU,KAAI,iBAAiB,OAAO;AAAA,MAC/D;AACA,4BAAsB,QAAQ,OAAQ,aAAa,MAAM,QAAQ;AACjE,cAAQ,OAAQ,UAAU,CAAC,OAAO,sBAAsB,GAAG,QAAQ,CAAC;AAAA,IACtE,CAAC;AAAA,EACH;AAEA,SAAO;AACT;AAEO,SAAS,cAAc,SAAoC;AAChE,QAAM,SAAS,eAAe,OAAO;AACrC,SAAO;AAAA,IACL,QAAQ,KAAU;AAChB,UAAI,QAAQ,uBAAuB,MAAM;AAAA,IAC3C;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["_a"]
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vestigemetrics/vue",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Vue adapter for Vestige Metrics compiled tags",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": ["dist", "README.md"],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "node ../../scripts/build-vue-package.mjs"
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"vue": ">=3.3.0"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/vestigemetrics/front_tag.git"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"homepage": "https://vestigemetrics.com.br",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/vestigemetrics/front_tag/issues"
|
|
24
|
+
}
|
|
25
|
+
}
|