Skip to content

Commit 9c1d4bd

Browse files
author
LHammer
authored
Merge pull request #13 from l-hammer/block_show_support_args
block show track support arguments
2 parents d0be03f + 7bfbff1 commit 9c1d4bd

File tree

4 files changed

+58
-6
lines changed

4 files changed

+58
-6
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "v-track",
3-
"version": "0.8.5",
3+
"version": "0.8.6",
44
"description": "一个基于Vue指令的埋点插件",
55
"author": "LHammer <lhammer@qq.com>",
66
"scripts": {

src/hooks/index.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: 宋慧武
33
* @Date: 2019-03-06 17:49:29
44
* @Last Modified by: 宋慧武
5-
* @Last Modified time: 2019-05-28 17:05:58
5+
* @Last Modified time: 2019-08-05 17:43:57
66
*/
77
import {
88
zipArray,
@@ -107,14 +107,15 @@ export function bind(
107107
}
108108
// 区域曝光埋点
109109
else if (partialMatch("show")) {
110-
const fn = () => events[id](context);
110+
const [args] = zipArray(value);
111+
const tck = events[id].bind(null, context, ...args);
111112
const once = partialMatch("once");
112113
const custom = partialMatch("custom");
113114

114115
if (!el.$visMonitor) {
115116
const vm = new VisMonitor(el, custom && context.$refs[value.ref]);
116117

117-
(once ? vm.$once : vm.$on).call(vm, "fullyvisible", fn);
118+
(once ? vm.$once : vm.$on).call(vm, "fullyvisible", tck);
118119
el.$visMonitor = vm;
119120
}
120121
} else if (

src/utils/helper.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: 宋慧武
33
* @Date: 2019-04-08 11:13:34
44
* @Last Modified by: 宋慧武
5-
* @Last Modified time: 2019-04-20 18:06:43
5+
* @Last Modified time: 2019-08-05 15:31:00
66
*/
77

88
/**
@@ -33,7 +33,7 @@ export const isDef = v => v !== undefined && v !== null;
3333
* @param {Object} value
3434
* @returns {Array} [keys, values]
3535
*/
36-
export function zipArray(value) {
36+
export function zipArray(value = {}) {
3737
return [Object.values(value), Object.keys(value)];
3838
}
3939

tests/unit/track-show-param.spec.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Created Date: 2019-08-05
3+
* Author: 宋慧武
4+
* ------
5+
* Last Modified: Monday 2019-08-05 17:01:32 pm
6+
* Modified By: the developer formerly known as 宋慧武 at <songhuiwu001@ke.com>
7+
* ------
8+
* HISTORY:
9+
* ------
10+
* Javascript will save your soul!
11+
*/
12+
import Vue from "vue";
13+
import VTrack from "@/";
14+
import { mount, createLocalVue } from "@vue/test-utils";
15+
import { mockParentNode, mockRect } from "../helper";
16+
17+
const localVue = createLocalVue();
18+
const mockTrackAction = jest.fn((_, id) => id);
19+
const trackEvents = {
20+
18015: mockTrackAction
21+
};
22+
const TrackShow = Vue.extend({
23+
template: `
24+
<div v-track:18015.show="{ id }" />
25+
`,
26+
data() {
27+
return {
28+
id: "2019"
29+
};
30+
}
31+
});
32+
33+
localVue.use(VTrack, {
34+
trackEvents
35+
});
36+
37+
jest.useFakeTimers();
38+
39+
describe("TrackShow", () => {
40+
it("确保DOM元素完全可见之后触发埋点,且至少间隔200ms执行一下", () => {
41+
const wrapper = mount(TrackShow, { localVue });
42+
const vm = wrapper.vm;
43+
44+
mockParentNode(vm.$el);
45+
mockRect(vm.$el);
46+
jest.runAllTimers();
47+
48+
expect(mockTrackAction.mock.results[0].value).toBe("2019");
49+
expect(mockTrackAction).toBeCalledTimes(1);
50+
});
51+
});

0 commit comments

Comments
 (0)