Skip to content

Commit 29ae044

Browse files
author
shengyonggen
committed
Release 1.21.5
1 parent 488050c commit 29ae044

17 files changed

+458
-184
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 1.21.5 (2021-01-20)
2+
1. 新增
3+
- 页面浏览时长支持单页面
4+
- 所有事件新增 `$viewport_width``$viewport_height` 属性
5+
- 点击事件新增 `$page_x``$page_y` 属性(SCA 需升级到 0.5 及以上版本)
6+
- 新增采集页面高度 `$page_height` 属性插件(SCA 需升级到 0.5 及以上版本)
7+
- `$WebPageLeave` 新增 `$viewport_position` 属性
8+
2. 修复
9+
- 修复 `login` 回调执行两次的问题
10+
111
## 1.21.4 (2021-01-14)
212
1. 修复
313
- 修复百度关键词 `id` `Hash` 冲突问题

core/sensorsdata.amd.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/sensorsdata.es6.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/sensorsdata.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/sensorsdata.mtp.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

heatmap.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sa-sdk-javascript",
3-
"version": "1.21.4",
3+
"version": "1.21.5",
44
"description": "official sensorsdata javascript sdk",
55
"main": "sensorsdata.min.js",
66
"scripts": {

product/heatmap.full.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9565,7 +9565,7 @@
95659565

95669566
window.sa_jssdk_heatmap_render = function(se, data, type, url) {
95679567
sd = se;
9568-
sd.heatmap_version = '1.21.4';
9568+
sd.heatmap_version = '1.21.5';
95699569
_ = sd._;
95709570
_.querySelectorAll = function(val) {
95719571
if (typeof val !== 'string') {

product/sensorsdata.amd.full.js

Lines changed: 105 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,7 +2081,7 @@
20812081
};
20822082

20832083
var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
2084-
var sdkversion_placeholder = '1.21.4';
2084+
var sdkversion_placeholder = '1.21.5';
20852085

20862086
function parseSuperProperties(data) {
20872087
var obj = data.properties;
@@ -2238,7 +2238,6 @@
22382238
props.$url = getURL();
22392239
props.$url_path = location.pathname;
22402240
props.$title = document.title;
2241-
props.$viewport_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 0;
22422241

22432242
return props;
22442243
}
@@ -2521,13 +2520,18 @@
25212520
};
25222521
},
25232522
properties: function() {
2524-
return {
2523+
var viewportHeightValue = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0;
2524+
var viewportWidthValue = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 0;
2525+
var propertiesObj = {
25252526
$timezone_offset: new Date().getTimezoneOffset(),
25262527
$screen_height: Number(screen.height) || 0,
25272528
$screen_width: Number(screen.width) || 0,
2529+
$viewport_height: viewportHeightValue,
2530+
$viewport_width: viewportWidthValue,
25282531
$lib: 'js',
25292532
$lib_version: sdkversion_placeholder
25302533
};
2534+
return propertiesObj;
25312535
},
25322536
currentProps: {},
25332537
register: function(obj) {
@@ -2958,40 +2962,70 @@
29582962
addEvent(window, hashEvent, callback);
29592963
}
29602964

2961-
function addSinglePageEvent(callback) {
2962-
var current_url = location.href;
2963-
var historyPushState = window.history.pushState;
2964-
var historyReplaceState = window.history.replaceState;
2965-
2966-
if (isFunction(window.history.pushState)) {
2967-
window.history.pushState = function() {
2968-
historyPushState.apply(window.history, arguments);
2969-
callback(current_url);
2970-
current_url = location.href;
2971-
};
2972-
}
2965+
var singlePage = {
2966+
is_create: false,
2967+
current_url: location.href,
2968+
eventList: [],
2969+
create: function() {
2970+
var _this = this;
29732971

2974-
if (isFunction(window.history.replaceState)) {
2975-
window.history.replaceState = function() {
2976-
historyReplaceState.apply(window.history, arguments);
2977-
callback(current_url);
2978-
current_url = location.href;
2979-
};
2980-
}
2972+
function publish() {
2973+
each(_this.eventList, function(event) {
2974+
if (isFunction(event)) {
2975+
event(_this.current_url);
2976+
}
2977+
});
2978+
_this.current_url = location.href;
2979+
}
2980+
var historyPushState = window.history.pushState;
2981+
var historyReplaceState = window.history.replaceState;
29812982

2982-
var singlePageEvent;
2983-
if (window.document.documentMode) {
2984-
singlePageEvent = 'hashchange';
2985-
} else {
2986-
singlePageEvent = historyPushState ? 'popstate' : 'hashchange';
2987-
}
2983+
if (isFunction(window.history.pushState)) {
2984+
window.history.pushState = function() {
2985+
historyPushState.apply(window.history, arguments);
2986+
publish();
2987+
};
2988+
}
29882989

2989-
addEvent(window, singlePageEvent, function() {
2990-
callback(current_url);
2991-
current_url = location.href;
2992-
});
2990+
if (isFunction(window.history.replaceState)) {
2991+
window.history.replaceState = function() {
2992+
historyReplaceState.apply(window.history, arguments);
2993+
publish();
2994+
};
2995+
}
29932996

2997+
var singlePageEvent;
2998+
if (window.document.documentMode) {
2999+
singlePageEvent = 'hashchange';
3000+
} else {
3001+
singlePageEvent = historyPushState ? 'popstate' : 'hashchange';
3002+
}
29943003

3004+
addEvent(window, singlePageEvent, function() {
3005+
publish();
3006+
});
3007+
this.is_create = true;
3008+
},
3009+
subscribe: function(callback) {
3010+
if (!this.is_create) {
3011+
this.create();
3012+
}
3013+
if (isFunction(callback)) {
3014+
this.eventList.push(callback);
3015+
}
3016+
},
3017+
prepend: function(callback) {
3018+
if (!this.is_create) {
3019+
this.create();
3020+
}
3021+
if (isFunction(callback)) {
3022+
this.eventList.unshift(callback);
3023+
}
3024+
}
3025+
};
3026+
3027+
function addSinglePageEvent(callback) {
3028+
singlePage.subscribe(callback);
29953029
}
29963030

29973031
function listenPageState(obj) {
@@ -3457,6 +3491,7 @@
34573491
addSinglePageEvent: addSinglePageEvent,
34583492
listenPageState: listenPageState,
34593493
bindReady: bindReady,
3494+
singlePage: singlePage,
34603495
xhr: xhr,
34613496
ajax: ajax,
34623497
jsonp: jsonp,
@@ -4630,6 +4665,40 @@
46304665
}
46314666
return prop;
46324667
},
4668+
addPointerEventProp: function(ev, target) {
4669+
function getScroll() {
4670+
var scrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft || 0;
4671+
var scrollTop = document.body.scrollTop || document.documentElement.scrollTop || 0;
4672+
return {
4673+
scrollLeft: scrollLeft,
4674+
scrollTop: scrollTop
4675+
};
4676+
}
4677+
4678+
function getElementPosition(target) {
4679+
if (document.documentElement.getBoundingClientRect) {
4680+
var targetEle = target.getBoundingClientRect();
4681+
return {
4682+
targetEleX: targetEle.left + getScroll().scrollLeft || 0,
4683+
targetEleY: targetEle.top + getScroll().scrollTop || 0
4684+
};
4685+
}
4686+
}
4687+
4688+
function toFixedThree(val) {
4689+
return Number(Number(val).toFixed(3));
4690+
}
4691+
4692+
function getPage(ev) {
4693+
var pageX = ev.pageX || ev.clientX + getScroll().scrollLeft || ev.offsetX + getElementPosition(target).targetEleX || 0;
4694+
var pageY = ev.pageY || ev.clientY + getScroll().scrollTop || ev.offsetY + getElementPosition(target).targetEleY || 0;
4695+
return {
4696+
$page_x: toFixedThree(pageX),
4697+
$page_y: toFixedThree(pageY)
4698+
};
4699+
}
4700+
return getPage(ev);
4701+
},
46334702
start: function(ev, target, tagName, customProps, callback) {
46344703
var userCustomProps = isObject(customProps) ? customProps : {};
46354704
var userCallback = isFunction(callback) ? callback : isFunction(customProps) ? customProps : undefined;
@@ -4645,7 +4714,7 @@
46454714
prop = extend(prop, customP);
46464715
}
46474716
}
4648-
prop = extend(prop, userCustomProps);
4717+
prop = extend(prop, this.addPointerEventProp(ev, target), userCustomProps);
46494718
if (tagName === 'a' && sd.para.heatmap && sd.para.heatmap.isTrackLink === true) {
46504719
sd.trackLink({
46514720
event: ev,
@@ -4758,8 +4827,6 @@
47584827
if (!this.inter) {
47594828
para.$viewport_position = (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || document.body.scrollTop || 0;
47604829
para.$viewport_position = Math.round(para.$viewport_position) || 0;
4761-
para.$viewport_height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0;
4762-
para.$viewport_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 0;
47634830
if (isNoDelay) {
47644831
interDelay.main(para, true);
47654832
} else {
@@ -5853,7 +5920,7 @@
58535920
distinct_id: id
58545921
}) && id !== sd.store.getDistinctId()) {
58555922
if (isObject(sd.store._state.identities) && sd.store._state.identities.hasOwnProperty(sd.para.login_id_key) && id === sd.store._state.first_id) {
5856-
callback && callback();
5923+
isFunction(callback) && callback();
58575924
return false;
58585925
}
58595926

@@ -5877,9 +5944,8 @@
58775944
});
58785945
}
58795946
} else {
5880-
callback && callback();
5947+
isFunction(callback) && callback();
58815948
}
5882-
callback && callback();
58835949
}
58845950

58855951
function logout(isChangeId) {
@@ -7844,7 +7910,7 @@
78447910
source: 'sa-web-sdk',
78457911
type: 'v-is-vtrack',
78467912
data: {
7847-
sdkversion: '1.21.4'
7913+
sdkversion: '1.21.5'
78487914
}
78497915
},
78507916
'*'

0 commit comments

Comments
 (0)