Skip to content

Commit 2b49b57

Browse files
author
shengyonggen
committed
Release 1.16.13
1 parent 2513aa6 commit 2b49b57

14 files changed

+230
-103
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 1.16.13 (2021-04-28)
2+
1. 新增
3+
- 新增参数配置 `is_secure_cookie`
4+
2. 优化
5+
- 安全扫描优化
6+
3. 修复
7+
- 修复用户 `ID` 变化后,弹窗和 `A/B Testing` 请求参数不准确的问题
18
## 1.16.12 (2021-04-22)
29
1. 优化
310
- 安全扫描优化

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.

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.16.12",
3+
"version": "1.16.13",
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
@@ -9398,7 +9398,7 @@
93989398

93999399
window.sa_jssdk_heatmap_render = function(se, data, type, url) {
94009400
sd = se;
9401-
sd.heatmap_version = '1.16.12';
9401+
sd.heatmap_version = '1.16.13';
94029402
_ = sd._;
94039403

94049404
_.bindReady = function(fn, win) {

product/sensorsdata.amd.full.js

Lines changed: 69 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,15 @@
774774
});;
775775

776776

777+
if (!String.prototype.replaceAll) {
778+
String.prototype.replaceAll = function(str, newStr) {
779+
if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]') {
780+
return this.replace(str, newStr);
781+
}
782+
return this.replace(new RegExp(str, 'g'), newStr);
783+
};
784+
}
785+
777786
(function() {
778787
var ArrayProto = Array.prototype;
779788
var FuncProto = Function.prototype;
@@ -1158,6 +1167,36 @@
11581167
return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()) + ' ' + pad(d.getHours()) + ':' + pad(d.getMinutes()) + ':' + pad(d.getSeconds()) + '.' + pad(d.getMilliseconds());
11591168
};
11601169

1170+
_.getRandomBasic = (function() {
1171+
var today = new Date();
1172+
var seed = today.getTime();
1173+
1174+
function rnd() {
1175+
seed = (seed * 9301 + 49297) % 233280;
1176+
return seed / (233280.0);
1177+
};
1178+
return function rand(number) {
1179+
return Math.ceil(rnd(seed) * number);
1180+
};
1181+
})();
1182+
_.getRandom = function() {
1183+
if (typeof Uint32Array === 'function') {
1184+
var cry = '';
1185+
if (typeof crypto !== 'undefined') {
1186+
cry = crypto;
1187+
} else if (typeof msCrypto !== 'undefined') {
1188+
cry = msCrypto;
1189+
}
1190+
if (_.isObject(cry) && cry.getRandomValues) {
1191+
var typedArray = new Uint32Array(1);
1192+
var randomNumber = cry.getRandomValues(typedArray)[0];
1193+
var integerLimit = Math.pow(2, 32);
1194+
return randomNumber / integerLimit;
1195+
}
1196+
}
1197+
return _.getRandomBasic(10000000000000000000) / 10000000000000000000;
1198+
};
1199+
11611200
_.searchObjDate = function(o) {
11621201
if (_.isObject(o)) {
11631202
_.each(o, function(a, b) {
@@ -1342,7 +1381,7 @@
13421381
return d.toString(16) + i.toString(16);
13431382
};
13441383
var R = function() {
1345-
return Math.random().toString(16).replace('.', '');
1384+
return _.getRandom().toString(16).replace('.', '');
13461385
};
13471386
var UA = function(n) {
13481387
var ua = navigator.userAgent,
@@ -1381,15 +1420,15 @@
13811420
if (se && /\d{5,}/.test(se)) {
13821421
se = se.toString(16);
13831422
} else {
1384-
se = String(Math.random() * 31242)
1423+
se = String(_.getRandom() * 31242)
13851424
.replace('.', '')
13861425
.slice(0, 8);
13871426
}
13881427
var val = T() + '-' + R() + '-' + UA() + '-' + se + '-' + T();
13891428
if (val) {
13901429
return val;
13911430
} else {
1392-
return (String(Math.random()) + String(Math.random()) + String(Math.random())).slice(2, 15);
1431+
return (String(_.getRandom()) + String(_.getRandom()) + String(_.getRandom())).slice(2, 15);
13931432
}
13941433
};
13951434
})();
@@ -1622,7 +1661,7 @@
16221661
}
16231662
return null;
16241663
},
1625-
set: function(name, value, days, cross_subdomain, is_secure) {
1664+
set: function(name, value, days, cross_subdomain) {
16261665
cross_subdomain = typeof cross_subdomain === 'undefined' ? sd.para.cross_subdomain : cross_subdomain;
16271666
var cdomain = '',
16281667
expires = '',
@@ -1647,23 +1686,24 @@
16471686

16481687
expires = '; expires=' + date.toGMTString();
16491688
}
1650-
1651-
if (is_secure) {
1689+
if (sd.para.is_secure_cookie) {
16521690
secure = '; secure';
16531691
}
16541692

16551693
function getValid(data) {
16561694
if (data) {
1657-
return data;
1695+
return data.replaceAll(/\r\n/g, '');
16581696
} else {
16591697
return false;
16601698
}
16611699
}
16621700
var valid_name = '';
16631701
var valid_value = '';
16641702
var valid_domain = '';
1665-
if (name && value) {
1703+
if (name) {
16661704
valid_name = getValid(name);
1705+
}
1706+
if (value) {
16671707
valid_value = getValid(value);
16681708
}
16691709
if (cdomain) {
@@ -1672,6 +1712,7 @@
16721712
if (valid_name && valid_value) {
16731713
document.cookie = valid_name + '=' + encodeURIComponent(valid_value) + expires + '; path=/' + valid_domain + secure;
16741714
}
1715+
16751716
},
16761717
encrypt: function(v) {
16771718
return 'data:enc;' + _.rot13obfs(v);
@@ -3206,7 +3247,7 @@
32063247

32073248
sd.setInitVar = function() {
32083249
sd._t = sd._t || 1 * new Date();
3209-
sd.lib_version = '1.16.12';
3250+
sd.lib_version = '1.16.13';
32103251
sd.is_first_visitor = false;
32113252
sd.source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
32123253
};
@@ -4110,7 +4151,7 @@
41104151
source: 'sa-web-sdk',
41114152
type: 'v-is-vtrack',
41124153
data: {
4113-
sdkversion: '1.16.12'
4154+
sdkversion: '1.16.13'
41144155
}
41154156
},
41164157
'*'
@@ -4437,7 +4478,7 @@
44374478
};
44384479
},
44394480
writeStore: function(data) {
4440-
var uuid = String(Math.random()).slice(2, 5) + String(Math.random()).slice(2, 5) + String(new Date().getTime()).slice(3);
4481+
var uuid = String(_.getRandom()).slice(2, 5) + String(_.getRandom()).slice(2, 5) + String(new Date().getTime()).slice(3);
44414482
localStorage.setItem('sawebjssdk-' + uuid, JSON.stringify(data));
44424483
}
44434484
};
@@ -4659,7 +4700,7 @@
46594700
return false;
46604701
}
46614702

