mirror of
https://github.com/analyticsjs/vue-baidu-analytics.git
synced 2025-04-04 23:42:46 +08:00
chore: update eslint rule
This commit is contained in:
parent
900b744a5b
commit
ed3e666286
1
.eslintignore
Normal file
1
.eslintignore
Normal file
@ -0,0 +1 @@
|
||||
dist/*
|
41
dist/main.d.ts
vendored
41
dist/main.d.ts
vendored
@ -1,16 +1,25 @@
|
||||
/**
|
||||
* 暴露 Hooks
|
||||
* @description 解决 Vue 3.0 使用全局变量很麻烦的问题
|
||||
* @example
|
||||
* import { usePush } from 'vue-baidu-analytics'
|
||||
* const baidu = usePush();
|
||||
* baidu.pv('/');
|
||||
*/
|
||||
export declare function usePush(): {
|
||||
pv: (pageUrl: string) => void;
|
||||
event: (category: string, action: string, label: string, value: number) => void;
|
||||
};
|
||||
/**
|
||||
* 定义插件
|
||||
*/
|
||||
export default function install(Vue: Vue, { router, siteIdList, isDebug }: Partial<Options>): false | undefined;
|
||||
import type { Options, Vue } from '@/types'
|
||||
/**
|
||||
* 暴露 Hooks
|
||||
* @description 解决 Vue 3.0 使用全局变量很麻烦的问题
|
||||
* @example
|
||||
* import { usePush } from 'vue-baidu-analytics'
|
||||
* const baidu = usePush();
|
||||
* baidu.pv('/');
|
||||
*/
|
||||
export declare function usePush(): {
|
||||
pv: (pageUrl: string) => void
|
||||
event: (
|
||||
category: string,
|
||||
action: string,
|
||||
label: string,
|
||||
value: number
|
||||
) => void
|
||||
}
|
||||
/**
|
||||
* 定义插件
|
||||
*/
|
||||
export default function install(
|
||||
Vue: Vue,
|
||||
{ router, siteIdList, isDebug }: Partial<Options>
|
||||
): false | undefined
|
||||
|
13
dist/modules/getVueVersion.d.ts
vendored
13
dist/modules/getVueVersion.d.ts
vendored
@ -1,6 +1,7 @@
|
||||
/**
|
||||
* 获取Vue的版本
|
||||
* @return 2=Vue2.x, 3=Vue3.x
|
||||
*/
|
||||
declare const getVueVersion: (Vue: Vue) => number;
|
||||
export default getVueVersion;
|
||||
import type { Vue } from '@/types'
|
||||
/**
|
||||
* 获取Vue的版本
|
||||
* @return 2=Vue2.x, 3=Vue3.x
|
||||
*/
|
||||
declare const getVueVersion: (Vue: Vue) => number
|
||||
export default getVueVersion
|
||||
|
12
dist/types.d.ts
vendored
Normal file
12
dist/types.d.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
import PushBAIDU from '@m/pushBAIDU'
|
||||
export interface Options {
|
||||
router: any
|
||||
siteIdList: string[]
|
||||
isDebug: boolean
|
||||
}
|
||||
export interface Vue {
|
||||
prototype: any
|
||||
$pushBAIDU: PushBAIDU
|
||||
version: number | string
|
||||
config: any
|
||||
}
|
531
dist/vue-baidu-analytics.js
vendored
531
dist/vue-baidu-analytics.js
vendored
@ -1,255 +1,302 @@
|
||||
/*!
|
||||
* name: vue-baidu-analytics
|
||||
* version: v2.1.0
|
||||
* version: v2.2.0
|
||||
* author: chengpeiquan
|
||||
*/
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
||||
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.baiduAnalytics = {}));
|
||||
}(this, (function (exports) { 'use strict';
|
||||
;(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined'
|
||||
? factory(exports)
|
||||
: typeof define === 'function' && define.amd
|
||||
? define(['exports'], factory)
|
||||
: ((global =
|
||||
typeof globalThis !== 'undefined' ? globalThis : global || self),
|
||||
factory((global.baiduAnalytics = {})))
|
||||
})(this, function (exports) {
|
||||
'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.
|
||||
/*! *****************************************************************************
|
||||
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.
|
||||
***************************************************************************** */
|
||||
function __spreadArray(to, from) {
|
||||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) to[j] = from[i];
|
||||
function __spreadArray(to, from, pack) {
|
||||
if (pack || arguments.length === 2)
|
||||
for (var i = 0, l = from.length, ar; i < l; i++) {
|
||||
if (ar || !(i in from)) {
|
||||
if (!ar) ar = Array.prototype.slice.call(from, 0, i)
|
||||
ar[i] = from[i]
|
||||
}
|
||||
}
|
||||
return to.concat(ar || from)
|
||||
}
|
||||
|
||||
return to;
|
||||
/**
|
||||
* 定义基础配置
|
||||
* 官方文档 https://tongji.baidu.com/open/api/more?p=guide_overview
|
||||
*/
|
||||
var BAIDU = /** @class */ (function () {
|
||||
function BAIDU(siteId, isDebug) {
|
||||
if (siteId === void 0) {
|
||||
siteId = ''
|
||||
}
|
||||
if (isDebug === void 0) {
|
||||
isDebug = false
|
||||
}
|
||||
this.siteId = siteId
|
||||
this.isDebug = isDebug
|
||||
}
|
||||
|
||||
/**
|
||||
* 定义基础配置
|
||||
* 官方文档 https://tongji.baidu.com/open/api/more?p=guide_overview
|
||||
*/
|
||||
var BAIDU = /** @class */ (function () {
|
||||
function BAIDU(siteId, isDebug) {
|
||||
if (siteId === void 0) { siteId = ''; }
|
||||
if (isDebug === void 0) { isDebug = false; }
|
||||
this.siteId = siteId;
|
||||
this.isDebug = isDebug;
|
||||
}
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
BAIDU.prototype.init = function () {
|
||||
var _a;
|
||||
window._hmt = window._hmt ? window._hmt : [];
|
||||
var SCRIPT = document.createElement('script');
|
||||
SCRIPT['async'] = true;
|
||||
SCRIPT['src'] = "https://hm.baidu.com/hm.js?" + this.siteId;
|
||||
(_a = document.querySelector('head')) === null || _a === void 0 ? void 0 : _a.appendChild(SCRIPT);
|
||||
if (this.isDebug) {
|
||||
console.log("[vue-baidu-analytics] siteId load done.\nsiteId: " + this.siteId);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* 设置要响应的站点
|
||||
*/
|
||||
BAIDU.prototype.setAccount = function () {
|
||||
window._hmt.push(['_setAccount', this.siteId]);
|
||||
};
|
||||
/**
|
||||
* 提交PV、UV
|
||||
*/
|
||||
BAIDU.prototype.trackPageview = function (pageUrl) {
|
||||
// 如果页面链接没传或者无效链接,则默认为根域名
|
||||
if (!pageUrl || typeof pageUrl !== 'string') {
|
||||
pageUrl = '/';
|
||||
}
|
||||
// 如果页面链接带上了域名,则需要过滤掉
|
||||
if (pageUrl.includes('http')) {
|
||||
var PAGE_CUT = pageUrl.split('/');
|
||||
var HOST_NAME = PAGE_CUT[0] + "//" + PAGE_CUT[2];
|
||||
pageUrl = pageUrl.replace(HOST_NAME, '');
|
||||
}
|
||||
// 设置响应 id 并提交数据
|
||||
this.setAccount();
|
||||
window._hmt.push(['_trackPageview', pageUrl]);
|
||||
if (this.isDebug) {
|
||||
console.log("[vue-baidu-analytics] track pv done.\nsiteId: " + this.siteId + "\npageUrl: " + pageUrl);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* 提交点击事件
|
||||
*/
|
||||
BAIDU.prototype.trackEvent = function (category, action, label, value) {
|
||||
// 前两个是必填项
|
||||
if (typeof category !== 'string' || typeof action !== 'string' || !category || !action) {
|
||||
throw new Error('[vue-baidu-analytics] Missing necessary category and operation information, and must be of type string.');
|
||||
}
|
||||
// 重置一些无效的默认值
|
||||
if (!label || typeof label !== 'string') {
|
||||
label = '';
|
||||
}
|
||||
if (!Number(value)) {
|
||||
value = 1;
|
||||
}
|
||||
// 设置响应id并提交数据
|
||||
this.setAccount();
|
||||
window._hmt.push(['_trackEvent', category, action, label, value]);
|
||||
if (this.isDebug) {
|
||||
console.log("[vue-baidu-analytics] track event done.\nsiteId: " + this.siteId + "\ncategory: " + category + "\naction: " + action + "\nlabel: " + label + "\nvalue: " + value);
|
||||
}
|
||||
};
|
||||
return BAIDU;
|
||||
}());
|
||||
|
||||
/**
|
||||
* 定义推送操作
|
||||
*/
|
||||
var PushBAIDU = /** @class */ (function () {
|
||||
function PushBAIDU(siteIdList, isDebug) {
|
||||
this.siteIdList = __spreadArray([], siteIdList);
|
||||
this.isDebug = isDebug;
|
||||
}
|
||||
/**
|
||||
* 批量部署站点
|
||||
*/
|
||||
PushBAIDU.prototype.init = function () {
|
||||
var _this = this;
|
||||
this.siteIdList.forEach(function (siteId) {
|
||||
var SITE = new BAIDU(siteId, _this.isDebug);
|
||||
SITE.init();
|
||||
});
|
||||
};
|
||||
/**
|
||||
* 批量提交pv上报
|
||||
*/
|
||||
PushBAIDU.prototype.pv = function (pageUrl) {
|
||||
var _this = this;
|
||||
this.siteIdList.forEach(function (siteId) {
|
||||
var SITE = new BAIDU(siteId, _this.isDebug);
|
||||
SITE.trackPageview(pageUrl);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* 批量提交事件上报
|
||||
*/
|
||||
PushBAIDU.prototype.event = function (category, action, label, value) {
|
||||
var _this = this;
|
||||
this.siteIdList.forEach(function (siteId) {
|
||||
var SITE = new BAIDU(siteId, _this.isDebug);
|
||||
SITE.trackEvent(category, action, label, value);
|
||||
});
|
||||
};
|
||||
return PushBAIDU;
|
||||
}());
|
||||
|
||||
/**
|
||||
* 获取Vue的版本
|
||||
* @return 2=Vue2.x, 3=Vue3.x
|
||||
*/
|
||||
var getVueVersion = function (Vue) {
|
||||
var version = 2;
|
||||
// 获取Vue的版本号
|
||||
var VUE_VERSION = String(Vue.version);
|
||||
// Vue 2.x
|
||||
if (VUE_VERSION.slice(0, 2) === '2.') {
|
||||
version = 2;
|
||||
}
|
||||
// Vue 3.x
|
||||
if (VUE_VERSION.slice(0, 2) === '3.') {
|
||||
version = 3;
|
||||
}
|
||||
return version;
|
||||
};
|
||||
|
||||
/**
|
||||
* 全局的数据
|
||||
*/
|
||||
var __GLOBAL__ = {
|
||||
pushBAIDU: {}
|
||||
};
|
||||
/**
|
||||
* 暴露 Hooks
|
||||
* @description 解决 Vue 3.0 使用全局变量很麻烦的问题
|
||||
* @example
|
||||
* import { usePush } from 'vue-baidu-analytics'
|
||||
* const baidu = usePush();
|
||||
* baidu.pv('/');
|
||||
*/
|
||||
function usePush() {
|
||||
// 提交 pv
|
||||
function pv(pageUrl) {
|
||||
return __GLOBAL__.pushBAIDU.pv(pageUrl);
|
||||
}
|
||||
// 提交事件
|
||||
function event(category, action, label, value) {
|
||||
return __GLOBAL__.pushBAIDU.event(category, action, label, value);
|
||||
}
|
||||
return {
|
||||
pv: pv,
|
||||
event: event
|
||||
};
|
||||
}
|
||||
/**
|
||||
* 定义插件
|
||||
*/
|
||||
function install(Vue, _a) {
|
||||
var router = _a.router, siteIdList = _a.siteIdList, _b = _a.isDebug, isDebug = _b === void 0 ? false : _b;
|
||||
/**
|
||||
* 一些环境和参数的检查
|
||||
*/
|
||||
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 (!siteIdList) {
|
||||
throw new Error('[vue-baidu-analytics] Missing tracking domain ID, add at least one of baidu analytics siteId.');
|
||||
}
|
||||
/**
|
||||
* 挂载推送的方法
|
||||
*/
|
||||
var pushBAIDU = new PushBAIDU(siteIdList, isDebug);
|
||||
__GLOBAL__.pushBAIDU = pushBAIDU;
|
||||
/**
|
||||
* 挂载全局变量到 Vue 上
|
||||
* 获取Vue版本(获取失败则默认为2)
|
||||
*/
|
||||
var VUE_VERSION = getVueVersion(Vue) || 2;
|
||||
switch (VUE_VERSION) {
|
||||
case 2:
|
||||
Vue.prototype.$pushBAIDU = pushBAIDU;
|
||||
break;
|
||||
case 3:
|
||||
Vue.config.globalProperties.$pushBAIDU = pushBAIDU;
|
||||
break;
|
||||
}
|
||||
/**
|
||||
* 部署站点并初始化
|
||||
*/
|
||||
if (siteIdList && Array.isArray(siteIdList)) {
|
||||
pushBAIDU.init();
|
||||
}
|
||||
/**
|
||||
* 路由切换时执行PV上报
|
||||
*/
|
||||
router.afterEach(function (to) {
|
||||
// 获取要上报的链接(当前版本不需要拼接了)
|
||||
var PAGE_URL = window.location.href;
|
||||
// 上报数据
|
||||
pushBAIDU.pv(PAGE_URL);
|
||||
});
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
BAIDU.prototype.init = function () {
|
||||
var _a
|
||||
window._hmt = window._hmt ? window._hmt : []
|
||||
var SCRIPT = document.createElement('script')
|
||||
SCRIPT['async'] = true
|
||||
SCRIPT['src'] = 'https://hm.baidu.com/hm.js?' + this.siteId
|
||||
;(_a = document.querySelector('head')) === null || _a === void 0
|
||||
? void 0
|
||||
: _a.appendChild(SCRIPT)
|
||||
if (this.isDebug) {
|
||||
console.log(
|
||||
'[vue-baidu-analytics] siteId load done.\nsiteId: ' + this.siteId
|
||||
)
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 设置要响应的站点
|
||||
*/
|
||||
BAIDU.prototype.setAccount = function () {
|
||||
window._hmt.push(['_setAccount', this.siteId])
|
||||
}
|
||||
/**
|
||||
* 提交PV、UV
|
||||
*/
|
||||
BAIDU.prototype.trackPageview = function (pageUrl) {
|
||||
// 如果页面链接没传或者无效链接,则默认为根域名
|
||||
if (!pageUrl || typeof pageUrl !== 'string') {
|
||||
pageUrl = '/'
|
||||
}
|
||||
// 如果页面链接带上了域名,则需要过滤掉
|
||||
if (pageUrl.startsWith('http')) {
|
||||
var PAGE_CUT = pageUrl.split('/')
|
||||
var HOST_NAME = PAGE_CUT[0] + '//' + PAGE_CUT[2]
|
||||
pageUrl = pageUrl.replace(HOST_NAME, '')
|
||||
}
|
||||
// 设置响应 id 并提交数据
|
||||
this.setAccount()
|
||||
window._hmt.push(['_trackPageview', pageUrl])
|
||||
if (this.isDebug) {
|
||||
console.log(
|
||||
'[vue-baidu-analytics] track pv done.\nsiteId: ' +
|
||||
this.siteId +
|
||||
'\npageUrl: ' +
|
||||
pageUrl
|
||||
)
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 提交点击事件
|
||||
*/
|
||||
BAIDU.prototype.trackEvent = function (category, action, label, value) {
|
||||
// 前两个是必填项
|
||||
if (
|
||||
typeof category !== 'string' ||
|
||||
typeof action !== 'string' ||
|
||||
!category ||
|
||||
!action
|
||||
) {
|
||||
throw new Error(
|
||||
'[vue-baidu-analytics] Missing necessary category and operation information, and must be of type string.'
|
||||
)
|
||||
}
|
||||
// 重置一些无效的默认值
|
||||
if (!label || typeof label !== 'string') {
|
||||
label = ''
|
||||
}
|
||||
if (!Number(value)) {
|
||||
value = 1
|
||||
}
|
||||
// 设置响应id并提交数据
|
||||
this.setAccount()
|
||||
window._hmt.push(['_trackEvent', category, action, label, value])
|
||||
if (this.isDebug) {
|
||||
console.log(
|
||||
'[vue-baidu-analytics] track event done.\nsiteId: ' +
|
||||
this.siteId +
|
||||
'\ncategory: ' +
|
||||
category +
|
||||
'\naction: ' +
|
||||
action +
|
||||
'\nlabel: ' +
|
||||
label +
|
||||
'\nvalue: ' +
|
||||
value
|
||||
)
|
||||
}
|
||||
}
|
||||
return BAIDU
|
||||
})()
|
||||
|
||||
exports.default = install;
|
||||
exports.usePush = usePush;
|
||||
/**
|
||||
* 定义推送操作
|
||||
*/
|
||||
var PushBAIDU = /** @class */ (function () {
|
||||
function PushBAIDU(siteIdList, isDebug) {
|
||||
this.siteIdList = __spreadArray([], siteIdList)
|
||||
this.isDebug = isDebug
|
||||
}
|
||||
/**
|
||||
* 批量部署站点
|
||||
*/
|
||||
PushBAIDU.prototype.init = function () {
|
||||
var _this = this
|
||||
this.siteIdList.forEach(function (siteId) {
|
||||
var SITE = new BAIDU(siteId, _this.isDebug)
|
||||
SITE.init()
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 批量提交pv上报
|
||||
*/
|
||||
PushBAIDU.prototype.pv = function (pageUrl) {
|
||||
var _this = this
|
||||
this.siteIdList.forEach(function (siteId) {
|
||||
var SITE = new BAIDU(siteId, _this.isDebug)
|
||||
SITE.trackPageview(pageUrl)
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 批量提交事件上报
|
||||
*/
|
||||
PushBAIDU.prototype.event = function (category, action, label, value) {
|
||||
var _this = this
|
||||
this.siteIdList.forEach(function (siteId) {
|
||||
var SITE = new BAIDU(siteId, _this.isDebug)
|
||||
SITE.trackEvent(category, action, label, value)
|
||||
})
|
||||
}
|
||||
return PushBAIDU
|
||||
})()
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
/**
|
||||
* 获取Vue的版本
|
||||
* @return 2=Vue2.x, 3=Vue3.x
|
||||
*/
|
||||
var getVueVersion = function (Vue) {
|
||||
var version = 2
|
||||
// 获取Vue的版本号
|
||||
var VUE_VERSION = String(Vue.version)
|
||||
// Vue 2.x
|
||||
if (VUE_VERSION.slice(0, 2) === '2.') {
|
||||
version = 2
|
||||
}
|
||||
// Vue 3.x
|
||||
if (VUE_VERSION.slice(0, 2) === '3.') {
|
||||
version = 3
|
||||
}
|
||||
return version
|
||||
}
|
||||
|
||||
})));
|
||||
/**
|
||||
* 全局的数据
|
||||
*/
|
||||
var __GLOBAL__ = {
|
||||
pushBAIDU: {},
|
||||
}
|
||||
/**
|
||||
* 暴露 Hooks
|
||||
* @description 解决 Vue 3.0 使用全局变量很麻烦的问题
|
||||
* @example
|
||||
* import { usePush } from 'vue-baidu-analytics'
|
||||
* const baidu = usePush();
|
||||
* baidu.pv('/');
|
||||
*/
|
||||
function usePush() {
|
||||
// 提交 pv
|
||||
function pv(pageUrl) {
|
||||
return __GLOBAL__.pushBAIDU.pv(pageUrl)
|
||||
}
|
||||
// 提交事件
|
||||
function event(category, action, label, value) {
|
||||
return __GLOBAL__.pushBAIDU.event(category, action, label, value)
|
||||
}
|
||||
return {
|
||||
pv: pv,
|
||||
event: event,
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 定义插件
|
||||
*/
|
||||
function install(Vue, _a) {
|
||||
var router = _a.router,
|
||||
siteIdList = _a.siteIdList,
|
||||
_b = _a.isDebug,
|
||||
isDebug = _b === void 0 ? false : _b
|
||||
/**
|
||||
* 一些环境和参数的检查
|
||||
*/
|
||||
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 (!siteIdList) {
|
||||
throw new Error(
|
||||
'[vue-baidu-analytics] Missing tracking domain ID, add at least one of baidu analytics siteId.'
|
||||
)
|
||||
}
|
||||
/**
|
||||
* 挂载推送的方法
|
||||
*/
|
||||
var pushBAIDU = new PushBAIDU(siteIdList, isDebug)
|
||||
__GLOBAL__.pushBAIDU = pushBAIDU
|
||||
/**
|
||||
* 挂载全局变量到 Vue 上
|
||||
* 获取Vue版本(获取失败则默认为2)
|
||||
*/
|
||||
var VUE_VERSION = getVueVersion(Vue) || 2
|
||||
switch (VUE_VERSION) {
|
||||
case 2:
|
||||
Vue.prototype.$pushBAIDU = pushBAIDU
|
||||
break
|
||||
case 3:
|
||||
Vue.config.globalProperties.$pushBAIDU = pushBAIDU
|
||||
break
|
||||
}
|
||||
/**
|
||||
* 部署站点并初始化
|
||||
*/
|
||||
if (siteIdList && Array.isArray(siteIdList)) {
|
||||
pushBAIDU.init()
|
||||
}
|
||||
/**
|
||||
* 路由切换时执行PV上报
|
||||
*/
|
||||
router.afterEach(function () {
|
||||
// 获取要上报的链接(当前版本不需要拼接了)
|
||||
var PAGE_URL = window.location.href
|
||||
// 上报数据
|
||||
pushBAIDU.pv(PAGE_URL)
|
||||
})
|
||||
}
|
||||
|
||||
exports.default = install
|
||||
exports.usePush = usePush
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true })
|
||||
})
|
||||
//# sourceMappingURL=vue-baidu-analytics.js.map
|
||||
|
2
dist/vue-baidu-analytics.js.map
vendored
2
dist/vue-baidu-analytics.js.map
vendored
File diff suppressed because one or more lines are too long
186
dist/vue-baidu-analytics.min.js
vendored
186
dist/vue-baidu-analytics.min.js
vendored
@ -1,7 +1,189 @@
|
||||
/*!
|
||||
* name: vue-baidu-analytics
|
||||
* version: v2.1.0
|
||||
* version: v2.2.0
|
||||
* author: chengpeiquan
|
||||
*/
|
||||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).baiduAnalytics={})}(this,(function(t){"use strict";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.includes("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){for(var i=0,n=e.length,o=t.length;i<n;i++,o++)t[o]=e[i];return t}([],t),this.isDebug=e}return t.prototype.init=function(){var t=this;this.siteIdList.forEach((function(i){new e(i,t.isDebug).init()}))},t.prototype.pv=function(t){var i=this;this.siteIdList.forEach((function(n){new e(n,i.isDebug).trackPageview(t)}))},t.prototype.event=function(t,i,n,o){var s=this;this.siteIdList.forEach((function(r){new e(r,s.isDebug).trackEvent(t,i,n,o)}))},t}(),n={pushBAIDU:{}};t.default=function(t,e){var o=e.router,s=e.siteIdList,r=e.isDebug,u=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 a=new i(s,u);switch(n.pushBAIDU=a,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=a;break;case 3:t.config.globalProperties.$pushBAIDU=a}s&&Array.isArray(s)&&a.init(),o.afterEach((function(t){var e=window.location.href;a.pv(e)}))},t.usePush=function(){return{pv:function(t){return n.pushBAIDU.pv(t)},event:function(t,e,i,o){return n.pushBAIDU.event(t,e,i,o)}}},Object.defineProperty(t,"__esModule",{value:!0})}));
|
||||
!(function (t, e) {
|
||||
'object' == typeof exports && 'undefined' != typeof module
|
||||
? e(exports)
|
||||
: 'function' == typeof define && define.amd
|
||||
? define(['exports'], e)
|
||||
: e(
|
||||
((t =
|
||||
'undefined' != typeof globalThis
|
||||
? globalThis
|
||||
: t || self).baiduAnalytics = {})
|
||||
)
|
||||
})(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.'
|
||||
)
|
||||
;(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) {
|
||||
if (i || 2 === arguments.length)
|
||||
for (var n, o = 0, s = e.length; o < s; o++)
|
||||
(!n && o in e) ||
|
||||
(n || (n = Array.prototype.slice.call(e, 0, o)), (n[o] = e[o]))
|
||||
return t.concat(n || e)
|
||||
})([], t)),
|
||||
(this.isDebug = e)
|
||||
}
|
||||
return (
|
||||
(t.prototype.init = function () {
|
||||
var t = this
|
||||
this.siteIdList.forEach(function (i) {
|
||||
new e(i, t.isDebug).init()
|
||||
})
|
||||
}),
|
||||
(t.prototype.pv = function (t) {
|
||||
var i = this
|
||||
this.siteIdList.forEach(function (n) {
|
||||
new e(n, i.isDebug).trackPageview(t)
|
||||
})
|
||||
}),
|
||||
(t.prototype.event = function (t, i, n, o) {
|
||||
var s = this
|
||||
this.siteIdList.forEach(function (r) {
|
||||
new e(r, s.isDebug).trackEvent(t, i, n, o)
|
||||
})
|
||||
}),
|
||||
t
|
||||
)
|
||||
})(),
|
||||
n = { pushBAIDU: {} }
|
||||
;(t.default = function (t, e) {
|
||||
var o = e.router,
|
||||
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
|
||||
)
|
||||
})(t) || 2)
|
||||
) {
|
||||
case 2:
|
||||
t.prototype.$pushBAIDU = u
|
||||
break
|
||||
case 3:
|
||||
t.config.globalProperties.$pushBAIDU = u
|
||||
}
|
||||
s && Array.isArray(s) && u.init(),
|
||||
o.afterEach(function () {
|
||||
var t = window.location.href
|
||||
u.pv(t)
|
||||
})
|
||||
}),
|
||||
(t.usePush = function () {
|
||||
return {
|
||||
pv: function (t) {
|
||||
return n.pushBAIDU.pv(t)
|
||||
},
|
||||
event: function (t, e, i, o) {
|
||||
return n.pushBAIDU.event(t, e, i, o)
|
||||
},
|
||||
}
|
||||
}),
|
||||
Object.defineProperty(t, '__esModule', { value: !0 })
|
||||
})
|
||||
//# sourceMappingURL=vue-baidu-analytics.min.js.map
|
||||
|
2
dist/vue-baidu-analytics.min.js.map
vendored
2
dist/vue-baidu-analytics.min.js.map
vendored
File diff suppressed because one or more lines are too long
@ -2829,7 +2829,7 @@ to-regex-range@^5.0.1:
|
||||
dependencies:
|
||||
is-number "^7.0.0"
|
||||
|
||||
tslib@2.1.0, tslib@^2.0.1:
|
||||
tslib@2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a"
|
||||
integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==
|
||||
@ -2839,6 +2839,11 @@ tslib@^1.8.1, tslib@^1.9.0:
|
||||
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
|
||||
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
|
||||
|
||||
tslib@^2.3.0:
|
||||
version "2.3.0"
|
||||
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.0.tgz#803b8cdab3e12ba581a4ca41c8839bbb0dacb09e"
|
||||
integrity sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==
|
||||
|
||||
tsutils@^3.17.1:
|
||||
version "3.21.0"
|
||||
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623"
|
||||
|
Loading…
x
Reference in New Issue
Block a user