@vuepress/plugin-umami-analytics 2.0.0-rc.27

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
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018-present, VuePress Community
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1 @@
1
+ export * from './useUmamiAnalytics.js';
@@ -0,0 +1 @@
1
+ export * from './useUmamiAnalytics.js';
@@ -0,0 +1,19 @@
1
+ import type { UmamiOptions } from '../../shared/index.js';
2
+ declare global {
3
+ interface Window {
4
+ umami: {
5
+ track: {
6
+ (payload?: Record<any, any>): void;
7
+ (name: string, data?: Record<any, any>): void;
8
+ };
9
+ };
10
+ }
11
+ }
12
+ /**
13
+ * Add umami analytics to the site
14
+ *
15
+ * @see https://tongji.umami.com/
16
+ * @see https://tongji.umami.com/holmes/Analytics/%E7%99%BE%E5%BA%A6%E7%BB%9F%E8%AE%A1%E4%BD%BF%E7%94%A8%E6%89%8B%E5%86%8C
17
+ * @see https://tongji.umami.com/holmes/Analytics/%E6%8A%80%E6%9C%AF%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97/JS%20API/JS%20API%E6%8A%80%E6%9C%AF%E6%96%87%E6%A1%A3/_trackPageview
18
+ */
19
+ export declare const useUmamiAnalytics: ({ link, id, domains, autoTrack, cache, hostUrl, }: UmamiOptions) => void;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Add umami analytics to the site
3
+ *
4
+ * @see https://tongji.umami.com/
5
+ * @see https://tongji.umami.com/holmes/Analytics/%E7%99%BE%E5%BA%A6%E7%BB%9F%E8%AE%A1%E4%BD%BF%E7%94%A8%E6%89%8B%E5%86%8C
6
+ * @see https://tongji.umami.com/holmes/Analytics/%E6%8A%80%E6%9C%AF%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97/JS%20API/JS%20API%E6%8A%80%E6%9C%AF%E6%96%87%E6%A1%A3/_trackPageview
7
+ */
8
+ export const useUmamiAnalytics = ({ link = 'https://us.umami.is/script.js', id, domains, autoTrack, cache, hostUrl, }) => {
9
+ // avoid duplicated import
10
+ if (window.umami)
11
+ return;
12
+ const script = document.createElement('script');
13
+ script.src = link;
14
+ script.async = true;
15
+ script.setAttribute('data-website-id', id);
16
+ if (autoTrack === false)
17
+ script.setAttribute('data-auto-track', 'false');
18
+ if (cache)
19
+ script.setAttribute('data-cache', 'true');
20
+ if (domains)
21
+ script.setAttribute('data-domains', domains.join(','));
22
+ if (hostUrl)
23
+ script.setAttribute('data-hostUrl', hostUrl);
24
+ document.head.appendChild(script);
25
+ };
@@ -0,0 +1,3 @@
1
+ import type { ClientConfig } from 'vuepress/client';
2
+ declare const _default: ClientConfig;
3
+ export default _default;
@@ -0,0 +1,9 @@
1
+ import { defineClientConfig } from 'vuepress/client';
2
+ import { useUmamiAnalytics } from './composables/index.js';
3
+ export default defineClientConfig({
4
+ setup() {
5
+ if (__VUEPRESS_SSR__)
6
+ return;
7
+ useUmamiAnalytics(__UMM_OPTIONS__);
8
+ },
9
+ });
@@ -0,0 +1 @@
1
+ export * from './composables/index.js';
@@ -0,0 +1 @@
1
+ export * from './composables/index.js';
@@ -0,0 +1,2 @@
1
+ export * from './umamiAnalyticsPlugin.js';
2
+ export type { UmamiOptions as UmamiPluginOptions } from '../shared/index.js';
@@ -0,0 +1 @@
1
+ export * from './umamiAnalyticsPlugin.js';
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'vuepress/core';
2
+ import type { UmamiOptions } from '../shared/index.js';
3
+ export declare const umamiAnalyticsPlugin: ({ id, ...options }: UmamiOptions) => Plugin;
@@ -0,0 +1,25 @@
1
+ import { Logger } from '@vuepress/helper';
2
+ import { colors, getDirname, path } from 'vuepress/utils';
3
+ const __dirname = getDirname(import.meta.url);
4
+ const PLUGIN_NAME = '@vuepress/plugin-umami-analytics';
5
+ const logger = new Logger(PLUGIN_NAME);
6
+ export const umamiAnalyticsPlugin = ({ id, ...options }) => (app) => {
7
+ const plugin = {
8
+ name: PLUGIN_NAME,
9
+ };
10
+ if (!id) {
11
+ logger.warn(`${colors.cyan('id')} is required!`);
12
+ return plugin;
13
+ }
14
+ // returns an empty plugin in dev mode when debug mode is not enabled
15
+ if (app.env.isDev) {
16
+ return plugin;
17
+ }
18
+ return {
19
+ ...plugin,
20
+ define: {
21
+ __UMM_OPTIONS__: { id, ...options },
22
+ },
23
+ clientConfigFile: path.resolve(__dirname, '../client/config.js'),
24
+ };
25
+ };
@@ -0,0 +1 @@
1
+ export * from './options.js';
@@ -0,0 +1 @@
1
+ export * from './options.js';
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Options for @vuepress/plugin-umami-analytics
3
+ */
4
+ export interface UmamiOptions {
5
+ /**
6
+ * The website ID in umami Analytics
7
+ *
8
+ * Umami 统计中的网站 ID。
9
+ */
10
+ id: string;
11
+ /**
12
+ * Link of umami analytics script
13
+ *
14
+ * Umami 统计的脚本链接
15
+ *
16
+ * @default 'https://us.umami.is/script.js'
17
+ */
18
+ link?: string;
19
+ /**
20
+ * By default, Umami tracks all pageviews and events for you automatically. You can disable this behavior and track events yourself using the tracker functions.
21
+ *
22
+ * 默认情况下,Umami 会自动跟踪所有页面浏览量和事件。你可以禁用此行为并使用追踪器功能自行追踪事件。
23
+ *
24
+ * @default true
25
+ */
26
+ autoTrack?: boolean;
27
+ /**
28
+ * Cache data to improve the performance of the tracking script.
29
+ *
30
+ * 缓存数据以提高追踪脚本的性能。
31
+ */
32
+ cache?: boolean;
33
+ /**
34
+ * Let the tracker only run on specific domains.
35
+ *
36
+ * 让跟踪器仅在特定的域名上运行。
37
+ */
38
+ domains?: string[];
39
+ /**
40
+ * Location to send data
41
+ *
42
+ * 发送数据的位置
43
+ *
44
+ * @default link
45
+ */
46
+ hostUrl?: string;
47
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@vuepress/plugin-umami-analytics",
3
+ "version": "2.0.0-rc.27",
4
+ "description": "VuePress plugin - umami-analytics",
5
+ "keywords": [
6
+ "vuepress-plugin",
7
+ "vuepress",
8
+ "plugin",
9
+ "umami",
10
+ "analytics"
11
+ ],
12
+ "homepage": "https://ecosystem.vuejs.press/plugins/umami-analytics.html",
13
+ "bugs": {
14
+ "url": "https://github.com/vuepress/ecosystem/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/vuepress/ecosystem.git",
19
+ "directory": "plugins/plugin-umami-analytics"
20
+ },
21
+ "license": "MIT",
22
+ "author": {
23
+ "name": "Mr.Hope",
24
+ "email": "mister-hope@outlook.com",
25
+ "url": "https://mister-hope.com"
26
+ },
27
+ "type": "module",
28
+ "exports": {
29
+ ".": "./lib/node/index.js",
30
+ "./client": "./lib/client/index.js",
31
+ "./package.json": "./package.json"
32
+ },
33
+ "main": "./lib/node/index.js",
34
+ "types": "./lib/node/index.d.ts",
35
+ "files": [
36
+ "lib"
37
+ ],
38
+ "scripts": {
39
+ "build": "tsc -b tsconfig.build.json",
40
+ "clean": "rimraf --glob ./lib ./*.tsbuildinfo"
41
+ },
42
+ "dependencies": {
43
+ "@vuepress/helper": "~2.0.0-rc.27",
44
+ "vue": "^3.4.26"
45
+ },
46
+ "peerDependencies": {
47
+ "vuepress": "2.0.0-rc.9"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "gitHead": "146dd05c696c2287eba9498ee8ec7476fabccb0b"
53
+ }