Skip to content

Commit 4de0f40

Browse files
author
shengyonggen
committed
点击图样式修改,webpack和npm相关包优化,app和h5打通的优化
1 parent e4f6216 commit 4de0f40

File tree

6 files changed

+139
-67
lines changed

6 files changed

+139
-67
lines changed

package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "sa-sdk-javascript",
3+
"version": "1.7.20",
4+
"description": "official sensorsdata javascript sdk",
5+
"main": "sensorsdata.min.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/sensorsdata/sa-sdk-javascript.git"
12+
},
13+
"keywords": [
14+
"sensorsdata",
15+
"javascript",
16+
"sdk"
17+
],
18+
"author": "shengyonggen",
19+
"license": "Apache-2.0",
20+
"bugs": {
21+
"url": "https://github.com/sensorsdata/sa-sdk-javascript/issues"
22+
},
23+
"homepage": "https://github.com/sensorsdata/sa-sdk-javascript#readme"
24+
}

sensorsdata.min.js

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

src/sdk.js

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,17 @@ _.encodeDates = function(obj) {
250250
return obj;
251251
};
252252

253+
_.hashCode = function(str){
254+
var hash = 0;
255+
if (str.length == 0) return hash;
256+
for (i = 0; i < str.length; i++) {
257+
char = str.charCodeAt(i);
258+
hash = ((hash<<5)-hash)+char;
259+
hash = hash & hash;
260+
}
261+
return hash;
262+
};
263+
253264
_.formatDate = function(d) {
254265
function pad(n) {
255266
return n < 10 ? '0' + n : n;
@@ -1459,41 +1470,45 @@ sd.sendState.getSendCall = function(data, callback) {
14591470
// 加cache防止缓存
14601471
data._nocache = (String(Math.random()) + String(Math.random()) + String(Math.random())).replace(/\./g,'').slice(0,15);
14611472
data = JSON.stringify(data);
1462-
1473+
logger.info(data);
14631474
// 打通app传数据给app
14641475
if(sd.para.use_app_track){
14651476
if((typeof SensorsData_APP_JS_Bridge === 'object') && SensorsData_APP_JS_Bridge.sensorsdata_track){
14661477
SensorsData_APP_JS_Bridge.sensorsdata_track(data);
1467-
logger.info('app数据',data);
1468-
}else if(/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream){
1478+
(typeof callback === 'function') && callback();
1479+
}else if(/sa-sdk-ios/.test(navigator.userAgent) && !window.MSStream){
14691480
var iframe = document.createElement('iframe');
14701481
iframe.setAttribute('src', 'sensorsanalytics://trackEvent?event=' + encodeURIComponent(data));
14711482
document.documentElement.appendChild(iframe);
14721483
iframe.parentNode.removeChild(iframe);
14731484
iframe = null;
1485+
(typeof callback === 'function') && callback();
1486+
}else{
1487+
this.prepareServerUrl(data,callback);
14741488
}
1475-
(typeof callback === 'function') && callback();
1476-
return false;
1489+
}else{
1490+
this.prepareServerUrl(data,callback);
14771491
}
1478-
logger.info(data);
1479-
this.prepareServerUrl(data,callback);
1492+
};
1493+
1494+
sd.sendState.getUrlPara = function(url,data){
1495+
var base64Data = _.base64Encode(data);
1496+
var crc = 'crc=' + _.hashCode(base64Data);
1497+
if (url.indexOf('?') !== -1) {
1498+
return url + '&data=' + encodeURIComponent(base64Data) + '&ext=' + encodeURIComponent(crc);
1499+
}else{
1500+
return url + '?data=' + encodeURIComponent(base64Data) + '&ext=' + encodeURIComponent(crc);
1501+
}
1502+
14801503
};
14811504

14821505
sd.sendState.prepareServerUrl = function(data,callback){
14831506
if(_.isArray(sd.para.server_url)){
14841507
for(var i =0; i<sd.para.server_url.length;i++){
1485-
if (sd.para.server_url[i].indexOf('?') !== -1) {
1486-
this.sendCall(sd.para.server_url[i] + '&data=' + encodeURIComponent(_.base64Encode(data)),callback);
1487-
} else {
1488-
this.senCall(sd.para.server_url[i] + '?data=' + encodeURIComponent(_.base64Encode(data)),callback);
1489-
}
1508+
this.sendCall(this.getUrlPara(sd.para.server_url[i],data),callback);
14901509
}
14911510
}else{
1492-
if (sd.para.server_url.indexOf('?') !== -1) {
1493-
this.sendCall(sd.para.server_url + '&data=' + encodeURIComponent(_.base64Encode(data)),callback);
1494-
} else {
1495-
this.sendCall(sd.para.server_url + '?data=' + encodeURIComponent(_.base64Encode(data)),callback);
1496-
}
1511+
this.sendCall(this.getUrlPara(sd.para.server_url,data),callback);
14971512
}
14981513
};
14991514

@@ -2589,7 +2604,7 @@ var heatmap_render = {
25892604
setRefresh: function(){
25902605
var me = this;
25912606
var div = document.createElement('div');
2592-
div.setAttribute('style','border-radius:3px;cursor:pointer;z-index:99999;padding:8px 10px;background:#3790e9;color:#fff;position: fixed;left:10px;bottom:10px;');
2607+
div.setAttribute('style','border-radius:3px;font-size:14px;cursor:pointer;z-index:99999;padding:8px 10px;background:#3790e9;color:#fff;position: fixed;left:10px;bottom:10px;');
25932608
div.innerHTML = '<svg width="15px" height="13px" viewBox="0 0 15 15" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g transform="translate(-145.000000, -1953.000000)" fill="#FFFFFF"><g transform="translate(132.000000, 1941.000000)"><path d="M27.8813854,14.6046259 L25.720853,15.6691713 C24.4905498,13.2443736 21.804888,11.6623409 18.7741412,12.0615454 C15.7734018,12.4607499 13.3728103,14.900333 13.042729,17.8574034 C12.592618,21.8494485 15.7583981,25.2352941 19.7193742,25.2352941 C22.5700766,25.2352941 24.9706681,23.4906226 25.9459084,21.0214688 L24.2804981,20.4744107 L24.2654944,20.4744107 C23.3952799,22.5295747 21.1297217,23.8602564 18.639108,23.342769 C16.7936532,22.9583499 15.2932835,21.4798147 14.9031874,19.646431 C14.2430247,16.5119364 16.6436163,13.7470755 19.7193742,13.7470755 C21.6548511,13.7470755 23.3052578,14.8411916 24.1154574,16.4380096 L21.8649028,17.5616964 C21.804888,17.5912671 21.804888,17.6947645 21.8799065,17.7095499 L26.3960193,19.1732998 C26.4410304,19.1880851 26.4860415,19.1585144 26.5010452,19.1141583 L27.9864112,14.6637674 C28.0314223,14.6341967 27.9564038,14.5750552 27.8813854,14.6046259 L27.8813854,14.6046259 Z" id="refresh"></path></g></g></g></svg> <span title="当页面有内容更切换时候,点击刷新数据,重新计算">刷新点击图数据</span>';
25942609
document.body.appendChild(div);
25952610
_.addEvent(div,'click',function(){

src/sensorsdata.full.js

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@
22
* @fileoverview sensors analytic javascript sdk
33
44
*/
5-
(function() {
5+
6+
;(function(root,factory) {
7+
8+
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
9+
define(factory);
10+
} else if (typeof exports === 'object' && typeof module === 'object') {
11+
module.exports = factory();
12+
}else{
13+
factory();
14+
}
15+
16+
})(this,function(){
17+
618
try{
719
var sd = window['sensorsDataAnalytic201505'],has_declare;
820
if(sd){
@@ -110,7 +122,7 @@ sd.initPara = function(para){
110122
, slice = ArrayProto.slice
111123
, toString = ObjProto.toString
112124
, hasOwnProperty = ObjProto.hasOwnProperty
113-
, LIB_VERSION = '1.7.19';
125+
, LIB_VERSION = '1.7.20';
114126

115127
sd.lib_version = LIB_VERSION;
116128

@@ -356,6 +368,17 @@ _.encodeDates = function(obj) {
356368
return obj;
357369
};
358370

371+
_.hashCode = function(str){
372+
var hash = 0;
373+
if (str.length == 0) return hash;
374+
for (i = 0; i < str.length; i++) {
375+
char = str.charCodeAt(i);
376+
hash = ((hash<<5)-hash)+char;
377+
hash = hash & hash;
378+
}
379+
return hash;
380+
};
381+
359382
_.formatDate = function(d) {
360383
function pad(n) {
361384
return n < 10 ? '0' + n : n;
@@ -1565,41 +1588,45 @@ sd.sendState.getSendCall = function(data, callback) {
15651588
// 加cache防止缓存
15661589
data._nocache = (String(Math.random()) + String(Math.random()) + String(Math.random())).replace(/\./g,'').slice(0,15);
15671590
data = JSON.stringify(data);
1568-
1591+
logger.info(data);
15691592
// 打通app传数据给app
15701593
if(sd.para.use_app_track){
15711594
if((typeof SensorsData_APP_JS_Bridge === 'object') && SensorsData_APP_JS_Bridge.sensorsdata_track){
15721595
SensorsData_APP_JS_Bridge.sensorsdata_track(data);
1573-
logger.info('app数据',data);
1574-
}else if(/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream){
1596+
(typeof callback === 'function') && callback();
1597+
}else if(/sa-sdk-ios/.test(navigator.userAgent) && !window.MSStream){
15751598
var iframe = document.createElement('iframe');
15761599
iframe.setAttribute('src', 'sensorsanalytics://trackEvent?event=' + encodeURIComponent(data));
15771600
document.documentElement.appendChild(iframe);
15781601
iframe.parentNode.removeChild(iframe);
15791602
iframe = null;
1603+
(typeof callback === 'function') && callback();
1604+
}else{
1605+
this.prepareServerUrl(data,callback);
15801606
}
1581-
(typeof callback === 'function') && callback();
1582-
return false;
1607+
}else{
1608+
this.prepareServerUrl(data,callback);
15831609
}
1584-
logger.info(data);
1585-
this.prepareServerUrl(data,callback);
1610+
};
1611+
1612+
sd.sendState.getUrlPara = function(url,data){
1613+
var base64Data = _.base64Encode(data);
1614+
var crc = 'crc=' + _.hashCode(base64Data);
1615+
if (url.indexOf('?') !== -1) {
1616+
return url + '&data=' + encodeURIComponent(base64Data) + '&ext=' + encodeURIComponent(crc);
1617+
}else{
1618+
return url + '?data=' + encodeURIComponent(base64Data) + '&ext=' + encodeURIComponent(crc);
1619+
}
1620+
15861621
};
15871622

15881623
sd.sendState.prepareServerUrl = function(data,callback){
15891624
if(_.isArray(sd.para.server_url)){
15901625
for(var i =0; i<sd.para.server_url.length;i++){
1591-
if (sd.para.server_url[i].indexOf('?') !== -1) {
1592-
this.sendCall(sd.para.server_url[i] + '&data=' + encodeURIComponent(_.base64Encode(data)),callback);
1593-
} else {
1594-
this.senCall(sd.para.server_url[i] + '?data=' + encodeURIComponent(_.base64Encode(data)),callback);
1595-
}
1626+
this.sendCall(this.getUrlPara(sd.para.server_url[i],data),callback);
15961627
}
15971628
}else{
1598-
if (sd.para.server_url.indexOf('?') !== -1) {
1599-
this.sendCall(sd.para.server_url + '&data=' + encodeURIComponent(_.base64Encode(data)),callback);
1600-
} else {
1601-
this.sendCall(sd.para.server_url + '?data=' + encodeURIComponent(_.base64Encode(data)),callback);
1602-
}
1629+
this.sendCall(this.getUrlPara(sd.para.server_url,data),callback);
16031630
}
16041631
};
16051632

@@ -2689,7 +2716,7 @@ var heatmap_render = {
26892716
setRefresh: function(){
26902717
var me = this;
26912718
var div = document.createElement('div');
2692-
div.setAttribute('style','border-radius:3px;cursor:pointer;z-index:99999;padding:8px 10px;background:#3790e9;color:#fff;position: fixed;left:10px;bottom:10px;');
2719+
div.setAttribute('style','border-radius:3px;font-size:14px;cursor:pointer;z-index:99999;padding:8px 10px;background:#3790e9;color:#fff;position: fixed;left:10px;bottom:10px;');
26932720
div.innerHTML = '<svg width="15px" height="13px" viewBox="0 0 15 15" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g transform="translate(-145.000000, -1953.000000)" fill="#FFFFFF"><g transform="translate(132.000000, 1941.000000)"><path d="M27.8813854,14.6046259 L25.720853,15.6691713 C24.4905498,13.2443736 21.804888,11.6623409 18.7741412,12.0615454 C15.7734018,12.4607499 13.3728103,14.900333 13.042729,17.8574034 C12.592618,21.8494485 15.7583981,25.2352941 19.7193742,25.2352941 C22.5700766,25.2352941 24.9706681,23.4906226 25.9459084,21.0214688 L24.2804981,20.4744107 L24.2654944,20.4744107 C23.3952799,22.5295747 21.1297217,23.8602564 18.639108,23.342769 C16.7936532,22.9583499 15.2932835,21.4798147 14.9031874,19.646431 C14.2430247,16.5119364 16.6436163,13.7470755 19.7193742,13.7470755 C21.6548511,13.7470755 23.3052578,14.8411916 24.1154574,16.4380096 L21.8649028,17.5616964 C21.804888,17.5912671 21.804888,17.6947645 21.8799065,17.7095499 L26.3960193,19.1732998 C26.4410304,19.1880851 26.4860415,19.1585144 26.5010452,19.1141583 L27.9864112,14.6637674 C28.0314223,14.6341967 27.9564038,14.5750552 27.8813854,14.6046259 L27.8813854,14.6046259 Z" id="refresh"></path></g></g></g></svg> <span title="当页面有内容更切换时候,点击刷新数据,重新计算">刷新点击图数据</span>';
26942721
document.body.appendChild(div);
26952722
_.addEvent(div,'click',function(){
@@ -3445,15 +3472,9 @@ var heatmap = {
34453472

34463473
sd.init();
34473474

3448-
3449-
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
3450-
// this[sd.para.name] = sd;
3451-
define(function() {
3452-
return sd;
3453-
});
3454-
}
3455-
3456-
3475+
3476+
return sd;
3477+
34573478
}catch(err){
34583479
if (typeof console === 'object' && console.log) {
34593480
try {console.log(err)} catch (e) {};
@@ -3473,4 +3494,7 @@ var heatmap = {
34733494
})();
34743495
*/
34753496
}
3476-
})();
3497+
3498+
3499+
3500+
});

src/sensorsdata.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@
22
* @fileoverview sensors analytic javascript sdk
33
44
*/
5-
(function() {
5+
6+
;(function(root,factory) {
7+
8+
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
9+
define(factory);
10+
} else if (typeof exports === 'object' && typeof module === 'object') {
11+
module.exports = factory();
12+
}else{
13+
factory();
14+
}
15+
16+
})(this,function(){
17+
618
try{
719
var sd = window['sensorsDataAnalytic201505'],has_declare;
820
if(sd){
@@ -118,15 +130,9 @@ sd.initPara = function(para){
118130
@@if (sensorsdata_mode !== 'vtrack') {
119131
sd.init();
120132
}
121-
122-
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
123-
// this[sd.para.name] = sd;
124-
define(function() {
125-
return sd;
126-
});
127-
}
128-
129-
133+
134+
return sd;
135+
130136
}catch(err){
131137
if (typeof console === 'object' && console.log) {
132138
try {console.log(err)} catch (e) {};
@@ -146,4 +152,7 @@ sd.initPara = function(para){
146152
})();
147153
*/
148154
}
149-
})();
155+
156+
157+
158+
});

vtrack.min.js

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

0 commit comments

Comments
 (0)