4662-
data._track_id = Number(String(Math.random()).slice(2, 5) + String(Math.random()).slice(2, 4) + String(new Date().getTime()).slice(-4));
4703+
data._track_id = Number(String(_.getRandom()).slice(2, 5) + String(_.getRandom()).slice(2, 4) + String(new Date().getTime()).slice(-4));
46634704
if (sd.para.use_client_time) {
46644705
data._flush_time = new Date().getTime();
46654706
}
@@ -5003,16 +5044,17 @@
50035044
},
50045045
set: function(name, value) {
50055046
this._state = this._state || {};
5006-
if (name === 'distinct_id' && this._state.distinct_id) {
5007-
sd.events.tempAdd('changeDistinctId', value);
5008-
}
5047+
var pre_id = this._state.distinct_id;
50095048
this._state[name] = value;
50105049
if (name === 'first_id') {
50115050
delete this._state._first_id;
50125051
} else if (name === 'distinct_id') {
50135052
delete this._state._distinct_id;
50145053
}
50155054
this.save();
5055+
if (name === 'distinct_id' && pre_id) {
5056+
sd.events.tempAdd('changeDistinctId', value);
5057+
}
50165058
},
50175059
change: function(name, value) {
50185060
this._state['_' + name] = value;
@@ -5498,19 +5540,17 @@
54985540
var iframe = null;
54995541
if (sd.bridge.iOS_UA_bridge()) {
55005542
iframe = document.createElement('iframe');
5501-
iframe.setAttribute(
5502-
'src',
5503-
'sensorsanalytics://trackEvent?event=' +
5504-
encodeURIComponent(
5505-
JSON.stringify(
5506-
_.extend({
5507-
server_url: sd.para.server_url
5508-
},
5509-
originData
5510-
)
5511-
)
5512-
)
5513-
);
5543+
5544+
function checkURL(originData) {
5545+
var data = JSON.stringify(_.extend({
5546+
server_url: sd.para.server_url
5547+
}, originData));
5548+
data = data.replaceAll(/\r\n/, '');
5549+
data = encodeURIComponent(data);
5550+
return 'sensorsanalytics://trackEvent?event=' + data;
5551+
}
5552+
var newurl = checkURL(originData);
5553+
iframe.setAttribute('src', newurl);
55145554
document.documentElement.appendChild(iframe);
55155555
iframe.parentNode.removeChild(iframe);
55165556
iframe = null;
@@ -5678,7 +5718,7 @@
56785718

56795719
function getKey() {
56805720
var d = new Date().getTime().toString(16);
5681-
var m = String(Math.random()).replace('.', '').slice(1, 8);
5721+
var m = String(_.getRandom()).replace('.', '').slice(1, 8);
56825722
return d + '-' + m;
56835723
}
56845724
var key = getKey();

0 commit comments

Comments
 (0)