Skip to content

Commit a921302

Browse files
author
shengyonggen
committed
增加清空所有cookie里的props的方法
1 parent 89daf75 commit a921302

File tree

5 files changed

+42
-10
lines changed

5 files changed

+42
-10
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: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,9 @@ saEvent.send = function(p, callback) {
14921492

14931493
if(typeof(state.props) === 'object'){
14941494
for(var key in state.props){
1495-
state.props[key] = state.props[key].slice(0, sd.para.max_referrer_string_length);
1495+
if(typeof state.props[key] === 'string'){
1496+
state.props[key] = state.props[key].slice(0, sd.para.max_referrer_string_length);
1497+
}
14961498
}
14971499
this.save();
14981500
}
@@ -1510,7 +1512,7 @@ saEvent.send = function(p, callback) {
15101512
var ds = _.cookie.get('sensorsdata2015session');
15111513
var state = null;
15121514
if (ds !== null && (typeof (state = JSON.parse(ds)) === 'object')) {
1513-
this._sessionState = state;
1515+
this._sessionState = state || {};
15141516
}
15151517
},
15161518

@@ -1548,6 +1550,16 @@ saEvent.send = function(p, callback) {
15481550
_.coverExtend(props, newp);
15491551
this.set('props', props);
15501552
},
1553+
clearAllProps: function() {
1554+
this._sessionState = {};
1555+
for(var i in this._state.props){
1556+
if(i.indexOf('latest_') !== 1){
1557+
delete this._state.props[i];
1558+
}
1559+
}
1560+
this.sessionSave({});
1561+
this.save();
1562+
},
15511563
sessionSave: function(props) {
15521564
this._sessionState = props;
15531565
_.cookie.set('sensorsdata2015session', JSON.stringify(this._sessionState), 0);
@@ -2036,6 +2048,10 @@ saEvent.send = function(p, callback) {
20362048
}
20372049
};
20382050

2051+
sd.clearAllRegister = function(){
2052+
store.clearAllProps();
2053+
};
2054+
20392055
sd.register = function(props) {
20402056
if (saEvent.check({properties: props})) {
20412057
store.setProps(props);

src/sensorsdata.full.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ if(typeof JSON!=='object'){JSON={}}(function(){'use strict';var rx_one=/^[\],:{}
620620
, slice = ArrayProto.slice
621621
, toString = ObjProto.toString
622622
, hasOwnProperty = ObjProto.hasOwnProperty
623-
, LIB_VERSION = '1.6.51';
623+
, LIB_VERSION = '1.6.53';
624624

625625
sd.lib_version = LIB_VERSION;
626626

@@ -2102,7 +2102,9 @@ saEvent.send = function(p, callback) {
21022102

21032103
if(typeof(state.props) === 'object'){
21042104
for(var key in state.props){
2105-
state.props[key] = state.props[key].slice(0, sd.para.max_referrer_string_length);
2105+
if(typeof state.props[key] === 'string'){
2106+
state.props[key] = state.props[key].slice(0, sd.para.max_referrer_string_length);
2107+
}
21062108
}
21072109
this.save();
21082110
}
@@ -2120,7 +2122,7 @@ saEvent.send = function(p, callback) {
21202122
var ds = _.cookie.get('sensorsdata2015session');
21212123
var state = null;
21222124
if (ds !== null && (typeof (state = JSON.parse(ds)) === 'object')) {
2123-
this._sessionState = state;
2125+
this._sessionState = state || {};
21242126
}
21252127
},
21262128

@@ -2158,6 +2160,16 @@ saEvent.send = function(p, callback) {
21582160
_.coverExtend(props, newp);
21592161
this.set('props', props);
21602162
},
2163+
clearAllProps: function() {
2164+
this._sessionState = {};
2165+
for(var i in this._state.props){
2166+
if(i.indexOf('latest_') !== 1){
2167+
delete this._state.props[i];
2168+
}
2169+
}
2170+
this.sessionSave({});
2171+
this.save();
2172+
},
21612173
sessionSave: function(props) {
21622174
this._sessionState = props;
21632175
_.cookie.set('sensorsdata2015session', JSON.stringify(this._sessionState), 0);
@@ -2646,6 +2658,10 @@ saEvent.send = function(p, callback) {
26462658
}
26472659
};
26482660

2661+
sd.clearAllRegister = function(){
2662+
store.clearAllProps();
2663+
};
2664+
26492665
sd.register = function(props) {
26502666
if (saEvent.check({properties: props})) {
26512667
store.setProps(props);

version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
var sensorsdata_js_sdk_latest_version = '1.6.51';
1+
var sensorsdata_js_sdk_latest_version = '1.6.53';

vtrack.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.

0 commit comments

Comments
 (0)