Skip to content

Commit 46be3fb

Browse files
author
shengyonggen
committed
增加distinct_id为undeinfided的监测
1 parent 4efcf3c commit 46be3fb

File tree

4 files changed

+57
-19
lines changed

4 files changed

+57
-19
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: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ sd.lib_version = LIB_VERSION;
1212
var error_msg = [];
1313
var is_first_visitor = false;
1414

15+
var just_test_distinctid = 0;
16+
var just_test_distinctid_2 = 0;
17+
1518
// 标准广告系列来源
1619
var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
1720

@@ -410,6 +413,7 @@ _.base64Encode = function(data) {
410413
return enc;
411414
};
412415

416+
413417
_.UUID = (function() {
414418
var T = function() {
415419
var d = 1 * new Date()
@@ -457,7 +461,15 @@ _.UUID = (function() {
457461
} else {
458462
se = String(Math.random() * 31242).replace('.', '').slice(0, 8);
459463
}
460-
return (T() + '-' + R() + '-' + UA() + '-' + se + '-' + T());
464+
var val = (T() + '-' + R() + '-' + UA() + '-' + se + '-' + T());
465+
if(val){
466+
just_test_distinctid_2 = 1;
467+
return val;
468+
}else{
469+
just_test_distinctid_2 = 2;
470+
return (String(Math.random()) + String(Math.random()) + String(Math.random())).slice(2, 15);
471+
}
472+
461473
};
462474
})();
463475

@@ -1254,7 +1266,7 @@ saEvent.send = function(p, callback) {
12541266
default:
12551267
wrong_case = String(store.getDistinctId());
12561268
}
1257-
error_msg.push('distinct_id_wrong' + wrong_case + '-' + (new Date()).getTime());
1269+
error_msg.push('distinct_id-' + just_test_distinctid + '-' + just_test_distinctid_2 + '-' + wrong_case + '-' + (new Date()).getTime());
12581270
}
12591271

12601272
_.extend(data, p);
@@ -1328,6 +1340,8 @@ saEvent.send = function(p, callback) {
13281340
};
13291341

