Skip to content

Commit bb29bd1

Browse files
author
shengyonggen
committed
给distinct_id为为定义的加错误日志
1 parent 0d0090e commit bb29bd1

File tree

5 files changed

+154
-14
lines changed

5 files changed

+154
-14
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: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ var is_first_visitor = false;
1414

1515
var just_test_distinctid = 0;
1616
var just_test_distinctid_2 = 0;
17+
var just_test_distinctid_detail = 0;
18+
var just_test_distinctid_detail2 = 0;
1719

1820
// 标准广告系列来源
1921
var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
@@ -581,6 +583,53 @@ _.hasStandardBrowserEnviroment = function() {
581583

582584
};
583585

586+
_.addEvent = (function() {
587+
var register_event = function(element, type, handler) {
588+
if (element.addEventListener) {
589+
element.addEventListener(type, handler, false);
590+
} else {
591+
var ontype = 'on' + type;
592+
var old_handler = element[ontype];
593+
element[ontype] = makeHandler(element, handler, old_handler);
594+
}
595+
};
596+
597+
function makeHandler(element, new_handler, old_handlers) {
598+
var handler = function(event) {
599+
event = event || fixEvent(window.event);
600+
if (!event) {
601+
return undefined;
602+
}
603+
var ret = true;
604+
var old_result, new_result;
605+
if (_.isFunction(old_handlers)) {
606+
old_result = old_handlers(event);
607+
}
608+
new_result = new_handler.call(element, event);
609+
if ((false === old_result) || (false === new_result)) {
610+
ret = false;
611+
}
612+
return ret;
613+
};
614+
return handler;
615+
}
616+
617+
function fixEvent(event) {
618+
if (event) {
619+
event.preventDefault = fixEvent.preventDefault;
620+
event.stopPropagation = fixEvent.stopPropagation;
621+
}
622+
return event;
623+
}
624+
fixEvent.preventDefault = function() {
625+
this.returnValue = false;
626+
};
627+
fixEvent.stopPropagation = function() {
628+
this.cancelBubble = true;
629+
};
630+
return register_event;
631+
})();
632+
584633
_.cookie = {
585634
get: function(name) {
586635
var nameEQ = name + '=';
@@ -973,7 +1022,7 @@ _.info = {
9731022
};
9741023
},
9751024
//当前页面的一些属性,在store初始化是生成
976-
pageProp: {},
1025+
pageProp: {},
9771026

9781027
campaignParams: function() {
9791028
var campaign_keywords = source_channel_standard.split(' ')
@@ -1266,7 +1315,7 @@ saEvent.send = function(p, callback) {
12661315
default:
12671316
wrong_case = String(store.getDistinctId());
12681317
}
1269-
error_msg.push('distinct_id-' + just_test_distinctid + '-' + just_test_distinctid_2 + '-' + wrong_case + '-' + (new Date()).getTime());
1318+
error_msg.push('distinct_id-' + just_test_distinctid + '-' + just_test_distinctid_2 + '-' + wrong_case + '-' + just_test_distinctid_detail + '-' + just_test_distinctid_detail2);
12701319
}
12711320

12721321
_.extend(data, p);
@@ -1437,6 +1486,8 @@ saEvent.send = function(p, callback) {
14371486
} else {
14381487

14391488
just_test_distinctid = 2;
1489+
just_test_distinctid_detail = JSON.stringify(cross);
1490+
just_test_distinctid_detail2 = navigator.userAgent+'^_^'+document.cookie;
14401491

14411492
this.toState(cross);
14421493
}
@@ -1485,7 +1536,22 @@ saEvent.send = function(p, callback) {
14851536
_referring_host: _.info.pageProp.referrer_host
14861537
});
14871538
},
1539+
allTrack: function(){
1540+
/*
1541+
_.addEvent('document','click',function(e){
1542+
var ev = e || window.event;
1543+
var target = ev.target || ev.srcElement;
1544+
var tagName = target.tagName.toLowerCase();
1545+
if( tagName === 'button' || tagName === 'a' || tagName === 'input' || tagName === 'textarea'){
1546+
14881547
1548+
}
1549+
1550+
1551+
});
1552+
*/
1553+
1554+
},
14891555
autoTrackWithoutProfile:function(para){
14901556
this.autoTrack(_.extend(para,{not_set_profile:true}));
14911557
},

src/sensorsdata.full.js

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
// 防止重复引入
99
sd = window[sd];
10-
sd._t = sd._t || 1 * new Date();
1110

1211
if ((typeof sd !== 'function' && typeof sd !== 'object') || sd.has_load_sdk) {
1312
return false;
1413
}
14+
sd._t = sd._t || 1 * new Date();
15+
1516
sd.has_load_sdk = true;
1617

