diff --git a/dist/main.d.ts b/dist/main.d.ts index e7ca395..5237312 100644 --- a/dist/main.d.ts +++ b/dist/main.d.ts @@ -22,4 +22,4 @@ export declare function usePush(): { export default function install( Vue: Vue, { router, siteIdList, isDebug }: Partial -): false | undefined +): void diff --git a/dist/vue-baidu-analytics.js b/dist/vue-baidu-analytics.js index d425fd7..99bb154 100644 --- a/dist/vue-baidu-analytics.js +++ b/dist/vue-baidu-analytics.js @@ -246,14 +246,7 @@ /** * 一些环境和参数的检查 */ - if (typeof document === 'undefined' || typeof window === 'undefined') { - return false - } - if (!router) { - throw new Error( - '[vue-baidu-analytics] Must pass a Vue-Router instance to vue-baidu-analytics.' - ) - } + if (typeof document === 'undefined' || typeof window === 'undefined') return if (!siteIdList) { throw new Error( '[vue-baidu-analytics] Missing tracking domain ID, add at least one of baidu analytics siteId.' @@ -286,12 +279,14 @@ /** * 路由切换时执行PV上报 */ - router.afterEach(function () { - // 获取要上报的链接(当前版本不需要拼接了) - var PAGE_URL = window.location.href - // 上报数据 - pushBAIDU.pv(PAGE_URL) - }) + if (router) { + router.afterEach(function () { + // 获取要上报的链接(当前版本不需要拼接了) + var PAGE_URL = window.location.href + // 上报数据 + pushBAIDU.pv(PAGE_URL) + }) + } } exports.default = install diff --git a/dist/vue-baidu-analytics.js.map b/dist/vue-baidu-analytics.js.map index 246c317..05bc9c9 100644 --- a/dist/vue-baidu-analytics.js.map +++ b/dist/vue-baidu-analytics.js.map @@ -1 +1 @@ -{"version":3,"file":"vue-baidu-analytics.js","sources":["../node_modules/tslib/tslib.es6.js","../src/modules/baidu.ts","../src/modules/pushBAIDU.ts","../src/modules/getVueVersion.ts","../src/main.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || from);\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n","/**\n * 定义基础配置\n * 官方文档 https://tongji.baidu.com/open/api/more?p=guide_overview\n */\nclass BAIDU {\n siteId: string\n isDebug: boolean\n\n constructor(siteId: string = '', isDebug: boolean = false) {\n this.siteId = siteId\n this.isDebug = isDebug\n }\n\n /**\n * 初始化\n */\n init() {\n window._hmt = window._hmt ? window._hmt : []\n const SCRIPT = document.createElement('script')\n SCRIPT['async'] = true\n SCRIPT['src'] = `https://hm.baidu.com/hm.js?${this.siteId}`\n document.querySelector('head')?.appendChild(SCRIPT)\n\n if (this.isDebug) {\n console.log(\n `[vue-baidu-analytics] siteId load done.\\nsiteId: ${this.siteId}`\n )\n }\n }\n\n /**\n * 设置要响应的站点\n */\n setAccount() {\n window._hmt.push(['_setAccount', this.siteId])\n }\n\n /**\n * 提交PV、UV\n */\n trackPageview(pageUrl: string) {\n // 如果页面链接没传或者无效链接,则默认为根域名\n if (!pageUrl || typeof pageUrl !== 'string') {\n pageUrl = '/'\n }\n\n // 如果页面链接带上了域名,则需要过滤掉\n if (pageUrl.startsWith('http')) {\n const PAGE_CUT = pageUrl.split('/')\n const HOST_NAME = `${PAGE_CUT[0]}//${PAGE_CUT[2]}`\n pageUrl = pageUrl.replace(HOST_NAME, '')\n }\n\n // 设置响应 id 并提交数据\n this.setAccount()\n window._hmt.push(['_trackPageview', pageUrl])\n\n if (this.isDebug) {\n console.log(\n `[vue-baidu-analytics] track pv done.\\nsiteId: ${this.siteId}\\npageUrl: ${pageUrl}`\n )\n }\n }\n\n /**\n * 提交点击事件\n */\n trackEvent(category: string, action: string, label: string, value: number) {\n // 前两个是必填项\n if (\n typeof category !== 'string' ||\n typeof action !== 'string' ||\n !category ||\n !action\n ) {\n throw new Error(\n '[vue-baidu-analytics] Missing necessary category and operation information, and must be of type string.'\n )\n }\n\n // 重置一些无效的默认值\n if (!label || typeof label !== 'string') {\n label = ''\n }\n\n if (!Number(value)) {\n value = 1\n }\n\n // 设置响应id并提交数据\n this.setAccount()\n window._hmt.push(['_trackEvent', category, action, label, value])\n\n if (this.isDebug) {\n console.log(\n `[vue-baidu-analytics] track event done.\\nsiteId: ${this.siteId}\\ncategory: ${category}\\naction: ${action}\\nlabel: ${label}\\nvalue: ${value}`\n )\n }\n }\n}\n\nexport default BAIDU\n","import BAIDU from '@m/baidu'\n\n/**\n * 定义推送操作\n */\nclass PushBAIDU {\n siteIdList: string[]\n isDebug: boolean\n\n constructor(siteIdList: string[], isDebug: boolean) {\n this.siteIdList = [...siteIdList]\n this.isDebug = isDebug\n }\n\n /**\n * 批量部署站点\n */\n init() {\n this.siteIdList.forEach((siteId: string) => {\n const SITE = new BAIDU(siteId, this.isDebug)\n SITE.init()\n })\n }\n\n /**\n * 批量提交pv上报\n */\n pv(pageUrl: string) {\n this.siteIdList.forEach((siteId: string) => {\n const SITE = new BAIDU(siteId, this.isDebug)\n SITE.trackPageview(pageUrl)\n })\n }\n\n /**\n * 批量提交事件上报\n */\n event(category: string, action: string, label: string, value: number) {\n this.siteIdList.forEach((siteId: string) => {\n const SITE = new BAIDU(siteId, this.isDebug)\n SITE.trackEvent(category, action, label, value)\n })\n }\n}\n\nexport default PushBAIDU\n","import type { Vue } from '@/types'\n\n/**\n * 获取Vue的版本\n * @return 2=Vue2.x, 3=Vue3.x\n */\nconst getVueVersion = (Vue: Vue): number => {\n let version: number = 2\n\n // 获取Vue的版本号\n const VUE_VERSION: string = String(Vue.version)\n\n // Vue 2.x\n if (VUE_VERSION.slice(0, 2) === '2.') {\n version = 2\n }\n\n // Vue 3.x\n if (VUE_VERSION.slice(0, 2) === '3.') {\n version = 3\n }\n\n return version\n}\n\nexport default getVueVersion\n","import PushBAIDU from '@m/pushBAIDU'\nimport getVueVersion from '@m/getVueVersion'\nimport type { Options, Vue } from '@/types'\n\n/**\n * 全局的数据\n */\nconst __GLOBAL__ = {\n pushBAIDU: {} as PushBAIDU,\n}\n\n/**\n * 暴露 Hooks\n * @description 解决 Vue 3.0 使用全局变量很麻烦的问题\n * @example\n * import { usePush } from 'vue-baidu-analytics'\n * const baidu = usePush();\n * baidu.pv('/');\n */\nexport function usePush() {\n // 提交 pv\n function pv(pageUrl: string) {\n return __GLOBAL__.pushBAIDU.pv(pageUrl)\n }\n\n // 提交事件\n function event(\n category: string,\n action: string,\n label: string,\n value: number\n ) {\n return __GLOBAL__.pushBAIDU.event(category, action, label, value)\n }\n\n return {\n pv,\n event,\n }\n}\n\n/**\n * 定义插件\n */\nexport default function install(\n Vue: Vue,\n { router, siteIdList, isDebug = false }: Partial\n) {\n /**\n * 一些环境和参数的检查\n */\n if (typeof document === 'undefined' || typeof window === 'undefined') {\n return false\n }\n\n if (!router) {\n throw new Error(\n '[vue-baidu-analytics] Must pass a Vue-Router instance to vue-baidu-analytics.'\n )\n }\n\n if (!siteIdList) {\n throw new Error(\n '[vue-baidu-analytics] Missing tracking domain ID, add at least one of baidu analytics siteId.'\n )\n }\n\n /**\n * 挂载推送的方法\n */\n const pushBAIDU: PushBAIDU = new PushBAIDU(siteIdList, isDebug)\n __GLOBAL__.pushBAIDU = pushBAIDU\n\n /**\n * 挂载全局变量到 Vue 上\n * 获取Vue版本(获取失败则默认为2)\n */\n const VUE_VERSION: number = getVueVersion(Vue) || 2\n switch (VUE_VERSION) {\n case 2:\n Vue.prototype.$pushBAIDU = pushBAIDU\n break\n case 3:\n Vue.config.globalProperties.$pushBAIDU = pushBAIDU\n break\n }\n\n /**\n * 部署站点并初始化\n */\n if (siteIdList && Array.isArray(siteIdList)) {\n pushBAIDU.init()\n }\n\n /**\n * 路由切换时执行PV上报\n */\n router.afterEach(() => {\n // 获取要上报的链接(当前版本不需要拼接了)\n const PAGE_URL: string = window.location.href\n\n // 上报数据\n pushBAIDU.pv(PAGE_URL)\n })\n}\n"],"names":["__spreadArray","to","from","pack","arguments","length","i","l","ar","Array","prototype","slice","call","concat"],"mappings":";;;;;;;;;;;IAAA;IACA;AACA;IACA;IACA;AACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAuJO,SAASA,aAAT,CAAuBC,EAAvB,EAA2BC,IAA3B,EAAiCC,IAAjC,EAAuC;IAC1C,MAAIA,IAAI,IAAIC,SAAS,CAACC,MAAV,KAAqB,CAAjC,EAAoC,KAAK,IAAIC,CAAC,GAAG,CAAR,EAAWC,CAAC,GAAGL,IAAI,CAACG,MAApB,EAA4BG,EAAjC,EAAqCF,CAAC,GAAGC,CAAzC,EAA4CD,CAAC,EAA7C,EAAiD;IACjF,QAAIE,EAAE,IAAI,EAAEF,CAAC,IAAIJ,IAAP,CAAV,EAAwB;IACpB,UAAI,CAACM,EAAL,EAASA,EAAE,GAAGC,KAAK,CAACC,SAAN,CAAgBC,KAAhB,CAAsBC,IAAtB,CAA2BV,IAA3B,EAAiC,CAAjC,EAAoCI,CAApC,CAAL;IACTE,MAAAA,EAAE,CAACF,CAAD,CAAF,GAAQJ,IAAI,CAACI,CAAD,CAAZ;IACH;IACJ;IACD,SAAOL,EAAE,CAACY,MAAH,CAAUL,EAAE,IAAIN,IAAhB,CAAP;IACH;;IC5KD;;;;IAIA;QAIE,eAAY,MAAmB,EAAE,OAAwB;YAA7C,uBAAA,EAAA,WAAmB;YAAE,wBAAA,EAAA,eAAwB;YACv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YAC3C,SAAS,CAAC,IAAI,EAAE,CAAA;SACjB;;;;QAKD,MAAM,CAAC,SAAS,CAAC;;YAEf,IAAM,QAAQ,GAAW,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAA;;YAG7C,SAAS,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAA;SACvB,CAAC,CAAA;IACJ;;;;;;;"} \ No newline at end of file +{"version":3,"file":"vue-baidu-analytics.js","sources":["../node_modules/tslib/tslib.es6.js","../src/modules/baidu.ts","../src/modules/pushBAIDU.ts","../src/modules/getVueVersion.ts","../src/main.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || from);\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n","/**\n * 定义基础配置\n * 官方文档 https://tongji.baidu.com/open/api/more?p=guide_overview\n */\nclass BAIDU {\n siteId: string\n isDebug: boolean\n\n constructor(siteId: string = '', isDebug: boolean = false) {\n this.siteId = siteId\n this.isDebug = isDebug\n }\n\n /**\n * 初始化\n */\n init() {\n window._hmt = window._hmt ? window._hmt : []\n const SCRIPT = document.createElement('script')\n SCRIPT['async'] = true\n SCRIPT['src'] = `https://hm.baidu.com/hm.js?${this.siteId}`\n document.querySelector('head')?.appendChild(SCRIPT)\n\n if (this.isDebug) {\n console.log(\n `[vue-baidu-analytics] siteId load done.\\nsiteId: ${this.siteId}`\n )\n }\n }\n\n /**\n * 设置要响应的站点\n */\n setAccount() {\n window._hmt.push(['_setAccount', this.siteId])\n }\n\n /**\n * 提交PV、UV\n */\n trackPageview(pageUrl: string) {\n // 如果页面链接没传或者无效链接,则默认为根域名\n if (!pageUrl || typeof pageUrl !== 'string') {\n pageUrl = '/'\n }\n\n // 如果页面链接带上了域名,则需要过滤掉\n if (pageUrl.startsWith('http')) {\n const PAGE_CUT = pageUrl.split('/')\n const HOST_NAME = `${PAGE_CUT[0]}//${PAGE_CUT[2]}`\n pageUrl = pageUrl.replace(HOST_NAME, '')\n }\n\n // 设置响应 id 并提交数据\n this.setAccount()\n window._hmt.push(['_trackPageview', pageUrl])\n\n if (this.isDebug) {\n console.log(\n `[vue-baidu-analytics] track pv done.\\nsiteId: ${this.siteId}\\npageUrl: ${pageUrl}`\n )\n }\n }\n\n /**\n * 提交点击事件\n */\n trackEvent(category: string, action: string, label: string, value: number) {\n // 前两个是必填项\n if (\n typeof category !== 'string' ||\n typeof action !== 'string' ||\n !category ||\n !action\n ) {\n throw new Error(\n '[vue-baidu-analytics] Missing necessary category and operation information, and must be of type string.'\n )\n }\n\n // 重置一些无效的默认值\n if (!label || typeof label !== 'string') {\n label = ''\n }\n\n if (!Number(value)) {\n value = 1\n }\n\n // 设置响应id并提交数据\n this.setAccount()\n window._hmt.push(['_trackEvent', category, action, label, value])\n\n if (this.isDebug) {\n console.log(\n `[vue-baidu-analytics] track event done.\\nsiteId: ${this.siteId}\\ncategory: ${category}\\naction: ${action}\\nlabel: ${label}\\nvalue: ${value}`\n )\n }\n }\n}\n\nexport default BAIDU\n","import BAIDU from '@m/baidu'\n\n/**\n * 定义推送操作\n */\nclass PushBAIDU {\n siteIdList: string[]\n isDebug: boolean\n\n constructor(siteIdList: string[], isDebug: boolean) {\n this.siteIdList = [...siteIdList]\n this.isDebug = isDebug\n }\n\n /**\n * 批量部署站点\n */\n init() {\n this.siteIdList.forEach((siteId: string) => {\n const SITE = new BAIDU(siteId, this.isDebug)\n SITE.init()\n })\n }\n\n /**\n * 批量提交pv上报\n */\n pv(pageUrl: string) {\n this.siteIdList.forEach((siteId: string) => {\n const SITE = new BAIDU(siteId, this.isDebug)\n SITE.trackPageview(pageUrl)\n })\n }\n\n /**\n * 批量提交事件上报\n */\n event(category: string, action: string, label: string, value: number) {\n this.siteIdList.forEach((siteId: string) => {\n const SITE = new BAIDU(siteId, this.isDebug)\n SITE.trackEvent(category, action, label, value)\n })\n }\n}\n\nexport default PushBAIDU\n","import type { Vue } from '@/types'\n\n/**\n * 获取Vue的版本\n * @return 2=Vue2.x, 3=Vue3.x\n */\nconst getVueVersion = (Vue: Vue): number => {\n let version: number = 2\n\n // 获取Vue的版本号\n const VUE_VERSION: string = String(Vue.version)\n\n // Vue 2.x\n if (VUE_VERSION.slice(0, 2) === '2.') {\n version = 2\n }\n\n // Vue 3.x\n if (VUE_VERSION.slice(0, 2) === '3.') {\n version = 3\n }\n\n return version\n}\n\nexport default getVueVersion\n","import PushBAIDU from '@m/pushBAIDU'\nimport getVueVersion from '@m/getVueVersion'\nimport type { Options, Vue } from '@/types'\n\n/**\n * 全局的数据\n */\nconst __GLOBAL__ = {\n pushBAIDU: {} as PushBAIDU,\n}\n\n/**\n * 暴露 Hooks\n * @description 解决 Vue 3.0 使用全局变量很麻烦的问题\n * @example\n * import { usePush } from 'vue-baidu-analytics'\n * const baidu = usePush();\n * baidu.pv('/');\n */\nexport function usePush() {\n // 提交 pv\n function pv(pageUrl: string) {\n return __GLOBAL__.pushBAIDU.pv(pageUrl)\n }\n\n // 提交事件\n function event(\n category: string,\n action: string,\n label: string,\n value: number\n ) {\n return __GLOBAL__.pushBAIDU.event(category, action, label, value)\n }\n\n return {\n pv,\n event,\n }\n}\n\n/**\n * 定义插件\n */\nexport default function install(\n Vue: Vue,\n { router, siteIdList, isDebug = false }: Partial\n) {\n /**\n * 一些环境和参数的检查\n */\n if (typeof document === 'undefined' || typeof window === 'undefined') return\n\n if (!siteIdList) {\n throw new Error(\n '[vue-baidu-analytics] Missing tracking domain ID, add at least one of baidu analytics siteId.'\n )\n }\n\n /**\n * 挂载推送的方法\n */\n const pushBAIDU: PushBAIDU = new PushBAIDU(siteIdList, isDebug)\n __GLOBAL__.pushBAIDU = pushBAIDU\n\n /**\n * 挂载全局变量到 Vue 上\n * 获取Vue版本(获取失败则默认为2)\n */\n const VUE_VERSION: number = getVueVersion(Vue) || 2\n switch (VUE_VERSION) {\n case 2:\n Vue.prototype.$pushBAIDU = pushBAIDU\n break\n case 3:\n Vue.config.globalProperties.$pushBAIDU = pushBAIDU\n break\n }\n\n /**\n * 部署站点并初始化\n */\n if (siteIdList && Array.isArray(siteIdList)) {\n pushBAIDU.init()\n }\n\n /**\n * 路由切换时执行PV上报\n */\n if (router) {\n router.afterEach(() => {\n // 获取要上报的链接(当前版本不需要拼接了)\n const PAGE_URL: string = window.location.href\n\n // 上报数据\n pushBAIDU.pv(PAGE_URL)\n })\n }\n}\n"],"names":["__spreadArray","to","from","pack","arguments","length","i","l","ar","Array","prototype","slice","call","concat"],"mappings":";;;;;;;;;;;IAAA;IACA;AACA;IACA;IACA;AACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAuJO,SAASA,aAAT,CAAuBC,EAAvB,EAA2BC,IAA3B,EAAiCC,IAAjC,EAAuC;IAC1C,MAAIA,IAAI,IAAIC,SAAS,CAACC,MAAV,KAAqB,CAAjC,EAAoC,KAAK,IAAIC,CAAC,GAAG,CAAR,EAAWC,CAAC,GAAGL,IAAI,CAACG,MAApB,EAA4BG,EAAjC,EAAqCF,CAAC,GAAGC,CAAzC,EAA4CD,CAAC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AAC,SAAS,GAAG,SAAS,CAAA;;;;;QAMhC,IAAM,WAAW,GAAW,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACnD,QAAQ,WAAW;YACjB,KAAK,CAAC;gBACJ,GAAG,CAAC,SAAS,CAAC,UAAU,GAAG,SAAS,CAAA;gBACpC,MAAK;YACP,KAAK,CAAC;gBACJ,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,UAAU,GAAG,SAAS,CAAA;gBAClD,MAAK;SACR;;;;QAKD,IAAI,UAAU,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YAC3C,SAAS,CAAC,IAAI,EAAE,CAAA;SACjB;;;;QAKD,IAAI,MAAM,EAAE;YACV,MAAM,CAAC,SAAS,CAAC;;gBAEf,IAAM,QAAQ,GAAW,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAA;;gBAG7C,SAAS,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAA;aACvB,CAAC,CAAA;SACH;IACH;;;;;;;"} \ No newline at end of file diff --git a/dist/vue-baidu-analytics.min.js b/dist/vue-baidu-analytics.min.js index 3fe9acc..f306008 100644 --- a/dist/vue-baidu-analytics.min.js +++ b/dist/vue-baidu-analytics.min.js @@ -16,90 +16,76 @@ ) })(this, function (t) { 'use strict' - /*! ***************************************************************************** - Copyright (c) Microsoft Corporation. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR - OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - PERFORMANCE OF THIS SOFTWARE. - ***************************************************************************** */ var e = - (function () { - function t(t, e) { - void 0 === t && (t = ''), - void 0 === e && (e = !1), - (this.siteId = t), - (this.isDebug = e) - } - return ( - (t.prototype.init = function () { - var t - window._hmt = window._hmt ? window._hmt : [] - var e = document.createElement('script') - ;(e.async = !0), - (e.src = 'https://hm.baidu.com/hm.js?' + this.siteId), - null === (t = document.querySelector('head')) || - void 0 === t || - t.appendChild(e), - this.isDebug && - console.log( - '[vue-baidu-analytics] siteId load done.\nsiteId: ' + - this.siteId - ) - }), - (t.prototype.setAccount = function () { - window._hmt.push(['_setAccount', this.siteId]) - }), - (t.prototype.trackPageview = function (t) { - if ( - ((t && 'string' == typeof t) || (t = '/'), t.startsWith('http')) - ) { - var e = t.split('/'), - i = e[0] + '//' + e[2] - t = t.replace(i, '') - } - this.setAccount(), - window._hmt.push(['_trackPageview', t]), - this.isDebug && - console.log( - '[vue-baidu-analytics] track pv done.\nsiteId: ' + - this.siteId + - '\npageUrl: ' + - t - ) - }), - (t.prototype.trackEvent = function (t, e, i, n) { - if ('string' != typeof t || 'string' != typeof e || !t || !e) - throw new Error( - '[vue-baidu-analytics] Missing necessary category and operation information, and must be of type string.' + var e = (function () { + function t(t, e) { + void 0 === t && (t = ''), + void 0 === e && (e = !1), + (this.siteId = t), + (this.isDebug = e) + } + return ( + (t.prototype.init = function () { + var t + window._hmt = window._hmt ? window._hmt : [] + var e = document.createElement('script') + ;(e.async = !0), + (e.src = 'https://hm.baidu.com/hm.js?' + this.siteId), + null === (t = document.querySelector('head')) || + void 0 === t || + t.appendChild(e), + this.isDebug && + console.log( + '[vue-baidu-analytics] siteId load done.\nsiteId: ' + + this.siteId ) - ;(i && 'string' == typeof i) || (i = ''), - Number(n) || (n = 1), - this.setAccount(), - window._hmt.push(['_trackEvent', t, e, i, n]), - this.isDebug && - console.log( - '[vue-baidu-analytics] track event done.\nsiteId: ' + - this.siteId + - '\ncategory: ' + - t + - '\naction: ' + - e + - '\nlabel: ' + - i + - '\nvalue: ' + - n - ) - }), - t - ) - })(), + }), + (t.prototype.setAccount = function () { + window._hmt.push(['_setAccount', this.siteId]) + }), + (t.prototype.trackPageview = function (t) { + if ( + ((t && 'string' == typeof t) || (t = '/'), t.startsWith('http')) + ) { + var e = t.split('/'), + i = e[0] + '//' + e[2] + t = t.replace(i, '') + } + this.setAccount(), + window._hmt.push(['_trackPageview', t]), + this.isDebug && + console.log( + '[vue-baidu-analytics] track pv done.\nsiteId: ' + + this.siteId + + '\npageUrl: ' + + t + ) + }), + (t.prototype.trackEvent = function (t, e, i, n) { + if ('string' != typeof t || 'string' != typeof e || !t || !e) + throw new Error( + '[vue-baidu-analytics] Missing necessary category and operation information, and must be of type string.' + ) + ;(i && 'string' == typeof i) || (i = ''), + Number(n) || (n = 1), + this.setAccount(), + window._hmt.push(['_trackEvent', t, e, i, n]), + this.isDebug && + console.log( + '[vue-baidu-analytics] track event done.\nsiteId: ' + + this.siteId + + '\ncategory: ' + + t + + '\naction: ' + + e + + '\nlabel: ' + + i + + '\nvalue: ' + + n + ) + }), + t + ) + })(), i = (function () { function t(t, e) { ;(this.siteIdList = (function (t, e, i) { @@ -139,40 +125,37 @@ s = e.siteIdList, r = e.isDebug, a = void 0 !== r && r - if ('undefined' == typeof document || 'undefined' == typeof window) - return !1 - if (!o) - throw new Error( - '[vue-baidu-analytics] Must pass a Vue-Router instance to vue-baidu-analytics.' - ) - if (!s) - throw new Error( - '[vue-baidu-analytics] Missing tracking domain ID, add at least one of baidu analytics siteId.' - ) - var u = new i(s, a) - switch ( - ((n.pushBAIDU = u), - (function (t) { - var e = 2, - i = String(t.version) - return ( - '2.' === i.slice(0, 2) && (e = 2), - '3.' === i.slice(0, 2) && (e = 3), - e + if ('undefined' != typeof document && 'undefined' != typeof window) { + if (!s) + throw new Error( + '[vue-baidu-analytics] Missing tracking domain ID, add at least one of baidu analytics siteId.' ) - })(t) || 2) - ) { - case 2: - t.prototype.$pushBAIDU = u - break - case 3: - t.config.globalProperties.$pushBAIDU = u + var u = new i(s, a) + switch ( + ((n.pushBAIDU = u), + (function (t) { + var e = 2, + i = String(t.version) + return ( + '2.' === i.slice(0, 2) && (e = 2), + '3.' === i.slice(0, 2) && (e = 3), + e + ) + })(t) || 2) + ) { + case 2: + t.prototype.$pushBAIDU = u + break + case 3: + t.config.globalProperties.$pushBAIDU = u + } + s && Array.isArray(s) && u.init(), + o && + o.afterEach(function () { + var t = window.location.href + u.pv(t) + }) } - s && Array.isArray(s) && u.init(), - o.afterEach(function () { - var t = window.location.href - u.pv(t) - }) }), (t.usePush = function () { return { diff --git a/dist/vue-baidu-analytics.min.js.map b/dist/vue-baidu-analytics.min.js.map index 781ce56..cb38047 100644 --- a/dist/vue-baidu-analytics.min.js.map +++ b/dist/vue-baidu-analytics.min.js.map @@ -1 +1 @@ -{"version":3,"file":"vue-baidu-analytics.min.js","sources":["../src/modules/baidu.ts","../src/modules/pushBAIDU.ts","../node_modules/tslib/tslib.es6.js","../src/main.ts","../src/modules/getVueVersion.ts"],"sourcesContent":["/**\n * 定义基础配置\n * 官方文档 https://tongji.baidu.com/open/api/more?p=guide_overview\n */\nclass BAIDU {\n siteId: string\n isDebug: boolean\n\n constructor(siteId: string = '', isDebug: boolean = false) {\n this.siteId = siteId\n this.isDebug = isDebug\n }\n\n /**\n * 初始化\n */\n init() {\n window._hmt = window._hmt ? window._hmt : []\n const SCRIPT = document.createElement('script')\n SCRIPT['async'] = true\n SCRIPT['src'] = `https://hm.baidu.com/hm.js?${this.siteId}`\n document.querySelector('head')?.appendChild(SCRIPT)\n\n if (this.isDebug) {\n console.log(\n `[vue-baidu-analytics] siteId load done.\\nsiteId: ${this.siteId}`\n )\n }\n }\n\n /**\n * 设置要响应的站点\n */\n setAccount() {\n window._hmt.push(['_setAccount', this.siteId])\n }\n\n /**\n * 提交PV、UV\n */\n trackPageview(pageUrl: string) {\n // 如果页面链接没传或者无效链接,则默认为根域名\n if (!pageUrl || typeof pageUrl !== 'string') {\n pageUrl = '/'\n }\n\n // 如果页面链接带上了域名,则需要过滤掉\n if (pageUrl.startsWith('http')) {\n const PAGE_CUT = pageUrl.split('/')\n const HOST_NAME = `${PAGE_CUT[0]}//${PAGE_CUT[2]}`\n pageUrl = pageUrl.replace(HOST_NAME, '')\n }\n\n // 设置响应 id 并提交数据\n this.setAccount()\n window._hmt.push(['_trackPageview', pageUrl])\n\n if (this.isDebug) {\n console.log(\n `[vue-baidu-analytics] track pv done.\\nsiteId: ${this.siteId}\\npageUrl: ${pageUrl}`\n )\n }\n }\n\n /**\n * 提交点击事件\n */\n trackEvent(category: string, action: string, label: string, value: number) {\n // 前两个是必填项\n if (\n typeof category !== 'string' ||\n typeof action !== 'string' ||\n !category ||\n !action\n ) {\n throw new Error(\n '[vue-baidu-analytics] Missing necessary category and operation information, and must be of type string.'\n )\n }\n\n // 重置一些无效的默认值\n if (!label || typeof label !== 'string') {\n label = ''\n }\n\n if (!Number(value)) {\n value = 1\n }\n\n // 设置响应id并提交数据\n this.setAccount()\n window._hmt.push(['_trackEvent', category, action, label, value])\n\n if (this.isDebug) {\n console.log(\n `[vue-baidu-analytics] track event done.\\nsiteId: ${this.siteId}\\ncategory: ${category}\\naction: ${action}\\nlabel: ${label}\\nvalue: ${value}`\n )\n }\n }\n}\n\nexport default BAIDU\n","import BAIDU from '@m/baidu'\n\n/**\n * 定义推送操作\n */\nclass PushBAIDU {\n siteIdList: string[]\n isDebug: boolean\n\n constructor(siteIdList: string[], isDebug: boolean) {\n this.siteIdList = [...siteIdList]\n this.isDebug = isDebug\n }\n\n /**\n * 批量部署站点\n */\n init() {\n this.siteIdList.forEach((siteId: string) => {\n const SITE = new BAIDU(siteId, this.isDebug)\n SITE.init()\n })\n }\n\n /**\n * 批量提交pv上报\n */\n pv(pageUrl: string) {\n this.siteIdList.forEach((siteId: string) => {\n const SITE = new BAIDU(siteId, this.isDebug)\n SITE.trackPageview(pageUrl)\n })\n }\n\n /**\n * 批量提交事件上报\n */\n event(category: string, action: string, label: string, value: number) {\n this.siteIdList.forEach((siteId: string) => {\n const SITE = new BAIDU(siteId, this.isDebug)\n SITE.trackEvent(category, action, label, value)\n })\n }\n}\n\nexport default PushBAIDU\n","/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || from);\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n","import PushBAIDU from '@m/pushBAIDU'\nimport getVueVersion from '@m/getVueVersion'\nimport type { Options, Vue } from '@/types'\n\n/**\n * 全局的数据\n */\nconst __GLOBAL__ = {\n pushBAIDU: {} as PushBAIDU,\n}\n\n/**\n * 暴露 Hooks\n * @description 解决 Vue 3.0 使用全局变量很麻烦的问题\n * @example\n * import { usePush } from 'vue-baidu-analytics'\n * const baidu = usePush();\n * baidu.pv('/');\n */\nexport function usePush() {\n // 提交 pv\n function pv(pageUrl: string) {\n return __GLOBAL__.pushBAIDU.pv(pageUrl)\n }\n\n // 提交事件\n function event(\n category: string,\n action: string,\n label: string,\n value: number\n ) {\n return __GLOBAL__.pushBAIDU.event(category, action, label, value)\n }\n\n return {\n pv,\n event,\n }\n}\n\n/**\n * 定义插件\n */\nexport default function install(\n Vue: Vue,\n { router, siteIdList, isDebug = false }: Partial\n) {\n /**\n * 一些环境和参数的检查\n */\n if (typeof document === 'undefined' || typeof window === 'undefined') {\n return false\n }\n\n if (!router) {\n throw new Error(\n '[vue-baidu-analytics] Must pass a Vue-Router instance to vue-baidu-analytics.'\n )\n }\n\n if (!siteIdList) {\n throw new Error(\n '[vue-baidu-analytics] Missing tracking domain ID, add at least one of baidu analytics siteId.'\n )\n }\n\n /**\n * 挂载推送的方法\n */\n const pushBAIDU: PushBAIDU = new PushBAIDU(siteIdList, isDebug)\n __GLOBAL__.pushBAIDU = pushBAIDU\n\n /**\n * 挂载全局变量到 Vue 上\n * 获取Vue版本(获取失败则默认为2)\n */\n const VUE_VERSION: number = getVueVersion(Vue) || 2\n switch (VUE_VERSION) {\n case 2:\n Vue.prototype.$pushBAIDU = pushBAIDU\n break\n case 3:\n Vue.config.globalProperties.$pushBAIDU = pushBAIDU\n break\n }\n\n /**\n * 部署站点并初始化\n */\n if (siteIdList && Array.isArray(siteIdList)) {\n pushBAIDU.init()\n }\n\n /**\n * 路由切换时执行PV上报\n */\n router.afterEach(() => {\n // 获取要上报的链接(当前版本不需要拼接了)\n const PAGE_URL: string = window.location.href\n\n // 上报数据\n pushBAIDU.pv(PAGE_URL)\n })\n}\n","import type { Vue } from '@/types'\n\n/**\n * 获取Vue的版本\n * @return 2=Vue2.x, 3=Vue3.x\n */\nconst getVueVersion = (Vue: Vue): number => {\n let version: number = 2\n\n // 获取Vue的版本号\n const VUE_VERSION: string = String(Vue.version)\n\n // Vue 2.x\n if (VUE_VERSION.slice(0, 2) === '2.') {\n version = 2\n }\n\n // Vue 3.x\n if (VUE_VERSION.slice(0, 2) === '3.') {\n version = 3\n }\n\n return version\n}\n\nexport default getVueVersion\n"],"names":["siteId","isDebug","this","BAIDU","window","_hmt","SCRIPT","document","createElement","querySelector","appendChild","console","log","push","pageUrl","startsWith","PAGE_CUT","split","HOST_NAME","replace","setAccount","category","action","label","value","Error","Number","siteIdList","to","from","pack","arguments","length","ar","i","l","Array","prototype","slice","call","concat","PushBAIDU","forEach","_this","init","trackPageview","trackEvent","__GLOBAL__","pushBAIDU","Vue","_a","router","_b","version","VUE_VERSION","String","getVueVersion","$pushBAIDU","config","globalProperties","isArray","afterEach","PAGE_URL","location","href","pv","event"],"mappings":";;;;;;;;;;;;;;;;;;;oFAIA,iBAIE,WAAYA,EAAqBC,gBAArBD,mBAAqBC,MAC/BC,KAAKF,OAASA,EACdE,KAAKD,QAAUA,EAyFnB,OAnFEE,iBAAA,iBACEC,OAAOC,KAAOD,OAAOC,KAAOD,OAAOC,KAAO,GAC1C,IAAMC,EAASC,SAASC,cAAc,UACtCF,EAAc,OAAI,EAClBA,EAAY,IAAI,8BAA8BJ,KAAKF,iBACnDO,SAASE,cAAc,wBAASC,YAAYJ,GAExCJ,KAAKD,SACPU,QAAQC,IACN,uDAAuDV,KAAKF,SAQlEG,uBAAA,WACEC,OAAOC,KAAKQ,KAAK,CAAC,cAAeX,KAAKF,UAMxCG,0BAAA,SAAcW,GAOZ,GALKA,GAA8B,iBAAZA,IACrBA,EAAU,KAIRA,EAAQC,WAAW,QAAS,CAC9B,IAAMC,EAAWF,EAAQG,MAAM,KACzBC,EAAeF,EAAS,QAAOA,EAAS,GAC9CF,EAAUA,EAAQK,QAAQD,EAAW,IAIvChB,KAAKkB,aACLhB,OAAOC,KAAKQ,KAAK,CAAC,iBAAkBC,IAEhCZ,KAAKD,SACPU,QAAQC,IACN,oDAAoDV,KAAKF,uBAAsBc,IAQrFX,uBAAA,SAAWkB,EAAkBC,EAAgBC,EAAeC,GAE1D,GACsB,iBAAbH,GACW,iBAAXC,IACND,IACAC,EAED,MAAM,IAAIG,MACR,2GAKCF,GAA0B,iBAAVA,IACnBA,EAAQ,IAGLG,OAAOF,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YA,ECjEH,SAACC,GACrB,IAAII,EAAkB,EAGhBC,EAAsBC,OAAON,EAAII,SAYvC,MATgC,OAA5BC,EAAYhB,MAAM,EAAG,KACvBe,EAAU,GAIoB,OAA5BC,EAAYhB,MAAM,EAAG,KACvBe,EAAU,GAGLA,EDuDqBG,CAAcP,IAAQ,GAEhD,KAAK,EACHA,EAAIZ,UAAUoB,WAAaT,EAC3B,MACF,KAAK,EACHC,EAAIS,OAAOC,iBAAiBF,WAAaT,EAOzCrB,GAAcS,MAAMwB,QAAQjC,IAC9BqB,EAAUJ,OAMZO,EAAOU,WAAU,WAEf,IAAMC,EAAmB1D,OAAO2D,SAASC,KAGzChB,EAAUiB,GAAGH,4BAnEf,MAAO,CACLG,GAfF,SAAYnD,GACV,OAAOiC,EAAWC,UAAUiB,GAAGnD,IAe/BoD,MAXF,SACE7C,EACAC,EACAC,EACAC,GAEA,OAAOuB,EAAWC,UAAUkB,MAAM7C,EAAUC,EAAQC,EAAOC"} \ No newline at end of file +{"version":3,"file":"vue-baidu-analytics.min.js","sources":["../src/modules/baidu.ts","../src/modules/pushBAIDU.ts","../node_modules/tslib/tslib.es6.js","../src/main.ts","../src/modules/getVueVersion.ts"],"sourcesContent":["/**\n * 定义基础配置\n * 官方文档 https://tongji.baidu.com/open/api/more?p=guide_overview\n */\nclass BAIDU {\n siteId: string\n isDebug: boolean\n\n constructor(siteId: string = '', isDebug: boolean = false) {\n this.siteId = siteId\n this.isDebug = isDebug\n }\n\n /**\n * 初始化\n */\n init() {\n window._hmt = window._hmt ? window._hmt : []\n const SCRIPT = document.createElement('script')\n SCRIPT['async'] = true\n SCRIPT['src'] = `https://hm.baidu.com/hm.js?${this.siteId}`\n document.querySelector('head')?.appendChild(SCRIPT)\n\n if (this.isDebug) {\n console.log(\n `[vue-baidu-analytics] siteId load done.\\nsiteId: ${this.siteId}`\n )\n }\n }\n\n /**\n * 设置要响应的站点\n */\n setAccount() {\n window._hmt.push(['_setAccount', this.siteId])\n }\n\n /**\n * 提交PV、UV\n */\n trackPageview(pageUrl: string) {\n // 如果页面链接没传或者无效链接,则默认为根域名\n if (!pageUrl || typeof pageUrl !== 'string') {\n pageUrl = '/'\n }\n\n // 如果页面链接带上了域名,则需要过滤掉\n if (pageUrl.startsWith('http')) {\n const PAGE_CUT = pageUrl.split('/')\n const HOST_NAME = `${PAGE_CUT[0]}//${PAGE_CUT[2]}`\n pageUrl = pageUrl.replace(HOST_NAME, '')\n }\n\n // 设置响应 id 并提交数据\n this.setAccount()\n window._hmt.push(['_trackPageview', pageUrl])\n\n if (this.isDebug) {\n console.log(\n `[vue-baidu-analytics] track pv done.\\nsiteId: ${this.siteId}\\npageUrl: ${pageUrl}`\n )\n }\n }\n\n /**\n * 提交点击事件\n */\n trackEvent(category: string, action: string, label: string, value: number) {\n // 前两个是必填项\n if (\n typeof category !== 'string' ||\n typeof action !== 'string' ||\n !category ||\n !action\n ) {\n throw new Error(\n '[vue-baidu-analytics] Missing necessary category and operation information, and must be of type string.'\n )\n }\n\n // 重置一些无效的默认值\n if (!label || typeof label !== 'string') {\n label = ''\n }\n\n if (!Number(value)) {\n value = 1\n }\n\n // 设置响应id并提交数据\n this.setAccount()\n window._hmt.push(['_trackEvent', category, action, label, value])\n\n if (this.isDebug) {\n console.log(\n `[vue-baidu-analytics] track event done.\\nsiteId: ${this.siteId}\\ncategory: ${category}\\naction: ${action}\\nlabel: ${label}\\nvalue: ${value}`\n )\n }\n }\n}\n\nexport default BAIDU\n","import BAIDU from '@m/baidu'\n\n/**\n * 定义推送操作\n */\nclass PushBAIDU {\n siteIdList: string[]\n isDebug: boolean\n\n constructor(siteIdList: string[], isDebug: boolean) {\n this.siteIdList = [...siteIdList]\n this.isDebug = isDebug\n }\n\n /**\n * 批量部署站点\n */\n init() {\n this.siteIdList.forEach((siteId: string) => {\n const SITE = new BAIDU(siteId, this.isDebug)\n SITE.init()\n })\n }\n\n /**\n * 批量提交pv上报\n */\n pv(pageUrl: string) {\n this.siteIdList.forEach((siteId: string) => {\n const SITE = new BAIDU(siteId, this.isDebug)\n SITE.trackPageview(pageUrl)\n })\n }\n\n /**\n * 批量提交事件上报\n */\n event(category: string, action: string, label: string, value: number) {\n this.siteIdList.forEach((siteId: string) => {\n const SITE = new BAIDU(siteId, this.isDebug)\n SITE.trackEvent(category, action, label, value)\n })\n }\n}\n\nexport default PushBAIDU\n","/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || from);\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n","import PushBAIDU from '@m/pushBAIDU'\nimport getVueVersion from '@m/getVueVersion'\nimport type { Options, Vue } from '@/types'\n\n/**\n * 全局的数据\n */\nconst __GLOBAL__ = {\n pushBAIDU: {} as PushBAIDU,\n}\n\n/**\n * 暴露 Hooks\n * @description 解决 Vue 3.0 使用全局变量很麻烦的问题\n * @example\n * import { usePush } from 'vue-baidu-analytics'\n * const baidu = usePush();\n * baidu.pv('/');\n */\nexport function usePush() {\n // 提交 pv\n function pv(pageUrl: string) {\n return __GLOBAL__.pushBAIDU.pv(pageUrl)\n }\n\n // 提交事件\n function event(\n category: string,\n action: string,\n label: string,\n value: number\n ) {\n return __GLOBAL__.pushBAIDU.event(category, action, label, value)\n }\n\n return {\n pv,\n event,\n }\n}\n\n/**\n * 定义插件\n */\nexport default function install(\n Vue: Vue,\n { router, siteIdList, isDebug = false }: Partial\n) {\n /**\n * 一些环境和参数的检查\n */\n if (typeof document === 'undefined' || typeof window === 'undefined') return\n\n if (!siteIdList) {\n throw new Error(\n '[vue-baidu-analytics] Missing tracking domain ID, add at least one of baidu analytics siteId.'\n )\n }\n\n /**\n * 挂载推送的方法\n */\n const pushBAIDU: PushBAIDU = new PushBAIDU(siteIdList, isDebug)\n __GLOBAL__.pushBAIDU = pushBAIDU\n\n /**\n * 挂载全局变量到 Vue 上\n * 获取Vue版本(获取失败则默认为2)\n */\n const VUE_VERSION: number = getVueVersion(Vue) || 2\n switch (VUE_VERSION) {\n case 2:\n Vue.prototype.$pushBAIDU = pushBAIDU\n break\n case 3:\n Vue.config.globalProperties.$pushBAIDU = pushBAIDU\n break\n }\n\n /**\n * 部署站点并初始化\n */\n if (siteIdList && Array.isArray(siteIdList)) {\n pushBAIDU.init()\n }\n\n /**\n * 路由切换时执行PV上报\n */\n if (router) {\n router.afterEach(() => {\n // 获取要上报的链接(当前版本不需要拼接了)\n const PAGE_URL: string = window.location.href\n\n // 上报数据\n pushBAIDU.pv(PAGE_URL)\n })\n }\n}\n","import type { Vue } from '@/types'\n\n/**\n * 获取Vue的版本\n * @return 2=Vue2.x, 3=Vue3.x\n */\nconst getVueVersion = (Vue: Vue): number => {\n let version: number = 2\n\n // 获取Vue的版本号\n const VUE_VERSION: string = String(Vue.version)\n\n // Vue 2.x\n if (VUE_VERSION.slice(0, 2) === '2.') {\n version = 2\n }\n\n // Vue 3.x\n if (VUE_VERSION.slice(0, 2) === '3.') {\n version = 3\n }\n\n return version\n}\n\nexport default getVueVersion\n"],"names":["siteId","isDebug","this","BAIDU","window","_hmt","SCRIPT","document","createElement","querySelector","appendChild","console","log","push","pageUrl","startsWith","PAGE_CUT","split","HOST_NAME","replace","setAccount","category","action","label","value","Error","Number","siteIdList","to","from","pack","arguments","length","ar","i","l","Array","prototype","slice","call","concat","PushBAIDU","forEach","_this","init","trackPageview","trackEvent","__GLOBAL__","pushBAIDU","Vue","_a","router","_b","version","VUE_VERSION","String","getVueVersion","$pushBAIDU","config","globalProperties","isArray","afterEach","PAGE_URL","location","href","pv","event"],"mappings":";;;;;;;;;;;;;;;;;;;oFAIA,iBAIE,WAAYA,EAAqBC,gBAArBD,mBAAqBC,MAC/BC,KAAKF,OAASA,EACdE,KAAKD,QAAUA,EAyFnB,OAnFEE,iBAAA,iBACEC,OAAOC,KAAOD,OAAOC,KAAOD,OAAOC,KAAO,GAC1C,IAAMC,EAASC,SAASC,cAAc,UACtCF,EAAc,OAAI,EAClBA,EAAY,IAAI,8BAA8BJ,KAAKF,iBACnDO,SAASE,cAAc,wBAASC,YAAYJ,GAExCJ,KAAKD,SACPU,QAAQC,IACN,uDAAuDV,KAAKF,SAQlEG,uBAAA,WACEC,OAAOC,KAAKQ,KAAK,CAAC,cAAeX,KAAKF,UAMxCG,0BAAA,SAAcW,GAOZ,GALKA,GAA8B,iBAAZA,IACrBA,EAAU,KAIRA,EAAQC,WAAW,QAAS,CAC9B,IAAMC,EAAWF,EAAQG,MAAM,KACzBC,EAAeF,EAAS,QAAOA,EAAS,GAC9CF,EAAUA,EAAQK,QAAQD,EAAW,IAIvChB,KAAKkB,aACLhB,OAAOC,KAAKQ,KAAK,CAAC,iBAAkBC,IAEhCZ,KAAKD,SACPU,QAAQC,IACN,oDAAoDV,KAAKF,uBAAsBc,IAQrFX,uBAAA,SAAWkB,EAAkBC,EAAgBC,EAAeC,GAE1D,GACsB,iBAAbH,GACW,iBAAXC,IACND,IACAC,EAED,MAAM,IAAIG,MACR,2GAKCF,GAA0B,iBAAVA,IACnBA,EAAQ,IAGLG,OAAOF,KACVA,EAAQ,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EAAII,SAYvC,MATgC,OAA5BC,EAAYhB,MAAM,EAAG,KACvBe,EAAU,GAIoB,OAA5BC,EAAYhB,MAAM,EAAG,KACvBe,EAAU,GAGLA,ED+CqBG,CAAcP,IAAQ,GAEhD,KAAK,EACHA,EAAIZ,UAAUoB,WAAaT,EAC3B,MACF,KAAK,EACHC,EAAIS,OAAOC,iBAAiBF,WAAaT,EAOzCrB,GAAcS,MAAMwB,QAAQjC,IAC9BqB,EAAUJ,OAMRO,GACFA,EAAOU,WAAU,WAEf,IAAMC,EAAmB1D,OAAO2D,SAASC,KAGzChB,EAAUiB,GAAGH,6BA5DjB,MAAO,CACLG,GAfF,SAAYnD,GACV,OAAOiC,EAAWC,UAAUiB,GAAGnD,IAe/BoD,MAXF,SACE7C,EACAC,EACAC,EACAC,GAEA,OAAOuB,EAAWC,UAAUkB,MAAM7C,EAAUC,EAAQC,EAAOC"} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 863af85..596b90f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -49,15 +49,7 @@ export default function install( /** * 一些环境和参数的检查 */ - if (typeof document === 'undefined' || typeof window === 'undefined') { - return false - } - - if (!router) { - throw new Error( - '[vue-baidu-analytics] Must pass a Vue-Router instance to vue-baidu-analytics.' - ) - } + if (typeof document === 'undefined' || typeof window === 'undefined') return if (!siteIdList) { throw new Error( @@ -95,11 +87,13 @@ export default function install( /** * 路由切换时执行PV上报 */ - router.afterEach(() => { - // 获取要上报的链接(当前版本不需要拼接了) - const PAGE_URL: string = window.location.href + if (router) { + router.afterEach(() => { + // 获取要上报的链接(当前版本不需要拼接了) + const PAGE_URL: string = window.location.href - // 上报数据 - pushBAIDU.pv(PAGE_URL) - }) + // 上报数据 + pushBAIDU.pv(PAGE_URL) + }) + } }