13301342
var store = sd.store = {
1343+
_sessionState: {},
1344+
_state: {},
13311345
getProps: function() {
13321346
return this._state.props;
13331347
},
@@ -1344,11 +1358,11 @@ saEvent.send = function(p, callback) {
13441358
this._state = state;
13451359
} else {
13461360
this.set('distinct_id', _.UUID());
1347-
error_msg.push('parseCookieDistinctJSSDKError');
1361+
error_msg.push('toStateParseDistinctError');
13481362
}
13491363
} else {
13501364
this.set('distinct_id', _.UUID());
1351-
error_msg.push('parseCookieJSSDKError');
1365+
error_msg.push('toStateParseError');
13521366
}
13531367
},
13541368
initSessionState: function() {
@@ -1365,6 +1379,7 @@ saEvent.send = function(p, callback) {
13651379
}
13661380
},
13671381
set: function(name, value) {
1382+
this._state = this._state || {};
13681383
this._state[name] = value;
13691384
this.save();
13701385
},
@@ -1399,8 +1414,6 @@ saEvent.send = function(p, callback) {
13991414
save: function() {
14001415
_.cookie.set('sensorsdata2015jssdkcross', JSON.stringify(this._state), 730, sd.para.cross_subdomain);
14011416
},
1402-
_sessionState: {},
1403-
_state: {},
14041417
init: function() {
14051418
// 如果不支持cookie,设置新的id,并且带有error_msg
14061419
if (!navigator.cookieEnabled) {
@@ -1414,8 +1427,14 @@ saEvent.send = function(p, callback) {
14141427
if (cross === null) {
14151428
// 判断是否是第一次载入sdk
14161429
is_first_visitor = true;
1430+
1431+
just_test_distinctid = 1;
1432+
14171433
this.set('distinct_id', _.UUID());
14181434
} else {
1435+
1436+
just_test_distinctid = 2;
1437+
14191438
this.toState(cross);
14201439
}
14211440
//判断新用户

src/sensorsdata.full.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,9 @@ sd.lib_version = LIB_VERSION;
622622
var error_msg = [];
623623
var is_first_visitor = false;
624624

625+
var just_test_distinctid = 0;
626+
var just_test_distinctid_2 = 0;
627+
625628
// 标准广告系列来源
626629
var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
627630

@@ -1020,6 +1023,7 @@ _.base64Encode = function(data) {
10201023
return enc;
10211024
};
10221025

1026+
10231027
_.UUID = (function() {
10241028
var T = function() {
10251029
var d = 1 * new Date()
@@ -1067,7 +1071,15 @@ _.UUID = (function() {
10671071
} else {
10681072
se = String(Math.random() * 31242).replace('.', '').slice(0, 8);
10691073
}
1070-
return (T() + '-' + R() + '-' + UA() + '-' + se + '-' + T());
1074+
var val = (T() + '-' + R() + '-' + UA() + '-' + se + '-' + T());
1075+
if(val){
1076+
just_test_distinctid_2 = 1;
1077+
return val;
1078+
}else{
1079+
just_test_distinctid_2 = 2;
1080+
return (String(Math.random()) + String(Math.random()) + String(Math.random())).slice(2, 15);
1081+
}
1082+
10711083
};
10721084
})();
10731085

@@ -1864,7 +1876,7 @@ saEvent.send = function(p, callback) {
18641876
default:
18651877
wrong_case = String(store.getDistinctId());
18661878
}
1867-
error_msg.push('distinct_id_wrong' + wrong_case + '-' + (new Date()).getTime());
1879+
error_msg.push('distinct_id-' + just_test_distinctid + '-' + just_test_distinctid_2 + '-' + wrong_case + '-' + (new Date()).getTime());
18681880
}
18691881

18701882
_.extend(data, p);
@@ -1932,6 +1944,8 @@ saEvent.send = function(p, callback) {
19321944
};
19331945

19341946
var store = sd.store = {
1947+
_sessionState: {},
1948+
_state: {},
19351949
getProps: function() {
19361950
return this._state.props;
19371951
},
@@ -1948,11 +1962,11 @@ saEvent.send = function(p, callback) {
19481962
this._state = state;
19491963
} else {
19501964
this.set('distinct_id', _.UUID());
1951-
error_msg.push('parseCookieDistinctJSSDKError');
1965+
error_msg.push('toStateParseDistinctError');
19521966
}
19531967
} else {
19541968
this.set('distinct_id', _.UUID());
1955-
error_msg.push('parseCookieJSSDKError');
1969+
error_msg.push('toStateParseError');
19561970
}
19571971
},
19581972
initSessionState: function() {
@@ -1969,6 +1983,7 @@ saEvent.send = function(p, callback) {
19691983
}
19701984
},
19711985
set: function(name, value) {
1986+
this._state = this._state || {};
19721987
this._state[name] = value;
19731988
this.save();
19741989
},
@@ -2003,8 +2018,6 @@ saEvent.send = function(p, callback) {
20032018
save: function() {
20042019
_.cookie.set('sensorsdata2015jssdkcross', JSON.stringify(this._state), 730, sd.para.cross_subdomain);
20052020
},
2006-
_sessionState: {},
2007-
_state: {},
20082021
init: function() {
20092022
// 如果不支持cookie,设置新的id,并且带有error_msg
20102023
if (!navigator.cookieEnabled) {
@@ -2018,8 +2031,14 @@ saEvent.send = function(p, callback) {
20182031
if (cross === null) {
20192032
// 判断是否是第一次载入sdk
20202033
is_first_visitor = true;
2034+
2035+
just_test_distinctid = 1;
2036+
20212037
this.set('distinct_id', _.UUID());
20222038
} else {
2039+
2040+
just_test_distinctid = 2;
2041+
20232042
this.toState(cross);
20242043
}
20252044
//判断新用户

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)