Skip to content

Commit

Permalink
Merge pull request #12 from l-hammer/bugfix_uvpv
Browse files Browse the repository at this point in the history
fix uvpv not called when parent router change
  • Loading branch information
LHammer committed Jul 31, 2019
2 parents a23a112 + cb080d8 commit d0be03f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
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.3",
"version": "0.8.5",
"description": "一个基于Vue指令的埋点插件",
"author": "LHammer <lhammer@qq.com>",
"scripts": {
Expand Down
18 changes: 5 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
* @Author: 宋慧武
* @Date: 2019-03-06 17:49:29
* @Last Modified by: 宋慧武
* @Last Modified time: 2019-07-30 21:46:22
* @Last Modified time: 2019-07-31 10:56:51
*/
import * as hooks from "./hooks";

export default class VTrack {
constructor() {
this.installed = false;
this.curPage = null; // 保存当前页name
}
// 保存当前点击的元素
static target = null;
// Vue.use 将执行此方法
static install(Vue, { trackEvents, trackEnable = {} }) {
const self = this;
trackEnable = {
UVPV: false,
TONP: false,
Expand Down Expand Up @@ -57,16 +55,10 @@ export default class VTrack {
window.onbeforeunload = () => TRACK_TONP(this, this.PAGE_ENTER_TIME);
},
// 统计UV、PV
beforeRouteEnter(to, _, next) {
// 防止有些情况该守卫执行多次导致重复埋点的问题
if (to.fullPath === self.curPage) {
next();
} else {
self.curPage = to.fullPath;
next(vm => {
trackEnable.UVPV && trackEvents.UVPV(vm);
});
}
beforeRouteEnter(_, __, next) {
next(vm => {
trackEnable.UVPV && trackEvents.UVPV(vm);
});
},
beforeRouteUpdate(_, __, next) {
if (trackEnable.UVPV && trackEnable.UVPV === "routeUpdate") {
Expand Down

0 comments on commit d0be03f

Please sign in to comment.