1718
// 压缩后的json库
@@ -614,7 +615,7 @@ if(typeof JSON!=='object'){JSON={}}(function(){'use strict';var rx_one=/^[\],:{}
614615
, slice = ArrayProto.slice
615616
, toString = ObjProto.toString
616617
, hasOwnProperty = ObjProto.hasOwnProperty
617-
, LIB_VERSION = '1.6.9';
618+
, LIB_VERSION = '1.6.11';
618619

619620
sd.lib_version = LIB_VERSION;
620621

@@ -624,6 +625,8 @@ var is_first_visitor = false;
624625

625626
var just_test_distinctid = 0;
626627
var just_test_distinctid_2 = 0;
628+
var just_test_distinctid_detail = 0;
629+
var just_test_distinctid_detail2 = 0;
627630

628631
// 标准广告系列来源
629632
var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
@@ -1191,6 +1194,59 @@ _.hasStandardBrowserEnviroment = function() {
11911194

11921195
};
11931196

1197+
_.addEvent = (function() {
1198+
var register_event = function(element, type, handler) {
1199+
if (element.addEventListener) {
1200+
element.addEventListener(type, handler, false);
1201+
} else {
1202+
var ontype = 'on' + type;
1203+
var old_handler = element[ontype];
1204+
element[ontype] = makeHandler(element, handler, old_handler);
1205+
}
1206+
};
1207+
1208+
function makeHandler(element, new_handler, old_handlers) {
1209+
var handler = function(event) {
1210+
event = event || fixEvent(window.event);
1211+
if (!event) {
1212+
return undefined;
1213+
}
1214+
1215+
var ret = true;
1216+
var old_result, new_result;
1217+
1218+
if (_.isFunction(old_handlers)) {
1219+
old_result = old_handlers(event);
1220+
}
1221+
new_result = new_handler.call(element, event);
1222+
1223+
if ((false === old_result) || (false === new_result)) {
1224+
ret = false;
1225+
}
1226+
1227+
return ret;
1228+
};
1229+
1230+
return handler;
1231+
}
1232+
1233+
function fixEvent(event) {
1234+
if (event) {
1235+
event.preventDefault = fixEvent.preventDefault;
1236+
event.stopPropagation = fixEvent.stopPropagation;
1237+
}
1238+
return event;
1239+
}
1240+
fixEvent.preventDefault = function() {
1241+
this.returnValue = false;
1242+
};
1243+
fixEvent.stopPropagation = function() {
1244+
this.cancelBubble = true;
1245+
};
1246+
1247+
return register_event;
1248+
})();
1249+
11941250
_.cookie = {
11951251
get: function(name) {
11961252
var nameEQ = name + '=';
@@ -1583,7 +1639,7 @@ _.info = {
15831639
};
15841640
},
15851641
//当前页面的一些属性,在store初始化是生成
1586-
pageProp: {},
1642+
pageProp: {},
15871643

15881644
campaignParams: function() {
15891645
var campaign_keywords = source_channel_standard.split(' ')
@@ -1876,7 +1932,7 @@ saEvent.send = function(p, callback) {
18761932
default:
18771933
wrong_case = String(store.getDistinctId());
18781934
}
1879-
error_msg.push('distinct_id-' + just_test_distinctid + '-' + just_test_distinctid_2 + '-' + wrong_case + '-' + (new Date()).getTime());
1935+
error_msg.push('distinct_id-' + just_test_distinctid + '-' + just_test_distinctid_2 + '-' + wrong_case + '-' + just_test_distinctid_detail + '-' + just_test_distinctid_detail2);
18801936
}
18811937

18821938
_.extend(data, p);
@@ -2041,6 +2097,8 @@ saEvent.send = function(p, callback) {
20412097
} else {
20422098

20432099
just_test_distinctid = 2;
2100+
just_test_distinctid_detail = JSON.stringify(cross);
2101+
just_test_distinctid_detail2 = navigator.userAgent+'^_^'+document.cookie;
20442102

20452103
this.toState(cross);
20462104
}
@@ -2089,7 +2147,22 @@ saEvent.send = function(p, callback) {
20892147
_referring_host: _.info.pageProp.referrer_host
20902148
});
20912149
},
2150+
allTrack: function(){
2151+
/*
2152+
_.addEvent('document','click',function(e){
2153+
var ev = e || window.event;
2154+
var target = ev.target || ev.srcElement;
2155+
var tagName = target.tagName.toLowerCase();
2156+
if( tagName === 'button' || tagName === 'a' || tagName === 'input' || tagName === 'textarea'){
2157+
2158+
2159+
}
20922160
2161+
2162+
});
2163+
*/
2164+
2165+
},
20932166
autoTrackWithoutProfile:function(para){
20942167
this.autoTrack(_.extend(para,{not_set_profile:true}));
20952168
},

src/sensorsdata.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
// 防止重复引入
99
sd = window[sd];
10-
sd._t = sd._t || 1 * new Date();
1110

1211
if ((typeof sd !== 'function' && typeof sd !== 'object') || sd.has_load_sdk) {
1312
return false;
1413
}
14+
sd._t = sd._t || 1 * new Date();
15+
1516
sd.has_load_sdk = true;
1617

1718
@@include('sa-sdk-javascript/src/json2.js')

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)