Skip to content

Commit e007770

Browse files
author
shengyonggen
committed
增加register
1 parent 5b31f4d commit e007770

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

sensorsdata.js

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var ArrayProto = Array.prototype,
2727
slice = ArrayProto.slice,
2828
toString = ObjProto.toString,
2929
hasOwnProperty = ObjProto.hasOwnProperty,
30-
LIB_VERSION = '0.5',
30+
LIB_VERSION = '0.6',
3131
LIB_NAME = 'MiniProgram';
3232

3333
sa.lib_version = LIB_VERSION;
@@ -507,14 +507,14 @@ sa.prepareData = function(p, callback) {
507507
_.extend(data, p);
508508

509509
// 合并properties里的属性
510-
if (_.isObject(p.properties) && !_.isEmptyObject(p.properties)) {
510+
if (_.isObject(p.properties) && !_.isEmptyObject(p.properties)){
511511
_.extend(data.properties, p.properties);
512512
}
513513

514514
// profile时不传公用属性
515515
if (!p.type || p.type.slice(0, 7) !== 'profile') {
516516
// 传入的属性 > 当前页面的属性 > session的属性 > cookie的属性 > 预定义属性
517-
data.properties = _.extend({}, _.info.properties, data.properties);
517+
data.properties = _.extend({}, _.info.properties, sa.store.getProps(), data.properties);
518518
}
519519
// 如果$time是传入的就用,否则使用服务端时间
520520
if (data.properties.$time && _.isDate(data.properties.$time)) {
@@ -569,6 +569,18 @@ sa.store = {
569569
getDistinctId : function() {
570570
return this._state.distinct_id;
571571
},
572+
getProps: function () {
573+
return this._state.props || {};
574+
},
575+
setProps: function (newp, isCover) {
576+
var props = this._state.props || {};
577+
if (!isCover) {
578+
_.extend(props, newp);
579+
this.set('props', props);
580+
} else {
581+
this.set('props', newp);
582+
}
583+
},
572584
set : function(name, value) {
573585
var obj = {};
574586
if(typeof name === 'string'){
@@ -582,6 +594,9 @@ sa.store = {
582594
}
583595
this.save();
584596
},
597+
change: function (name, value) {
598+
this._state[name] = value;
599+
},
585600
save : function() {
586601
wx.setStorageSync("sensorsdata2015_wechat", JSON.stringify(this._state));
587602
},
@@ -625,6 +640,29 @@ sa.track = function(e, p, c) {
625640
properties : p
626641
}, c);
627642
};
643+
/*
644+
sa.identify = function (id, isSave) {
645+
if (typeof id === 'number') {
646+
id = String(id);
647+
}else if(typeof id !== 'string'){
648+
return false;
649+
}
650+
var firstId = sa.store.getFirstId();
651+
if (isSave === true) {
652+
if (firstId) {
653+
sa.store.set('first_id', id);
654+
} else {
655+
sa.store.set('distinct_id', id);
656+
}
657+
} else {
658+
if (firstId) {
659+
sa.store.change('first_id', id);
660+
} else {
661+
sa.store.change('distinct_id', id);
662+
}
663+
}
664+
};
665+
*/
628666

629667
sa.trackSignup = function(id, e, p, c) {
630668

@@ -638,10 +676,14 @@ sa.trackSignup = function(id, e, p, c) {
638676
sa.store.set('distinct_id', id);
639677
};
640678

641-
sa.register = function(){
642-
643-
679+
sa.register = function(obj){
680+
if (_.isObject(obj) && !_.isEmptyObject(obj)) {
681+
sa.store.setProps(obj);
682+
}
683+
};
644684

685+
sa.clearAllRegister = function(){
686+
sa.store.setProps({},true);
645687
};
646688

647689
sa.login = function(id) {

0 commit comments

Comments
 (0)