Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix uvpv not called when parent router change #12

Merged
merged 2 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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