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

Commit 4524371

Browse files
committed
release: v2.2.0
1 parent 805de8a commit 4524371

24 files changed

+1631
-801
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/*
2+
demo/*

.eslintrc.js

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

.eslintrc.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true
4+
}

README.en.md

Lines changed: 315 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,315 @@
1+
<p align='center'>
2+
<img src="https://cdn.jsdelivr.net/gh/chengpeiquan/assets-storage/img/2021/04/20210405010440.png" alt="vue-cnzz-analytics" />
3+
</p>
4+
5+
<p align='center'>
6+
<a href='https://www.npmjs.com/package/vue-cnzz-analytics'>
7+
<img src="https://img.shields.io/npm/v/vue-cnzz-analytics?color=41b883&label=npm" />
8+
</a>
9+
</p>
10+
<br>
11+
<br>
12+
13+
English | [简体中文](https://github.com/analyticsjs/vue-cnzz-analytics/blob/master/README.zh-CN.md)
14+
15+
Only 3 kB, this plugin base on the CNZZ analytics, it can help you quickly to collect the page views on your website, including single page web application.
16+
17+
Projects using this plugin need to be import [Vue Router](https://router.vuejs.org/) .
18+
19+
>Since the version v2.0.0, it supports the Vue 3.0, and is compatible with the Vue 2.0, you can see the live demo to learn more.<br>If you haven’t started using Vue 3.0, welcome to read the tutorial [learning Vue3](https://vue3.chengpeiquan.com/) .
20+
21+
## Features
22+
23+
* Asynchronously load the CNZZ analytics scripts, no need to modify the entry HTML.
24+
25+
* Support the deployment of multiple site IDs and corresponding data reporting.
26+
27+
* Supports automatic reporting of PV data generated by route switching (supports hash mode and history mode).
28+
29+
* Support manual submission of page views reports.
30+
31+
* Support manual submission of event reports.
32+
33+
* Since the version v2.0.0, the plugin can automatically recognize the Vue version at Vue 2.0 or Vue 3.0 .
34+
35+
* Since the version v2.1.0, Hooks API is provided (So the usage of CDN installation is slightly adjusted)
36+
37+
## Project
38+
39+
As long as Vue and Vue Router are introduced, the projects can be used normally, no matter what method is used to develop your project, e.g. :
40+
41+
* Vue-CLI scaffolding project
42+
43+
* Vite project
44+
45+
* Introduce the HTML page of Vue related CDN
46+
47+
* VuePress project
48+
49+
It is not limited to SPA single page projects, it can also be used in SSG / SSR projects.
50+
51+
## Preview
52+
53+
Both live demos have enabled debug mode, and you can open the console to view the report.
54+
55+
Vue 2.0 :[vue-cnzz-analytics demo for Vue 2.x](https://analyticsjs.github.io/vue-cnzz-analytics/demo/vue2.html "vue-cnzz-analytics demo for Vue 2.x")
56+
57+
Vue 3.0 :[vue-cnzz-analytics demo for Vue 3.x](https://analyticsjs.github.io/vue-cnzz-analytics/demo/vue3.html "vue-cnzz-analytics demo for Vue 3.x")
58+
59+
## Options
60+
61+
Option|Required|Type|Description
62+
:-:|:-:|:-:|-
63+
router|true|object|Vue Router, this plugin is based on Vue Router.
64+
siteIdList|true|number[]|The site ids for CNZZ analytics, if only one site needs to be reported, just keep one item in the array.
65+
isDebug|false|boolean|if `true`, it will open the debug mode,you can see the log in the console.
66+
67+
Tips: Please remember to turn off the debug mode before publish.
68+
69+
## Install
70+
71+
You can install the plugin from NPM.
72+
73+
```bash
74+
npm install vue-cnzz-analytics --save-dev
75+
```
76+
77+
Can also use the CDN URL in your HTML.
78+
79+
```html
80+
<script src="https://cdn.jsdelivr.net/npm/vue-cnzz-analytics/dist/vue-cnzz-analytics.min.js"></script>
81+
```
82+
83+
## Usage
84+
85+
If use NPM, you must import the plugin in `main.js` .
86+
87+
```js
88+
import cnzzAnalytics from 'vue-cnzz-analytics'
89+
```
90+
91+
Then, refer to the sample code in Vue 2.0 and Vue 3.0 below to use it.
92+
93+
When the route is switched, the new URL address will be reported to CNZZ analytics after the visit.
94+
95+
### Use in the Vue 2.0
96+
97+
See:[main.js - Vue 2.0 demo](https://analyticsjs.github.io/vue-cnzz-analytics/demo/js/main-for-vue2.js)
98+
99+
>Since the version v2.1.0, if you use CDN in your HTML, must be use `cnzzAnalytics.default` to use the plugin.
100+
101+
```js
102+
Vue.use(cnzzAnalytics, {
103+
router: router,
104+
siteIdList: [
105+
11111,
106+
22222
107+
],
108+
isDebug: false
109+
});
110+
```
111+
112+
### Use in the Vue 3.0
113+
114+
See:[main.js - Vue 3.0 demo](https://analyticsjs.github.io/vue-cnzz-analytics/demo/js/main-for-vue3.js)
115+
116+
>Since the version v2.1.0, if you use CDN in your HTML, must be use `cnzzAnalytics.default` to use the plugin.
117+
118+
```js
119+
createApp(app)
120+
.use(router)
121+
.use(cnzzAnalytics, {
122+
router: router,
123+
siteIdList: [
124+
11111,
125+
22222
126+
],
127+
isDebug: false
128+
})
129+
.mount('#app');
130+
```
131+
132+
### Use in the VuePress
133+
134+
The plugin can also be used in [VuePress](https://vuepress.vuejs.org/zh/) project.
135+
136+
In the `/docs/.vuepress` folder under the project, create a file named `enhanceApp.js`, and write the following code in this file.
137+
138+
You can see [App Level Enhancements - VuePress](https://vuepress.vuejs.org/guide/basic-config.html#app-level-enhancements) to learn more.
139+
140+
```js
141+
import cnzzAnalytics from 'vue-cnzz-analytics'
142+
143+
export default ({ Vue, router }) => {
144+
Vue.use(cnzzAnalytics, {
145+
router: router,
146+
siteIdList: [
147+
11111,
148+
22222
149+
],
150+
isDebug: false
151+
});
152+
};
153+
```
154+
155+
You can turn on the debug mode in the development environment to learn about related reports (remember to turn off debug before going online).
156+
157+
## API
158+
159+
Since the version v2.1.0, you can use the Global API `$pushCNZZ` and the Hooks API `usePush` in your project, they both support the Vue 2.0 and 3.0.
160+
161+
>The APIs can't be used directly, it needs to cooperate with the [Methods](#Methods) to operate the specific functions.
162+
163+
### The Global API
164+
165+
In the Vue 2.0:
166+
167+
```js
168+
// xxx.vue in Vue 2.0
169+
export default {
170+
// ...
171+
mounted () {
172+
this.$pushCNZZ.pv('/example-url/');
173+
},
174+
// ...
175+
}
176+
```
177+
178+
In the Vue 3.0, you can use the Global Properties:
179+
180+
```js
181+
// xxx.vue in Vue 3.0
182+
import { getCurrentInstance } from 'vue'
183+
184+
export default {
185+
setup () {
186+
const app = getCurrentInstance();
187+
app.appContext.config.globalProperties.$pushCNZZ.pv('/example-url/');
188+
}
189+
}
190+
```
191+
192+
You can also import the proxy component in the current instance to operate:
193+
194+
```js
195+
// xxx.vue in Vue 3.0
196+
import { getCurrentInstance } from 'vue'
197+
198+
export default {
199+
setup () {
200+
const { proxy } = getCurrentInstance();
201+
proxy.$pushCNZZ.pv('/example-url/');
202+
}
203+
}
204+
```
205+
206+
### The Hooks API
207+
208+
In the Vue 2.0:
209+
210+
```js
211+
// xxx.vue in Vue 2.0
212+
import { usePush } from 'vue-cnzz-analytics'
213+
214+
export default {
215+
// ...
216+
data () {
217+
return {
218+
cnzz: usePush()
219+
}
220+
},
221+
mounted () {
222+
this.cnzz.pv('/example-url/');
223+
},
224+
// ...
225+
}
226+
```
227+
228+
In the Vue 3.0, just use it as if you were using the route `const router = useRouter();`.
229+
230+
```js
231+
// xxx.vue in Vue 3.0
232+
import { usePush } from 'vue-cnzz-analytics'
233+
234+
export default {
235+
setup () {
236+
const cnzz = usePush();
237+
cnzz.pv('/example-url/');
238+
}
239+
}
240+
```
241+
242+
If the name of the hook API has already been declared, you can rename it when import.
243+
244+
```js
245+
import { usePush as useCnzz } from 'vue-cnzz-analytics'
246+
const cnzz = useCnzz();
247+
```
248+
249+
## Methods
250+
251+
All methods are needs to be triggered through the API, and the methods supported by the Global API and the Hooks API are exactly the same.
252+
253+
Method|Description
254+
:--|:--
255+
Manually report the page views|[Click here to see.](#manually-report-the-page-views)
256+
Manually report the event analysis|[Click here to see.](#manually-report-the-event-analysis)
257+
258+
>Since there are still many users of Vue 2.0, the following examples only use the operation method of Vue 2.0 to demonstrate. Vue 3.0 can call specific methods according to the description of the Hooks API.
259+
260+
Tips: If multiple site IDs are configured, the data will be reported to all sites at the same time.
261+
262+
### Manually report the page views
263+
264+
If you switch content rendering on some pages through Tab, but you need to report access data, you can use this method to manually report.
265+
266+
Method|Description
267+
:-:|-
268+
pv|Manually perform PV data reporting.
269+
270+
**Params**
271+
272+
Param|Required|Type|Description
273+
:-:|:-:|:-:|-
274+
pageUrl|false|string|The URL submitted for the report must be a relative path starting with `/`, if not filled, it will be submitted as the domain name root directory by default.
275+
fromUrl|false|string|The URL of the incoming page must be an absolute address beginning with `http` or `https`, if it is not filled in, the statistics platform will consider the source of the visit to be a direct input address.
276+
277+
**Example**
278+
279+
```js
280+
this.$pushCNZZ.pv('/example-url/', 'https://example.com/example-from-url/');
281+
```
282+
283+
### Manually report the event analysis
284+
285+
For example, there is a "exchange" function button on your page. If you want to count the clicks of this button, you can perform click analysis by binding the button to report events.
286+
287+
Method|Description
288+
:-:|-
289+
event|Manually perform event analysis data reporting.
290+
291+
**Params**
292+
293+
Param|Required|Type|Description
294+
:-:|:-:|:-:|-
295+
category|true|string|The name of the location where the event occurred, e.g. `banner`
296+
action|true|string|The description of the behavior that generated the event, e.g. `click`
297+
label|false|string|The name of the label that generated the event can be used to record the event sub-id, e.g. `bannerId_123`. (@default: '')
298+
value|false|number|The score of the event. (@default: 0)
299+
nodeId|false|string|The id of the element that generated the event. (@default: '')
300+
301+
**Example**
302+
303+
```js
304+
this.$pushCNZZ.event(
305+
this.category,
306+
this.action,
307+
this.label,
308+
this.value,
309+
this.nodeId
310+
);
311+
```
312+
313+
## License
314+
315+
[MIT License](https://github.com/analyticsjs/vue-cnzz-analytics/blob/master/LICENSE) © 2019 [chengpeiquan](https://github.com/chengpeiquan)

0 commit comments

Comments
 (0)