Skip to content

Commit

Permalink
Merge pull request #9 from l-hammer/feat_uvpv
Browse files Browse the repository at this point in the history
Feat uvpv
  • Loading branch information
LHammer authored Jul 26, 2019
2 parents 7dc4b35 + 0a8ef88 commit 4f6f853
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 19 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,19 @@ export default {
/**
* @name UVPV 固定名称不支持修改
* @desc UV、PV埋点
* @param {Object} context 当前上下文
*/
UVPV() {
UVPV(context) {
...
},
/**
* @name TONP 固定名称不支持修改
* @desc 页面停留时间埋点(Time on Page)
* @param {Object} context 当前上下文
* @param {Timestamp} et 进入页面时间
* @param {Timestamp} dt 离开页面时间
*/
TONP({ et, dt }) {
TONP(context, { et, dt }) {
...
},
/**
Expand Down
2 changes: 0 additions & 2 deletions docs/dist/js/app.b09015e7.js

This file was deleted.

1 change: 0 additions & 1 deletion docs/dist/js/app.b09015e7.js.map

This file was deleted.

2 changes: 2 additions & 0 deletions docs/dist/js/app.c3e9c962.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/dist/js/app.c3e9c962.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=dist/favicon.ico><link href=//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/nord.min.css rel=stylesheet><title>v-track</title><link href=dist/css/app.1efa72a7.css rel=preload as=style><link href=dist/css/chunk-vendors.bf068a49.css rel=preload as=style><link href=dist/js/app.b09015e7.js rel=preload as=script><link href=dist/js/chunk-vendors.c94e27ba.js rel=preload as=script><link href=dist/css/chunk-vendors.bf068a49.css rel=stylesheet><link href=dist/css/app.1efa72a7.css rel=stylesheet></head><body><noscript><strong>We're sorry but v-track doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=dist/js/chunk-vendors.c94e27ba.js></script><script src=dist/js/app.b09015e7.js></script></body></html>
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=dist/favicon.ico><link href=//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/nord.min.css rel=stylesheet><title>v-track</title><link href=dist/css/app.1efa72a7.css rel=preload as=style><link href=dist/css/chunk-vendors.bf068a49.css rel=preload as=style><link href=dist/js/app.c3e9c962.js rel=preload as=script><link href=dist/js/chunk-vendors.c94e27ba.js rel=preload as=script><link href=dist/css/chunk-vendors.bf068a49.css rel=stylesheet><link href=dist/css/app.1efa72a7.css rel=stylesheet></head><body><noscript><strong>We're sorry but v-track doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=dist/js/chunk-vendors.c94e27ba.js></script><script src=dist/js/app.c3e9c962.js></script></body></html>
8 changes: 5 additions & 3 deletions docs/pages/started.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import trackEvents from "./track-events";
Vue.use(VTrack, {
trackEvents, // 埋点事件对象
trackEnable: {
UVPV: false, // 是否开启UVPV统计,默认为false
UVPV: true, // 是否开启UVPV统计,默认为false
TONP: true // 是否开启页面停留时长统计,默认为false
}
})
Expand All @@ -71,17 +71,19 @@ export default {
/**
* @name UVPV 固定名称不支持修改
* @desc UV、PV埋点
* @param {Object} context 当前上下文
*/
UVPV() {
UVPV(_) {
trackAction("1");
},
/**
* @name TONP 固定名称不支持修改
* @desc 页面停留时间埋点(Time on Page)
* @param {Object} context 当前上下文
* @param {Timestamp} et 进入页面时间
* @param {Timestamp} dt 离开页面时间
*/
TONP({ et, dt }) {
TONP(_, { et, dt }) {
trackAction("2", {
stt: dt - et
});
Expand Down
6 changes: 4 additions & 2 deletions docs/tracks/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@
* @Author: 宋慧武
* @Date: 2019-04-14 17:10:31
* @Last Modified by: 宋慧武
* @Last Modified time: 2019-04-27 23:13:43
* @Last Modified time: 2019-07-26 11:32:10
*/
import trackAction from "./action";

export default {
/**
* @name UVPV 固定名称不支持修改
* @desc UV、PV埋点
* @param {Object} context 当前上下文
*/
UVPV() {
trackAction("1");
},
/**
* @name TONP 固定名称不支持修改
* @desc 页面停留时间埋点(Time on Page)
* @param {Object} context 当前上下文
* @param {Timestamp} et 进入页面时间
* @param {Timestamp} dt 离开页面时间
*/
TONP({ et, dt }) {
TONP(_, { et, dt }) {
trackAction("2", {
stt: `${(dt - et) / 1e3}s`
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "v-track",
"version": "0.8.0",
"version": "0.8.1",
"description": "一个基于Vue指令的埋点插件",
"author": "LHammer <[email protected]>",
"scripts": {
Expand Down
15 changes: 8 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: 宋慧武
* @Date: 2019-03-06 17:49:29
* @Last Modified by: 宋慧武
* @Last Modified time: 2019-04-27 23:32:41
* @Last Modified time: 2019-07-26 11:28:45
*/
import * as hooks from "./hooks";

Expand All @@ -21,9 +21,9 @@ export default class VTrack {
TONP: false,
...trackEnable
};
const TRACK_TONP = et => {
const TRACK_TONP = (ctx, et) => {
if (trackEnable.TONP) {
trackEvents.TONP({
trackEvents.TONP(ctx, {
et,
dt: Date.now()
});
Expand Down Expand Up @@ -54,7 +54,7 @@ export default class VTrack {
PAGE_ENTER_TIME: Date.now()
}),
created() {
window.onbeforeunload = () => TRACK_TONP(this.PAGE_ENTER_TIME);
window.onbeforeunload = () => TRACK_TONP(this, this.PAGE_ENTER_TIME);
},
// 统计UV、PV
beforeRouteEnter(to, _, next) {
Expand All @@ -63,13 +63,14 @@ export default class VTrack {
next();
} else {
self.curPage = to.name;
trackEnable.UVPV && trackEvents.UVPV();
next();
next(vm => {
trackEnable.UVPV && trackEvents.UVPV(vm);
});
}
},
// 页面停留时间
beforeRouteLeave(_, __, next) {
TRACK_TONP(this.PAGE_ENTER_TIME);
TRACK_TONP(this, this.PAGE_ENTER_TIME);
next();
}
});
Expand Down

0 comments on commit 4f6f853

Please sign in to comment.