Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit b554612

Browse files
committed
'release'
1 parent 33f2f9c commit b554612

16 files changed

Lines changed: 12064 additions & 2 deletions

File tree

.browserslistrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
> 1%
2+
last 2 versions

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
indent_size = 2
8+
indent_style = space
9+
insert_final_newline = true
10+
max_line_length = 80
11+
trim_trailing_whitespace = true
12+
13+
[*.md]
14+
max_line_length = 0
15+
trim_trailing_whitespace = false

.eslintrc.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
node: true
5+
},
6+
'extends': [
7+
'plugin:vue/essential',
8+
'eslint:recommended'
9+
],
10+
rules: {
11+
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
12+
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
13+
},
14+
parserOptions: {
15+
parser: 'babel-eslint'
16+
}
17+
}

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.DS_Store
2+
node_modules
3+
/dist
4+
5+
# local env files
6+
.env.local
7+
.env.*.local
8+
9+
# Log files
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
14+
# Editor directories and files
15+
.idea
16+
.vscode
17+
*.suo
18+
*.ntvs*
19+
*.njsproj
20+
*.sln
21+
*.sw?

README.md

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,130 @@
1-
# vue-baidu-analytics
2-
A data collection tool that supports reporting of single-page application data built by Vue-cli, based on Baidu statistics.
1+
vue-baidu-analytics 使用说明
2+
===
3+
4+
基于Vue-CLI 3.0开发的百度统计插件,支持自动上报切换路由产生的流量数据,同时对官方api进行了二次封装,简化了手动上报数据的操作。
5+
6+
本插件支持部署多个站点id并对应上报数据(需求背景:比如部门A和部门B合作的项目,两个部门都要加上自己的统计代码算入自己的业绩流量池…)。
7+
8+
## 功能
9+
10+
* 异步载入百度统计脚本,无需修改入口html
11+
12+
* 支持部署多个站点id,并对应进行数据上报
13+
14+
* 支持自动上报路由切换产生的pv数据(支持hash模式和history模式)
15+
16+
* 支持手动提交pv上报
17+
18+
* 支持手动提交事件分析上报
19+
20+
## 参数
21+
22+
参数|是否必填|参数类型|参数说明
23+
:-:|:-:|::-
24+
router|是|JSON Object|Vue Router,本插件基于路由使用
25+
siteIdList|是|Array|百度统计的站点id列表,item为站点id<br>只有一个站点需要上报就保留一个item即可
26+
debug|否|Boolean|是否开启debug模式,默认false<br>开启后会在控制台打印上报信息,上线前记得关闭
27+
28+
## 安装
29+
30+
在npm上安装
31+
32+
>npm i vue-baidu-analytics
33+
34+
然后在 main.js 里引入插件。
35+
36+
```javascript
37+
import baiduAnalytics from 'vue-baidu-analytics'
38+
```
39+
40+
## 使用
41+
42+
安装插件后,在 main.js 引入以下代码,即可开启自动上报功能,首次访问页面会部署统计代码并提交第一次访问数据上报。
43+
44+
后续在路由切换过程中,也会根据路由的切换提交相应的url信息到百度统计。
45+
46+
```javascript
47+
Vue.use(baiduAnalytics, {
48+
router: router,
49+
siteIdList: [
50+
'your siteid',
51+
'your another siteid',
52+
'your one more siteid',
53+
''
54+
],
55+
debug: false
56+
});
57+
```
58+
59+
可在开发环境打开debug模式了解相关的上报情况(上线前记得关闭debug)。
60+
61+
## api
62+
63+
插件目前封装了两个常用的api,可在组件里调用。
64+
65+
注:如果配置了多个站点id,会同时上报给所有站点。
66+
67+
### 手动上报PV
68+
69+
api名称|功能说明
70+
:-:|::-
71+
$trackBaiduPv|手动执行PV数据上报
72+
73+
#### api参数
74+
75+
参数|是否必填|参数类型|参数说明
76+
:-:|:-:|::-
77+
url|否|String|提交上报的url,必须是以"/"(斜杠)开头的相对路径<br>如果不填,则会默认提交为域名根目录
78+
79+
详细的参数使用要求请查看官方文档:
80+
81+
>https://tongji.baidu.com/open/api/more?p=guide_trackPageview
82+
83+
注:原本url是必填,插件处理了一个默认值,所以变成选填。
84+
85+
#### 使用示范
86+
87+
在template里使用
88+
89+
```html
90+
<button @click="$trackBaiduPv('/test')">手动上报PV</button>
91+
```
92+
93+
在method里使用
94+
95+
```javascript
96+
this.$trackBaiduPv('/test');
97+
```
98+
99+
### 手动上报事件分析
100+
101+
api名称|功能说明
102+
:-:|::-
103+
$trackBaiduEvent|手动执行事件分析数据上报
104+
105+
#### api参数
106+
107+
参数|是否必填|参数类型|参数说明
108+
:-:|:-:|::-
109+
category|是|String|事件名称
110+
action|是|String|交互动作
111+
opt_label|否|String|事件信息,默认为空
112+
opt_value|否|Number|事件价值,默认1
113+
114+
详细的参数使用要求请查看官方文档
115+
116+
>https://tongji.baidu.com/open/api/more?p=guide_trackEvent
117+
118+
#### 使用示范
119+
120+
在template里使用
121+
122+
```html
123+
<button @click="$trackBaiduEvent('act_vote', 'click', 'works', 1)">手动上报分析事件</button>
124+
```
125+
126+
在method里使用
127+
128+
```javascript
129+
this.$trackBaiduEvent('act_vote', 'click', 'works', 1);
130+
```

babel.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
presets: [
3+
'@vue/cli-plugin-babel/preset'
4+
]
5+
}

0 commit comments

Comments
 (0)