Skip to content

Commit c86f586

Browse files
author
shengyonggen
committed
decodeurl异常的处理
1 parent 1fbc5d6 commit c86f586

File tree

4 files changed

+46
-96
lines changed

4 files changed

+46
-96
lines changed

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: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var just_test_distinctid_2 = 0;
1717
var just_test_distinctid_detail = 0;
1818
var just_test_distinctid_detail2 = 0;
1919

20+
2021
// 标准广告系列来源
2122
var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
2223

@@ -163,10 +164,6 @@ logger.info = function() {
163164
return found;
164165
};
165166

166-
_.includes = function(str, needle) {
167-
return str.indexOf(needle) !== -1;
168-
};
169-
170167
})();
171168

172169
_.inherit = function(subclass, superclass) {
@@ -224,6 +221,16 @@ _.isJSONString = function(str) {
224221
}
225222
return true;
226223
};
224+
// gbk等编码decode会异常
225+
_.decodeURIComponent = function(val){
226+
var result = '';
227+
try{
228+
result = decodeURIComponent(val);
229+
}catch(e){
230+
result = val;
231+
};
232+
return result;
233+
};
227234

228235
_.encodeDates = function(obj) {
229236
_.each(obj, function(v, k) {
@@ -489,7 +496,7 @@ _.getQueryParam = function(url, param) {
489496
if (results === null || (results && typeof(results[1]) !== 'string' && results[1].length)) {
490497
return '';
491498
} else {
492-
return decodeURIComponent(results[1]).replace(/\+/g, ' ');
499+
return _.decodeURIComponent(results[1]).replace(/\+/g, ' ');
493500
}
494501
};
495502

@@ -694,7 +701,7 @@ _.cookie = {
694701
c = c.substring(1, c.length);
695702
}
696703
if (c.indexOf(nameEQ) == 0) {
697-
return decodeURIComponent(c.substring(nameEQ.length, c.length));
704+
return _.decodeURIComponent(c.substring(nameEQ.length, c.length));
698705
}
699706
}
700707
return null;
@@ -879,7 +886,7 @@ _.url = (function() {
879886
}
880887

881888
function _d(s) {
882-
return decodeURIComponent(s.replace(/\+/g, ' '));
889+
return _.decodeURIComponent(s.replace(/\+/g, ' '));
883890
}
884891

885892
function _i(arg, str) {
@@ -1055,7 +1062,10 @@ _.url = (function() {
10551062
};
10561063
})();
10571064

1065+
_.dom = {
1066+
10581067

1068+
};
10591069

10601070

10611071
_.info = {
@@ -1592,47 +1602,12 @@ saEvent.send = function(p, callback) {
15921602
});
15931603
},
15941604
allTrack: function(){
1595-
// 避免没有ready
1596-
if(!document || !document.body){
1597-
setTimeout(this.allTrack,1000);
1598-
return false;
1599-
}
16001605

1601-
if(sd.allTrack === 'has_init'){
1602-
return false;
1603-
}
1604-
sd.allTrack = 'has_init';
1605-
1606-
_.addEvent(document,'click',function(e){
1607-
1608-
var props = {};
1609-
var target = e.target;
1610-
var tagName = target.tagName.toLowerCase();
1611-
if(' button a select input textarea '.indexOf(' '+ tagName + ' ') !== -1){
1612-
props.$el_tagName = tagName;
1613-
props.$el_name = target.getAttribute('name');
1614-
props.$el_id = target.getAttribute('id');
1615-
props.$el_className = target.className;
1616-
props.$el_href = target.getAttribute('href');
1617-
1618-
// 获取内容
1619-
if (target.textContent) {
1620-
var textContent = _.trim(target.textContent);
1621-
if (textContent) {
1622-
textContent = textContent.replace(/[\r\n]/g, ' ').replace(/[ ]+/g, ' ').substring(0, 255);
1623-
}
1624-
props.$el_text = textContent;
1625-
}
1626-
props = _.strip_empty_properties(props);
1627-
console.log(props)
1628-
sd.track('$web_event',props);
1629-
}
1630-
});
16311606
},
16321607
autoTrackWithoutProfile:function(para){
16331608
this.autoTrack(_.extend(para,{not_set_profile:true}));
16341609
},
1635-
autoTrack: function(para) {
1610+
autoTrack: function(para, callback) {
16361611
para = _.isObject(para) ? para : {};
16371612

16381613
var utms = _.info.campaignParams();
@@ -1666,7 +1641,7 @@ saEvent.send = function(p, callback) {
16661641
$url: location.href,
16671642
$url_path: location.pathname,
16681643
$title: document.title
1669-
}, $utms,para)
1644+
}, $utms,para),callback
16701645
);
16711646
}
16721647

