@datarangers/sdk-javascript 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/index-base.min.js +1 -6629
- package/es/index.min.js +1 -9570
- package/es/plugin/ab.js +1 -1114
- package/es/plugin/autotrack.js +1 -1608
- package/es/plugin/duration.js +1 -100
- package/es/plugin/route.js +1 -605
- package/es/plugin/stay.js +1 -476
- package/lib/index-base.min.js +1 -6634
- package/lib/index.min.js +1 -9575
- package/lib/plugin/ab.js +1 -1116
- package/lib/plugin/autotrack.js +1 -1610
- package/lib/plugin/duration.js +1 -102
- package/lib/plugin/route.js +1 -607
- package/lib/plugin/stay.js +1 -478
- package/package.json +1 -1
package/es/plugin/duration.js
CHANGED
|
@@ -1,100 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var TrackDuration = /** @class */function () {
|
|
3
|
-
function TrackDuration() {}
|
|
4
|
-
TrackDuration.prototype.apply = function (collector, config) {
|
|
5
|
-
var _this = this;
|
|
6
|
-
this.collector = collector;
|
|
7
|
-
this.config = config;
|
|
8
|
-
var Types = collector.Types;
|
|
9
|
-
collector.on(Types.TrackDurationStart, function (eventName) {
|
|
10
|
-
_this.trackStart(eventName);
|
|
11
|
-
});
|
|
12
|
-
collector.on(Types.TrackDurationEnd, function (info) {
|
|
13
|
-
_this.trackEnd(info);
|
|
14
|
-
});
|
|
15
|
-
collector.on(Types.TrackDurationPause, function (eventName) {
|
|
16
|
-
_this.trackPause(eventName);
|
|
17
|
-
});
|
|
18
|
-
collector.on(Types.TrackDurationResume, function (eventName) {
|
|
19
|
-
_this.trackResume(eventName);
|
|
20
|
-
});
|
|
21
|
-
this.Types = Types;
|
|
22
|
-
this.TrackMap = new Map();
|
|
23
|
-
this.ready(Types.TrackDuration);
|
|
24
|
-
};
|
|
25
|
-
TrackDuration.prototype.ready = function (name) {
|
|
26
|
-
var _this = this;
|
|
27
|
-
this.collector.set(name);
|
|
28
|
-
if (this.collector.hook._hooksCache.hasOwnProperty(name)) {
|
|
29
|
-
var emits = this.collector.hook._hooksCache[name];
|
|
30
|
-
if (!Object.keys(emits).length) return;
|
|
31
|
-
var _loop_1 = function _loop_1(key) {
|
|
32
|
-
if (emits[key].length) {
|
|
33
|
-
emits[key].forEach(function (item) {
|
|
34
|
-
_this.collector.hook.emit(key, item);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
for (var key in emits) {
|
|
39
|
-
_loop_1(key);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
TrackDuration.prototype.trackStart = function (eventName) {
|
|
44
|
-
this.TrackMap.set(eventName, {
|
|
45
|
-
startTime: Date.now(),
|
|
46
|
-
isPause: false,
|
|
47
|
-
pauseTime: 0,
|
|
48
|
-
resumeTime: 0
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
TrackDuration.prototype.trackEnd = function (info) {
|
|
52
|
-
var eventName = info.eventName,
|
|
53
|
-
params = info.params;
|
|
54
|
-
if (!this.TrackMap.has(eventName)) return;
|
|
55
|
-
var trackData = this.TrackMap.get(eventName);
|
|
56
|
-
var event_duration = 0;
|
|
57
|
-
if (trackData.isPause) {
|
|
58
|
-
// 暂停后,未恢复,直接结束
|
|
59
|
-
event_duration = trackData.pauseTime - trackData.startTime;
|
|
60
|
-
} else {
|
|
61
|
-
// 处于未暂停状态,可能是恢复了,可能是从未暂停过
|
|
62
|
-
if (trackData.resumeTime) {
|
|
63
|
-
// 暂停后,恢复了
|
|
64
|
-
event_duration = trackData.pauseTime - trackData.startTime + (Date.now() - trackData.resumeTime);
|
|
65
|
-
} else {
|
|
66
|
-
// 未暂停过
|
|
67
|
-
event_duration = Date.now() - trackData.startTime;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
var eventParmas = Object.assign(params, {
|
|
71
|
-
event_duration: event_duration
|
|
72
|
-
});
|
|
73
|
-
this.collector.event(eventName, eventParmas);
|
|
74
|
-
this.cleanTrack(eventName);
|
|
75
|
-
};
|
|
76
|
-
// 事件暂停计时
|
|
77
|
-
TrackDuration.prototype.trackPause = function (eventName) {
|
|
78
|
-
if (!this.TrackMap.has(eventName)) return;
|
|
79
|
-
var trackData = this.TrackMap.get(eventName);
|
|
80
|
-
if (trackData.isPause) return;
|
|
81
|
-
trackData.isPause = true;
|
|
82
|
-
trackData.pauseTime = Date.now();
|
|
83
|
-
this.TrackMap.set(eventName, trackData);
|
|
84
|
-
};
|
|
85
|
-
// 事件恢复计时
|
|
86
|
-
TrackDuration.prototype.trackResume = function (eventName) {
|
|
87
|
-
if (!this.TrackMap.has(eventName)) return;
|
|
88
|
-
var trackData = this.TrackMap.get(eventName);
|
|
89
|
-
if (!trackData.isPause) return;
|
|
90
|
-
trackData.isPause = false;
|
|
91
|
-
trackData.resumeTime = Date.now();
|
|
92
|
-
this.TrackMap.set(eventName, trackData);
|
|
93
|
-
};
|
|
94
|
-
TrackDuration.prototype.cleanTrack = function (eventName) {
|
|
95
|
-
this.TrackMap["delete"](eventName);
|
|
96
|
-
};
|
|
97
|
-
return TrackDuration;
|
|
98
|
-
}();
|
|
99
|
-
|
|
100
|
-
export { TrackDuration as default };
|
|
1
|
+
function t(t,e,a){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var a=t[Symbol.toPrimitive];if(void 0!==a){var r=a.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[e]=a,t}var e=function(){function e(){t(this,"collector",void 0),t(this,"config",void 0),t(this,"TrackMap",void 0),t(this,"Types",void 0)}var a=e.prototype;return a.apply=function(t,e){var a=this;this.collector=t,this.config=e;var r=t.Types;t.on(r.TrackDurationStart,function(t){a.trackStart(t)}),t.on(r.TrackDurationEnd,function(t){a.trackEnd(t)}),t.on(r.TrackDurationPause,function(t){a.trackPause(t)}),t.on(r.TrackDurationResume,function(t){a.trackResume(t)}),this.Types=r,this.TrackMap=new Map,this.ready(r.TrackDuration)},a.ready=function(t){var e=this;if(this.collector.set(t),this.collector.hook._hooksCache.hasOwnProperty(t)){var a=this.collector.hook._hooksCache[t];if(!Object.keys(a).length)return;var r=function(t){a[t].length&&a[t].forEach(function(a){e.collector.hook.emit(t,a)})};for(var i in a)r(i)}},a.trackStart=function(t){this.TrackMap.set(t,{startTime:Date.now(),isPause:!1,pauseTime:0,resumeTime:0})},a.trackEnd=function(t){var e=t.eventName,a=t.params;if(this.TrackMap.has(e)){var r=this.TrackMap.get(e),i=0;i=r.isPause?r.pauseTime-r.startTime:r.resumeTime?r.pauseTime-r.startTime+(Date.now()-r.resumeTime):Date.now()-r.startTime;var n=Object.assign(a,{event_duration:i});this.collector.event(e,n),this.cleanTrack(e)}},a.trackPause=function(t){if(this.TrackMap.has(t)){var e=this.TrackMap.get(t);e.isPause||(e.isPause=!0,e.pauseTime=Date.now(),this.TrackMap.set(t,e))}},a.trackResume=function(t){if(this.TrackMap.has(t)){var e=this.TrackMap.get(t);e.isPause&&(e.isPause=!1,e.resumeTime=Date.now(),this.TrackMap.set(t,e))}},a.cleanTrack=function(t){this.TrackMap.delete(t)},e}();export{e as default};
|