|
774 | 774 | });; |
775 | 775 |
|
776 | 776 |
|
| 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 | + |
777 | 786 | (function() { |
778 | 787 | var ArrayProto = Array.prototype; |
779 | 788 | var FuncProto = Function.prototype; |
|
1158 | 1167 | return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()) + ' ' + pad(d.getHours()) + ':' + pad(d.getMinutes()) + ':' + pad(d.getSeconds()) + '.' + pad(d.getMilliseconds()); |
1159 | 1168 | }; |
1160 | 1169 |
|
| 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 | + |
1161 | 1200 | _.searchObjDate = function(o) { |
1162 | 1201 | if (_.isObject(o)) { |
1163 | 1202 | _.each(o, function(a, b) { |
|
1342 | 1381 | return d.toString(16) + i.toString(16); |
1343 | 1382 | }; |
1344 | 1383 | var R = function() { |
1345 | | - return Math.random().toString(16).replace('.', ''); |
| 1384 | + return _.getRandom().toString(16).replace('.', ''); |
1346 | 1385 | }; |
1347 | 1386 | var UA = function(n) { |
1348 | 1387 | var ua = navigator.userAgent, |
|
1381 | 1420 | if (se && /\d{5,}/.test(se)) { |
1382 | 1421 | se = se.toString(16); |
1383 | 1422 | } else { |
1384 | | - se = String(Math.random() * 31242) |
| 1423 | + se = String(_.getRandom() * 31242) |
1385 | 1424 | .replace('.', '') |
1386 | 1425 | .slice(0, 8); |
1387 | 1426 | } |
1388 | 1427 | var val = T() + '-' + R() + '-' + UA() + '-' + se + '-' + T(); |
1389 | 1428 | if (val) { |
1390 | 1429 | return val; |
1391 | 1430 | } 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); |
1393 | 1432 | } |
1394 | 1433 | }; |
1395 | 1434 | })(); |
|
1622 | 1661 | } |
1623 | 1662 | return null; |
1624 | 1663 | }, |
1625 | | - set: function(name, value, days, cross_subdomain, is_secure) { |
| 1664 | + set: function(name, value, days, cross_subdomain) { |
1626 | 1665 | cross_subdomain = typeof cross_subdomain === 'undefined' ? sd.para.cross_subdomain : cross_subdomain; |
1627 | 1666 | var cdomain = '', |
1628 | 1667 | expires = '', |
|
1647 | 1686 |
|
1648 | 1687 | expires = '; expires=' + date.toGMTString(); |
1649 | 1688 | } |
1650 | | - |
1651 | | - if (is_secure) { |
| 1689 | + if (sd.para.is_secure_cookie) { |
1652 | 1690 | secure = '; secure'; |
1653 | 1691 | } |
1654 | 1692 |
|
1655 | 1693 | function getValid(data) { |
1656 | 1694 | if (data) { |
1657 | | - return data; |
| 1695 | + return data.replaceAll(/\r\n/g, ''); |
1658 | 1696 | } else { |
1659 | 1697 | return false; |
1660 | 1698 | } |
1661 | 1699 | } |
1662 | 1700 | var valid_name = ''; |
1663 | 1701 | var valid_value = ''; |
1664 | 1702 | var valid_domain = ''; |
1665 | | - if (name && value) { |
| 1703 | + if (name) { |
1666 | 1704 | valid_name = getValid(name); |
| 1705 | + } |
| 1706 | + if (value) { |
1667 | 1707 | valid_value = getValid(value); |
1668 | 1708 | } |
1669 | 1709 | if (cdomain) { |
|
1672 | 1712 | if (valid_name && valid_value) { |
1673 | 1713 | document.cookie = valid_name + '=' + encodeURIComponent(valid_value) + expires + '; path=/' + valid_domain + secure; |
1674 | 1714 | } |
| 1715 | + |
1675 | 1716 | }, |
1676 | 1717 | encrypt: function(v) { |
1677 | 1718 | return 'data:enc;' + _.rot13obfs(v); |
|
3206 | 3247 |
|
3207 | 3248 | sd.setInitVar = function() { |
3208 | 3249 | sd._t = sd._t || 1 * new Date(); |
3209 | | - sd.lib_version = '1.16.12'; |
| 3250 | + sd.lib_version = '1.16.13'; |
3210 | 3251 | sd.is_first_visitor = false; |
3211 | 3252 | sd.source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term'; |
3212 | 3253 | }; |
|
4110 | 4151 | source: 'sa-web-sdk', |
4111 | 4152 | type: 'v-is-vtrack', |
4112 | 4153 | data: { |
4113 | | - sdkversion: '1.16.12' |
| 4154 | + sdkversion: '1.16.13' |
4114 | 4155 | } |
4115 | 4156 | }, |
4116 | 4157 | '*' |
|
4437 | 4478 | }; |
4438 | 4479 | }, |
4439 | 4480 | 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); |
4441 | 4482 | localStorage.setItem('sawebjssdk-' + uuid, JSON.stringify(data)); |
4442 | 4483 | } |
4443 | 4484 | }; |
|
4659 | 4700 | return false; |
4660 | 4701 | } |
4661 | 4702 |
|
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)); |
4663 | 4704 | if (sd.para.use_client_time) { |
4664 | 4705 | data._flush_time = new Date().getTime(); |
4665 | 4706 | } |
|
5003 | 5044 | }, |
5004 | 5045 | set: function(name, value) { |
5005 | 5046 | 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; |
5009 | 5048 | this._state[name] = value; |
5010 | 5049 | if (name === 'first_id') { |
5011 | 5050 | delete this._state._first_id; |
5012 | 5051 | } else if (name === 'distinct_id') { |
5013 | 5052 | delete this._state._distinct_id; |
5014 | 5053 | } |
5015 | 5054 | this.save(); |
| 5055 | + if (name === 'distinct_id' && pre_id) { |
| 5056 | + sd.events.tempAdd('changeDistinctId', value); |
| 5057 | + } |
5016 | 5058 | }, |
5017 | 5059 | change: function(name, value) { |
5018 | 5060 | this._state['_' + name] = value; |
|
5498 | 5540 | var iframe = null; |
5499 | 5541 | if (sd.bridge.iOS_UA_bridge()) { |
5500 | 5542 | 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); |
5514 | 5554 | document.documentElement.appendChild(iframe); |
5515 | 5555 | iframe.parentNode.removeChild(iframe); |
5516 | 5556 | iframe = null; |
|
5678 | 5718 |
|
5679 | 5719 | function getKey() { |
5680 | 5720 | 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); |
5682 | 5722 | return d + '-' + m; |
5683 | 5723 | } |
5684 | 5724 | var key = getKey(); |
|
0 commit comments