src/sensorsdata.full.js

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ if(typeof JSON!=='object'){JSON={}}(function(){'use strict';var rx_one=/^[\],:{}
617617
, slice = ArrayProto.slice
618618
, toString = ObjProto.toString
619619
, hasOwnProperty = ObjProto.hasOwnProperty
620-
, LIB_VERSION = '1.6.13';
620+
, LIB_VERSION = '1.6.15';
621621

622622
sd.lib_version = LIB_VERSION;
623623

@@ -630,6 +630,7 @@ var just_test_distinctid_2 = 0;
630630
var just_test_distinctid_detail = 0;
631631
var just_test_distinctid_detail2 = 0;
632632

633+
633634
// 标准广告系列来源
634635
var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
635636

@@ -776,10 +777,6 @@ logger.info = function() {
776777
return found;
777778
};
778779

779-
_.includes = function(str, needle) {
780-
return str.indexOf(needle) !== -1;
781-
};
782-
783780
})();
784781

785782
_.inherit = function(subclass, superclass) {
@@ -837,6 +834,16 @@ _.isJSONString = function(str) {
837834
}
838835
return true;
839836
};
837+
// gbk等编码decode会异常
838+
_.decodeURIComponent = function(val){
839+
var result = '';
840+
try{
841+
result = decodeURIComponent(val);
842+
}catch(e){
843+
result = val;
844+
};
845+
return result;
846+
};
840847

841848
_.encodeDates = function(obj) {
842849
_.each(obj, function(v, k) {
@@ -1102,7 +1109,7 @@ _.getQueryParam = function(url, param) {
11021109
if (results === null || (results && typeof(results[1]) !== 'string' && results[1].length)) {
11031110
return '';
11041111
} else {
1105-
return decodeURIComponent(results[1]).replace(/\+/g, ' ');
1112+
return _.decodeURIComponent(results[1]).replace(/\+/g, ' ');
11061113
}
11071114
};
11081115

@@ -1307,7 +1314,7 @@ _.cookie = {
13071314
c = c.substring(1, c.length);
13081315
}
13091316
if (c.indexOf(nameEQ) == 0) {
1310-
return decodeURIComponent(c.substring(nameEQ.length, c.length));
1317+
return _.decodeURIComponent(c.substring(nameEQ.length, c.length));
13111318
}
13121319
}
13131320
return null;
@@ -1492,7 +1499,7 @@ _.url = (function() {
14921499
}
14931500

14941501
function _d(s) {
1495-
return decodeURIComponent(s.replace(/\+/g, ' '));
1502+
return _.decodeURIComponent(s.replace(/\+/g, ' '));
14961503
}
14971504

14981505
function _i(arg, str) {
@@ -1668,7 +1675,10 @@ _.url = (function() {
16681675
};
16691676
})();
16701677

1678+
_.dom = {
1679+
16711680

1681+
};
16721682

16731683

16741684
_.info = {
@@ -2199,47 +2209,12 @@ saEvent.send = function(p, callback) {
21992209
});
22002210
},
22012211
allTrack: function(){
2202-
// 避免没有ready
2203-
if(!document || !document.body){
2204-
setTimeout(this.allTrack,1000);
2205-
return false;
2206-
}
22072212

2208-
if(sd.allTrack === 'has_init'){
2209-
return false;
2210-
}
2211-
sd.allTrack = 'has_init';
2212-
2213-
_.addEvent(document,'click',function(e){
2214-
2215-
var props = {};
2216-
var target = e.target;
2217-
var tagName = target.tagName.toLowerCase();
2218-
if(' button a select input textarea '.indexOf(' '+ tagName + ' ') !== -1){
2219-
props.$el_tagName = tagName;
2220-
props.$el_name = target.getAttribute('name');
2221-
props.$el_id = target.getAttribute('id');
2222-
props.$el_className = target.className;
2223-
props.$el_href = target.getAttribute('href');
2224-
2225-
// 获取内容
2226-
if (target.textContent) {
2227-
var textContent = _.trim(target.textContent);
2228-
if (textContent) {
2229-
textContent = textContent.replace(/[\r\n]/g, ' ').replace(/[ ]+/g, ' ').substring(0, 255);
2230-
}
2231-
props.$el_text = textContent;
2232-
}
2233-
props = _.strip_empty_properties(props);
2234-
console.log(props)
2235-
sd.track('$web_event',props);
2236-
}
2237-
});
22382213
},
22392214
autoTrackWithoutProfile:function(para){
22402215
this.autoTrack(_.extend(para,{not_set_profile:true}));
22412216
},
2242-
autoTrack: function(para) {
2217+
autoTrack: function(para, callback) {
22432218
para = _.isObject(para) ? para : {};
22442219

22452220
var utms = _.info.campaignParams();
@@ -2273,7 +2248,7 @@ saEvent.send = function(p, callback) {
22732248
$url: location.href,
22742249
$url_path: location.pathname,
22752250
$title: document.title
2276-
}, $utms,para)
2251+
}, $utms,para),callback
22772252
);
22782253
}
22792254

vtrack.min.js

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

0 commit comments

Comments
 (0)